Skip to content

Commit

Permalink
Merge pull request #32 from LiquidCGS/31-add-lsm6ds3tr-c
Browse files Browse the repository at this point in the history
Add support for LSM6DS3TR-C
  • Loading branch information
LiquidCGS authored Nov 12, 2024
2 parents 5a92d75 + c2a536f commit 2c8480d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Supported IMUS:
* BMI055
* BMX055 (Magnetometer currently untested)
* BMI160
* LSM6DS3
* LSM6DS3 (And some of it's variants)
* LSM6DSL (currently untested)
* QMI8658

Expand Down
Binary file added datasheets/LSM6DS3TR-C-Datasheet.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/IMUIdentifier/IMUIdentifier.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const IMU IMUList[NUM_IMUS] =
{0x68, 0x69, 0x75, 0x19, "MPU6886", "3A,3G", true},
{0x69, 0x68, 0x00, 0xD1, "BMI160", "3A,3G", true},
{0x6B, 0x6A, 0x0F, 0x69, "LSM6DS3", "3A,3G", true},
{0x6B, 0x6A, 0x0F, 0x6A, "LSM6DSL", "3A,3G", true},
{0x6B, 0x6A, 0x0F, 0x6A, "LSM6DSL or LSM6DS3TR-C", "3A,3G", true},
{0x68, 0x69, 0x75, 0x98, "ICM20689", "3A,3G", true},
{0x68, 0x69, 0x75, 0x20, "ICM20690", "3A,3G", true},
{0x6B, 0x6A, 0x00, 0x05, "QMI8658", "3A,3G", true},
Expand Down
11 changes: 7 additions & 4 deletions src/F_LSM6DS3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ int LSM6DS3::init(calData cal, uint8_t address)
{
calibration = cal;
}

if (!(readByte(IMUAddress, LSM6DS3_WHO_AM_I) == LSM6DS3_WHOAMI_DEFAULT_VALUE)) {
return -1;

uint8_t IMUWhoAmI = checkReady(IMUAddress, 500);
if (!(IMUWhoAmI == LSM6DS3_WHOAMI_DEFAULT_VALUE)) {
if (!(IMUWhoAmI == LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE)) {
return -1;
}
}

// reset device
writeByte(IMUAddress, LSM6DS3_CTRL3_C, 0x01); // Toggle softreset
delay(100); // wait for reset
while (!checkReady(IMUAddress, 100)); // wait for reset

writeByte(IMUAddress, LSM6DS3_CTRL1_XL, 0x47); // Start up accelerometer, set range to +-16g, set output data rate to 104hz, BW_XL bits to 11.
writeByte(IMUAddress, LSM6DS3_CTRL2_G, 0x4C); // Start up gyroscope, set range to -+2000dps, output data rate to 104hz.
Expand Down
13 changes: 13 additions & 0 deletions src/F_LSM6DS3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define LSM6DS3_OUTZ_H_XL 0x2D

#define LSM6DS3_WHOAMI_DEFAULT_VALUE 0x69
#define LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE 0x6A

class LSM6DS3 : public IMUBase {
public:
Expand Down Expand Up @@ -135,5 +136,17 @@ class LSM6DS3 : public IMUBase {
dest[i++] = Wire.read();
} // Put read results in the Rx buffer
}

uint8_t checkReady(uint8_t address, uint8_t timeout)
{
uint8_t IMUWhoAmI = 0;
// Wait until a valid byte is returned, up until timeout value.
for (uint8_t checkCount = timeout; checkCount > 0; checkCount--) {
IMUWhoAmI = readByte(address, LSM6DS3_WHO_AM_I);
if (IMUWhoAmI == 0xFF) { delay(1); } else { break; }
}
// Return IMU identifier if found.
return IMUWhoAmI;
}
};
#endif /* _F_LSM6DS3_H_ */

0 comments on commit 2c8480d

Please sign in to comment.