Skip to content

Commit e7be519

Browse files
committed
Places new documentation in documentation folder
* Replaces old references to ISM part * Updates SPI MODE * Updates a few bit fields that have changed in the v4.0 reference document * Adds a few tap related functions * Adds a software reset function * Updates all examples with correct output data rate comment * Also updates all examples with sofware reset function and additional sensor class
1 parent 38a94af commit e7be519

15 files changed

+136
-38
lines changed
Binary file not shown.
1.89 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.

examples/example1_basic_readings/example1_basic_readings.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "SparkFun_KX13X.h"
2525

2626
SparkFun_KX132 kxAccel;
27+
// SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above
2728

2829
outputData myData; // Struct for the accelerometer's data
2930

@@ -40,14 +41,17 @@ void setup()
4041
delay(50);
4142

4243

43-
if( !kxAccel.begin(chipSelect) )
44+
if( !kxAccel.begin() )
4445
{
4546
Serial.println("Could not communicate with the the KX13X. Freezing.");
4647
while(1);
4748
}
4849

4950
Serial.println("Ready.");
5051

52+
if( kxAccel.softwareReset() )
53+
Serial.println("Reset.");
54+
5155
// Many settings for KX13X can only be
5256
// applied when the accelerometer is powered down.
5357
// However there are many that can be changed "on-the-fly"
@@ -57,7 +61,7 @@ void setup()
5761

5862
kxAccel.setRange(0x18); // 16g Range
5963
kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
60-
// kxAccel.setOutputDataRate(); // Default is 400Hz
64+
// kxAccel.setOutputDataRate(); // Default is 50Hz
6165
kxAccel.enableAccel();
6266

6367

examples/example2_interrupts/example2_interrupts.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "SparkFun_KX13X.h"
2626

2727
SparkFun_KX132 kxAccel;
28+
// SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above
2829

2930
outputData myData; // Struct for the accelerometer's data
3031
byte dataReadyPin = 2; // Change to fit your project.
@@ -50,6 +51,10 @@ void setup()
5051

5152
Serial.println("Ready.");
5253

54+
// Reset the chip so that old settings don't apply to new setups.
55+
if( kxAccel.softwareReset() )
56+
Serial.println("Reset.");
57+
5358
// Many settings for KX13X can only be
5459
// applied when the accelerometer is powered down.
5560
// However there are many that can be changed "on-the-fly"

examples/example3_buffer/example3_buffer.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "SparkFun_Qwiic_KX13X.h"
2626

2727
SparkFun_KX132 kxAccel;
28+
// SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above
2829

2930
outputData myData; // Struct for the accelerometer's data
3031
byte dataReadyPin = 2; // Change to fit your project.
@@ -50,6 +51,10 @@ void setup()
5051

5152
Serial.println("Ready.");
5253

54+
// Reset the chip so that old settings don't apply to new setups.
55+
if( kxAccel.softwareReset() )
56+
Serial.println("Reset.");
57+
5358
// Many settings for KX13X can only be
5459
// applied when the accelerometer is powered down.
5560
// However there are many that can be changed "on-the-fly"
@@ -77,7 +82,7 @@ void setup()
7782
// Changes depending on the resolution, see datasheet for more info.
7883

7984
kxAccel.setRange(0x18); // 16g Range
80-
//kxAccel.setOutputDataRate(); // Default is 400Hz
85+
//kxAccel.setOutputDataRate(); // Default is 50Hz
8186
kxAccel.enableAccel();
8287

