Skip to content

HWTapConfig Example not working #24

@nauen

Description

@nauen

Hey guys,

figuring the chip. But the library is a bit of.
the tap example is not working. There are used the wrong register.
Here an example how I was able to run the tap function.

`#include "SparkFunLSM6DS3.h"
#include "Wire.h"

LSM6DS3 myIMU( I2C_MODE, 0x6B );

void setup()
{
Serial.begin(115200);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");

//Call .beginCore() to configure the IMU
if ( myIMU.begin() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}

//Error accumulation variable
uint8_t errorAccumulator = 0;

uint8_t dataToWrite = 0; //Temporary variable

//Setup the accelerometer******************************
dataToWrite = 0; //Start Fresh!
dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_416Hz;

// //Now, write the patched together data
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);

//Set the ODR bit
errorAccumulator += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);

// Enable tap detection on X, Y, Z axis, but do not latch output

errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_TAP_CFG1, 0x8E ); // org 0x0E

// Set tap threshold
// Write 0Ch into TAP_THS_6D
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_TAP_THS_6D, 0x8C ); // 0x03

// Set Duration, Quiet and Shock time windows
// Write 7Fh into INT_DUR2
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_INT_DUR2, 0x7F );

// Single & Double tap enabled (SINGLE_DOUBLE_TAP = 1)
// Write 80h into WAKE_UP_THS
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x80 );

// Single tap interrupt driven to INT1 pin -- enable latch
// Write 08h into MD1_CFG
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_MD1_CFG, 0x08 ); // 0x48

if ( errorAccumulator )
{
Serial.println("Problem configuring the device.");
}
else
{
Serial.println("Device O.K.");
}

}

bool checkForDoubleTap()
{
static unsigned long tapWait; // decay value so double taps wont refire right away
uint8_t reg;
myIMU.readRegister(&reg, LSM6DS3_ACC_GYRO_TAP_SRC);

if (tapWait < millis()) {

if (((reg & 0x40) == 0x40) && ((reg & 0x10) == 0x10)) {     // double tap
  Serial.print("double tap ");
  Serial.println(millis());
  tapWait = millis() + 200;
  return true;
}

}

return false;
}

void loop()
{
checkForDoubleTap();
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions