Skip to content

v2.0.3 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4e4b946
Correct register struct names
PaulZC Jan 16, 2023
82b9683
Make TSCP bitfields LSB-first
PaulZC Jan 16, 2023
00a77e2
Make TSPP bitfields LSB-first
PaulZC Jan 16, 2023
5817e51
Make INS1-3 bitfields LSB-first
PaulZC Jan 16, 2023
21881fb
Make CNTL bitfields LSB-first
PaulZC Jan 16, 2023
14152d5
Make INC bitfields LSB-first
PaulZC Jan 16, 2023
8d0b37a
Make CNTL bitfields LSB-first
PaulZC Jan 16, 2023
e2d1847
Whitespace changes... Sorry!
PaulZC Jan 16, 2023
3c6723f
Add extra range DP
PaulZC Jan 16, 2023
9c56699
Add CNTL register bitfield unions
PaulZC Jan 16, 2023
65f937f
Correct setRange: make it read-modify-write; use correct gsel bits
PaulZC Jan 16, 2023
c2d8a88
Correct enableDataEngine - allow the drdye bit to be cleared as well …
PaulZC Jan 16, 2023
5fdf6c8
Correct enableTapEngine - allow the tdte bit to be cleared
PaulZC Jan 16, 2023
be1d802
Correct enableTiltEngine
PaulZC Jan 16, 2023
f4df41c
Correct enableAccel
PaulZC Jan 16, 2023
706fd84
Correct enableWakeEngine
PaulZC Jan 16, 2023
97a21cb
Correct enableSleepEngine
PaulZC Jan 16, 2023
62add95
Correct setOutputDataRate
PaulZC Jan 16, 2023
b927396
Correct setTapDataRate and setTiltDataRate
PaulZC Jan 16, 2023
eb80e0b
Correct setWakeDataRate. Update getOutputDataRate
PaulZC Jan 16, 2023
52f953a
Update enablePhysInterrupt and correct setPinMode
PaulZC Jan 16, 2023
085ea0f
Change setPinMode to maintain backward compatibility
PaulZC Jan 16, 2023
a2746fb
Update setLatchControl and setPulseWidth
PaulZC Jan 16, 2023
ccab060
Add INC4 and INC6 bitfields
PaulZC Jan 16, 2023
9dafcff
Update enableDirecTapInterupt, enableDoubleTapInterrupt and dataReady
PaulZC Jan 16, 2023
7c599e0
More bitfield updates
PaulZC Jan 16, 2023
0d65289
Update getRawAccelData so it can read 8-bit buffer data if required
PaulZC Jan 16, 2023
d7c2154
v2.0.3
PaulZC Jan 16, 2023
06eb831
Correct CNTL1 rim
PaulZC Jan 17, 2023
8fbe78f
Update example3_buffer.ino
PaulZC Jan 17, 2023
2a07ec1
Update getRawAccelData and Example3
PaulZC Jan 17, 2023
5a5ca2e
Update SparkFun_KX13X_regs.h
PaulZC Jan 17, 2023
e5d5628
Add namespace protection for QwIDeviceBus
PaulZC Jan 18, 2023
56e34a3
Add getRawAccelRegisterData and getRawAccelBufferData
PaulZC Jan 18, 2023
4737801
Delete esp32.svd
PaulZC Jan 18, 2023
cd5db07
Update examples
PaulZC Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 65 additions & 69 deletions examples/example1_basic_readings/example1_basic_readings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,101 @@
example1-BasicReadings

This example shows the basic settings and functions for retrieving accelerometer
data. Other possible Range settings, depending on your accelerometer KX132 or KX134, are
the following:

SFE_KX132_RANGE2G
SFE_KX132_RANGE4G
SFE_KX132_RANGE8G
SFE_KX132_RANGE16G
SFE_KX134_RANGE8G
SFE_KX134_RANGE16G
SFE_KX134_RANGE32G
SFE_KX134_RANGE64G
data. Other possible Range settings, depending on your accelerometer KX132 or KX134, are
the following:

SFE_KX132_RANGE2G
SFE_KX132_RANGE4G
SFE_KX132_RANGE8G
SFE_KX132_RANGE16G

SFE_KX134_RANGE8G
SFE_KX134_RANGE16G
SFE_KX134_RANGE32G
SFE_KX134_RANGE64G

Written by Elias Santistevan @ SparkFun Electronics, October 2022

Products:
Products:

SparkFun Triple Axis Accelerometer Breakout - KX132:
https://www.sparkfun.com/products/17871
SparkFun Triple Axis Accelerometer Breakout - KX132:
https://www.sparkfun.com/products/17871

SparkFun Triple Axis Accelerometer Breakout - KX134:
https://www.sparkfun.com/products/17589
SparkFun Triple Axis Accelerometer Breakout - KX134:
https://www.sparkfun.com/products/17589

Repository:

https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library
https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library

SparkFun code, firmware, and software is released under the MIT
License (http://opensource.org/licenses/MIT).
SparkFun code, firmware, and software is released under the MIT
License (http://opensource.org/licenses/MIT).
*/

#include <Wire.h>
#include "SparkFun_KX13X.h"
#include <SparkFun_KX13X.h> // Click here to get the library: http://librarymanager/All#SparkFun_KX13X

SparkFun_KX132 kxAccel;
//SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above
SparkFun_KX132 kxAccel;
// SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above

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

void setup()
void setup()
{

Wire.begin();

Serial.begin(115200);
Wire.begin();

Serial.begin(115200);
Serial.println("Welcome.");

// Wait for the Serial monitor to be opened.
while(!Serial)
// Wait for the Serial monitor to be opened.
while (!Serial)
delay(50);


if( !kxAccel.begin() )
{
if (!kxAccel.begin())
{
Serial.println("Could not communicate with the the KX13X. Freezing.");
while(1);
}
while (1)
;
}

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

if( kxAccel.softwareReset() )
Serial.println("Reset.");
if (kxAccel.softwareReset())
Serial.println("Reset.");

//Give some time for the accelerometer to reset.
//It needs two, but give it five for good measure.
delay(5);

// Many settings for KX13X can only be
// applied when the accelerometer is powered down.
// However there are many that can be changed "on-the-fly"
// check datasheet for more info, or the comments in the
// "...regs.h" file which specify which can be changed when.
kxAccel.enableAccel(false);

kxAccel.setRange(SFE_KX132_RANGE16G); // 16g Range
//kxAccel.setRange(SFE_KX134_RANGE16G); // 16g for the KX134

kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
// kxAccel.setOutputDataRate(); // Default is 50Hz
kxAccel.enableAccel();
// Give some time for the accelerometer to reset.
// It needs two, but give it five for good measure.
delay(5);

// Many settings for KX13X can only be
// applied when the accelerometer is powered down.
// However there are many that can be changed "on-the-fly"
// check datasheet for more info, or the comments in the
// "...regs.h" file which specify which can be changed when.
kxAccel.enableAccel(false);

kxAccel.setRange(SFE_KX132_RANGE16G); // 16g Range
// kxAccel.setRange(SFE_KX134_RANGE16G); // 16g for the KX134

kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
// kxAccel.setOutputDataRate(); // Default is 50Hz
kxAccel.enableAccel();
}

void loop()
void loop()
{
// Check if data is ready.
if( kxAccel.dataReady() )
{
kxAccel.getAccelData(&myData);
Serial.print("X: ");
Serial.print(myData.xData, 4);
Serial.print(" Y: ");
Serial.print(myData.yData, 4);
Serial.print(" Z: ");
Serial.print(myData.zData, 4);
Serial.println();
}
// Check if data is ready.
if (kxAccel.dataReady())
{
kxAccel.getAccelData(&myData);
Serial.print("X: ");
Serial.print(myData.xData, 4);
Serial.print(" Y: ");
Serial.print(myData.yData, 4);
Serial.print(" Z: ");
Serial.print(myData.zData, 4);
Serial.println();
}
delay(20); // Delay should be 1/ODR (Output Data Rate), default is 1/50ODR

}
114 changes: 56 additions & 58 deletions examples/example2_interrupts/example2_interrupts.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,108 @@

Written by Elias Santistevan @ SparkFun Electronics, October 2022

Products:
Products:

SparkFun Triple Axis Accelerometer Breakout - KX132:
https://www.sparkfun.com/products/17871
SparkFun Triple Axis Accelerometer Breakout - KX132:
https://www.sparkfun.com/products/17871

SparkFun Triple Axis Accelerometer Breakout - KX134:
https://www.sparkfun.com/products/17589
SparkFun Triple Axis Accelerometer Breakout - KX134:
https://www.sparkfun.com/products/17589


Repository:

https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library
https://github.com/sparkfun/SparkFun_KX13X_Arduino_Library

SparkFun code, firmware, and software is released under the MIT
License (http://opensource.org/licenses/MIT).
SparkFun code, firmware, and software is released under the MIT
License (http://opensource.org/licenses/MIT).
*/

#include <Wire.h>
#include <SPI.h>
#include "SparkFun_KX13X.h"
#include <SparkFun_KX13X.h> // Click here to get the library: http://librarymanager/All#SparkFun_KX13X

SparkFun_KX132 kxAccel;
SparkFun_KX132 kxAccel;
// SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above

outputData myData; // Struct for the accelerometer's data
byte dataReadyPin = 2; // Change to fit your project.

void setup()
void setup()
{

Wire.begin();

Serial.begin(115200);
Wire.begin();

Serial.begin(115200);
Serial.println("Welcome.");

// Wait for the Serial monitor to be opened.
while(!Serial)
// Wait for the Serial monitor to be opened.
while (!Serial)
delay(50);


if( !kxAccel.begin() )
{
if (!kxAccel.begin())
{
Serial.println("Could not communicate with the the KX13X. Freezing.");
while(1);
}
while (1)
;
}

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

// Reset the chip so that old settings don't apply to new setups.
if( kxAccel.softwareReset() )
Serial.println("Reset.");
// Reset the chip so that old settings don't apply to new setups.
if (kxAccel.softwareReset())
Serial.println("Reset.");

//Give some time for the accelerometer to reset.
//It needs two, but give it five for good measure.
delay(5);
// Give some time for the accelerometer to reset.
// It needs two, but give it five for good measure.
delay(5);

// Many settings for KX13X can only be
// applied when the accelerometer is powered down.
// However there are many that can be changed "on-the-fly"
// check datasheet for more info, or the comments in the
// "...regs.h" file which specify which can be changed when.
kxAccel.enableAccel(false);
// Many settings for KX13X can only be
// applied when the accelerometer is powered down.
// However there are many that can be changed "on-the-fly"
// check datasheet for more info, or the comments in the
// "...regs.h" file which specify which can be changed when.
kxAccel.enableAccel(false);

kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
kxAccel.enablePhysInterrupt(); // Enables interrupt pin 1
kxAccel.routeHardwareInterrupt(0x10); // Routes the data ready bit to pin 1
kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
kxAccel.enablePhysInterrupt(); // Enables interrupt pin 1
kxAccel.routeHardwareInterrupt(0x10); // Routes the data ready bit to pin 1

// Routing Data Ready pin to interrupt pin 2.
//kxAccel.enablePhysInterrupt(true, 2); // Enables interrupt pin 2
//kxAccel.routeHardwareInterrupt(0x10, 2); // Routes the data ready bit to pin 2
// Routing Data Ready pin to interrupt pin 2.
// kxAccel.enablePhysInterrupt(true, 2); // Enables interrupt pin 2
// kxAccel.routeHardwareInterrupt(0x10, 2); // Routes the data ready bit to pin 2

// This will change the interrupt behavior to latch instead of pulse
// In this case you'll need to release directly with clearInterrupt();.
//kxAccel.setLatchControl();
// In this case you'll need to release directly with clearInterrupt();.
// kxAccel.setLatchControl();

//kxAccel.setPinMode(); // Change interrupt to active HIGH
//kxAccel.setPulseWidth(); // Change the length of a pulsed (non latched) interrupt

kxAccel.setRange(SFE_KX132_RANGE16G); // 16g Range
//kxAccel.setRange(SFE_KX134_RANGE16G); // 16g for the KX134

//kxAccel.setOutputDataRate(); // Default is 400Hz
kxAccel.enableAccel();
// kxAccel.setPinMode(); // Change interrupt to active HIGH
// kxAccel.setPulseWidth(); // Change the length of a pulsed (non latched) interrupt

kxAccel.setRange(SFE_KX132_RANGE16G); // 16g Range
// kxAccel.setRange(SFE_KX134_RANGE16G); // 16g for the KX134

// kxAccel.setOutputDataRate(); // Default is 400Hz
kxAccel.enableAccel();
}

void loop()
void loop()
{

if( digitalRead(dataReadyPin) == HIGH ) // Check for data ready pin
{
if (digitalRead(dataReadyPin) == HIGH) // Check for data ready pin
{
kxAccel.getAccelData(&myData);
Serial.print("X: ");
Serial.print(myData.xData, 4);
Serial.print(" Y: ");
Serial.print(myData.yData, 4);
Serial.print(" Z: ");
Serial.print(myData.zData, 4);
Serial.println();
// If interrupt behavior has been changed to latch, use the
// following function to clear it after reading data.
//kxAccel.clearInterrupt();
Serial.println();

// If interrupt behavior has been changed to latch, use the
// following function to clear it after reading data.
// kxAccel.clearInterrupt();
}

delay(20); // Delay should be 1/ODR (Output Data Rate), default is 50Hz
Expand Down
Loading