8388

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
example6-tap
33
4-
This example shows the how to enable the tap interrupts
4+
This example shows the how to enable the tap interrupts.
55
66
Please refer to the header file for more possible settings, found here:
77
..\SparkFun_KX13X_Arduino_Library\src\sfe_kx13x_defs.h
@@ -20,22 +20,18 @@
2020
License (http://opensource.org/licenses/MIT).
2121
*/
2222

23-
#include <SPI.h>
2423
#include <Wire.h>
2524
#include "SparkFun_KX13X.h"
2625

27-
SparkFun_KX132_SPI kxAccel;
26+
SparkFun_KX132 kxAccel;
27+
// SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above
2828

29-
byte chipSelect = 1; // Change to fit your project.
29+
byte direction = 0;
3030

3131
void setup()
3232
{
3333

34-
// Get the chip select pin ready.
35-
pinMode(chipSelect, OUTPUT);
36-
digitalWrite(chipSelect, HIGH);
37-
38-
SPI.begin();
34+
Wire.begin();
3935

4036
Serial.begin(115200);
4137
Serial.println("Welcome.");
@@ -45,24 +41,29 @@ void setup()
4541
delay(50);
4642

4743

48-
if( !kxAccel.begin(chipSelect) )
44+
if( !kxAccel.begin() )
4945
{
5046
Serial.println("Could not communicate with the the KX13X. Freezing.");
5147
while(1);
5248
}
5349

5450
Serial.println("Ready.");
5551

52+
// Reset the chip so that old settings don't apply to new setups.
53+
if( kxAccel.softwareReset() )
54+
Serial.println("Reset.");
55+
5656
// Many settings for KX13X can only be
5757
// applied when the accelerometer is powered down.
5858
// However there are many that can be changed "on-the-fly"
5959
// check datasheet for more info, or the comments in the
6060
// "...regs.h" file which specify which can be changed when.
6161
kxAccel.enableAccel(false);
6262

63-
kxAccel.setRange(0x18); // 16g Range
64-
kxAccel.enableTapEngine(); // Enable tap Engine
65-
// kxAccel.setOutputDataRate(); // Default is 400Hz
63+
kxAccel.setRange(0x18); // 16g Range
64+
kxAccel.enableTapEngine(); // Enable tap Engine
65+
kxAccel.enableDirecTapInterupt(); // This enables checking the direction of the interrupt
66+
//kxAccel.setTapDataRate(uint8_t rate); // Default is 400Hz
6667
kxAccel.enableAccel();
6768

6869

@@ -73,14 +74,14 @@ void loop()
7374
// Check if tap was detected
7475
if( kxAccel.tapDetected() )
7576
{
76-
Serial.println("Tap Detected.");
77+
Serial.print("Tap Detected: ");
78+
Serial.println(kxAccel.getDirection(), HEX);
7779
kxAccel.clearInterrupt();
78-
while(1);
7980
}
8081

81-
if( kxAccel.unknownTap() || kxAccel.doubleTapDetected() )
82+
if( kxAccel.unknownTap() || kxAccel.doubleTapDetected() ) // These all share the same bit space
8283
kxAccel.clearInterrupt();
8384

84-
delay(30); // Delay should be 1/ODR (Output Data Rate), default tap ODR is 400Hz
85+
delay(25); // Delay should be 1/ODR (Output Data Rate), default tap ODR is 400Hz
8586

8687
}

examples/example5_spi/example5_spi.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "SparkFun_KX13X.h"
2525

2626
SparkFun_KX132_SPI kxAccel;
27+
// SparkFun_KX134_SPI kxAccel; // For the KX134, uncomment this and comment line above
2728

2829
outputData myData; // Struct for the accelerometer's data
2930
byte chipSelect = 1; // Change to fit your project.
@@ -53,6 +54,10 @@ void setup()
5354

5455
Serial.println("Ready.");
5556

57+
// Reset the chip so that old settings don't apply to new setups.
58+
if( kxAccel.softwareReset() )
59+
Serial.println("Reset.");
60+
5661
// Many settings for KX13X can only be
5762
// applied when the accelerometer is powered down.
5863
// However there are many that can be changed "on-the-fly"
@@ -62,7 +67,7 @@ void setup()
6267

6368
kxAccel.setRange(0x18); // 16g Range
6469
kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
65-
// kxAccel.setOutputDataRate(); // Default is 400Hz
70+
// kxAccel.setOutputDataRate(); // Default is 50Hz
6671
kxAccel.enableAccel();
6772

6873

src/SparkFun_KX13X.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ class SparkFun_KX132_SPI : public QwDevKX132
105105
return this->QwDevKX132::init();
106106
}
107107

108-
bool begin(SPIClass &spiPort, SPISettings ismSettings, uint8_t cs)
108+
bool begin(SPIClass &spiPort, SPISettings kxSettings, uint8_t cs)
109109
{
110110
// Setup a SPI object and pass into the superclass
111111
setCommunicationBus(_spiBus);
112112

113113
// Initialize the SPI bus class with provided SPI port, SPI setttings, and chip select pin.
114-
_spiBus.init(spiPort, ismSettings, cs, true);
114+
_spiBus.init(spiPort, kxSettings, cs, true);
115115

116116
// Initialize the system - return results
117117
return this->QwDevKX132::init();
@@ -226,13 +226,13 @@ class SparkFun_KX134_SPI : public QwDevKX134
226226
return this->QwDevKX134::init();
227227
}
228228

229-
bool begin(SPIClass &spiPort, SPISettings ismSettings, uint8_t cs)
229+
bool begin(SPIClass &spiPort, SPISettings kxSettings, uint8_t cs)
230230
{
231231
// Setup a SPI object and pass into the superclass
232232
setCommunicationBus(_spiBus);
233233

234234
// Initialize the SPI bus class with provided SPI port, SPI setttings, and chip select pin.
235-
_spiBus.init(spiPort, ismSettings, cs, true);
235+
_spiBus.init(spiPort, kxSettings, cs, true);
236236

237237
// Initialize the system - return results
238238
return this->QwDevKX134::init();

0 commit comments

Comments
 (0)