Last active
August 10, 2024 07:46
-
-
Save disq/ed225f9f702d968cafa231ae14cc44f3 to your computer and use it in GitHub Desktop.
LIS3DH custom reg settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add these to public methods block: | |
// Getters for i2c_dev and spi_dev - Modification to the original library | |
Adafruit_I2CDevice *getI2CDevice() { return i2c_dev; } | |
Adafruit_SPIDevice *getSPIDevice() { return spi_dev; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is how I use them | |
// ... other init code ... | |
Adafruit_I2CDevice *i2c_dev = imu.getI2CDevice(); ///< Pointer to I2C bus interface | |
Adafruit_SPIDevice *spi_dev = imu.getSPIDevice(); ///< Pointer to SPI bus interface | |
Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_CTRL3, 1); | |
Adafruit_BusIO_RegisterBits i1_click = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 7); | |
i1_click.write(1); // enable i1 click | |
Adafruit_BusIO_Register ctrl5 = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_CTRL5, 1); | |
Adafruit_BusIO_RegisterBits int1_latch_bit = Adafruit_BusIO_RegisterBits(&ctrl5, 1, 3); | |
int1_latch_bit.write(true); | |
// and so on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void imu_setClick() { | |
imu.setRange(LIS3DH_RANGE_8_G); // 2, 4, 8 or 16 G! | |
imu.enableDRDY(false); | |
// Adjust this number for the sensitivity of the 'click' force | |
// this strongly depend on the range! for 16G, try 5-10 | |
// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80 | |
const uint8_t clickthresh = 70; | |
// const uint8_t clickthresh = 20; | |
const uint8_t timelimit = 10; | |
const uint8_t timelatency = 20; | |
const uint8_t timewindow = 255; | |
Adafruit_I2CDevice *i2c_dev = imu.getI2CDevice(); ///< Pointer to I2C bus interface | |
Adafruit_SPIDevice *spi_dev = imu.getSPIDevice(); ///< Pointer to SPI bus interface | |
Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_CTRL3, 1); | |
Adafruit_BusIO_RegisterBits i1_click = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 7); | |
Adafruit_BusIO_Register click_cfg = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_CLICKCFG, 1); | |
i1_click.write(1); // enable i1 click | |
Adafruit_BusIO_Register ctrl5 = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_CTRL5, 1); | |
Adafruit_BusIO_RegisterBits int1_latch_bit = Adafruit_BusIO_RegisterBits(&ctrl5, 1, 3); | |
int1_latch_bit.write(true); | |
// click_cfg.write(0x15); // turn on all axes & singletap | |
// click_cfg.write(0x2A); // turn on all axes & doubletap | |
click_cfg.write(0x10); // turn on Z axis & singletap | |
Adafruit_BusIO_Register click_ths = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_CLICKTHS, 1); | |
click_ths.write(clickthresh); // arbitrary | |
Adafruit_BusIO_Register time_limit = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_TIMELIMIT, 1); | |
time_limit.write(timelimit); // arbitrary | |
Adafruit_BusIO_Register time_latency = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_TIMELATENCY, 1); | |
time_latency.write(timelatency); // arbitrary | |
Adafruit_BusIO_Register time_window = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS3DH_REG_TIMEWINDOW, 1); | |
time_window.write(timewindow); // arbitrary | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment