0

adxl343 double tap?!!
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

adxl343 double tap?!!

by OverwatchGirl on Fri Aug 16, 2019 5:17 pm

Hello, I have been trying not to post in here for as long as possible, but I've exhausted every possible search term i can think of over the past 6 hours. I'm trying to get the double tap function to work on the adxl343. Initially I just wanted to try and adapt the singletap code to work but this is failing. I've tried everything I can think of, and now I give up and hopefully someone here can help me. I'm using an itsbity m4 express. SCL and SDA hooked to SCL and SDA with pullups. Int1 to (7) int2 to (4). Sensortest example works fine. I believe the tap detection events such as thershold, duration etc are pulled from the .cpp file? but tbh I've never understood what the .cpp file is. There isn't5 any documentation anywhere that I can find, explaining how to perform a double tap on the 343. Even if I set single tap to false, the program just seems to ignore all taps.

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL343.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);

/** The input pin to enable the interrupt on, connected to INT1 on the ADXL. */
#define INPUT_PIN_INT1   (7) // SAMD21/SAMD51 = 5 for interrupt pin
#define INPUT_PIN_INT2   (4) // SAMD21/SAMD51 = 5 for interrupt pin

uint32_t g_tap_count = 0;
int_config g_int_config_enabled = { 0 };
int_config g_int_config_map = { 0 };

/** Interrupt service routine for INT1 events. This will be called when a single tap is detected. */
void int1_isr(void)
{
    g_tap_count=1;
}

void int2_isr(void)
{
    g_tap_count=2;
}

void setup(void)
{
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Harry Potter Wand"); Serial.println("");

  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL343 ... check your connections */
    Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
    while(1);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL343_RANGE_16_G);

  /* Configure the HW interrupts. */
  pinMode(INPUT_PIN_INT1, INPUT);
  pinMode(INPUT_PIN_INT2, INPUT);
  attachInterrupt(digitalPinToInterrupt(INPUT_PIN_INT1), int1_isr, RISING);
  attachInterrupt(digitalPinToInterrupt(INPUT_PIN_INT2), int2_isr, RISING);

  /* Enable single tap interrupts on the accelerometer. */
  g_int_config_enabled.bits.single_tap = true;
  g_int_config_enabled.bits.double_tap = true;
  accel.enableInterrupts(g_int_config_enabled);

  /* Map single tap interrupts to INT1 pin. */
  g_int_config_map.bits.single_tap = ADXL343_INT1;
  g_int_config_map.bits.double_tap = ADXL343_INT2;
  accel.mapInterrupts(g_int_config_map);

  /* Reset tap counter. */
  g_tap_count = 0;
 
  Serial.println("ADXL343 init complete. Waiting for single tap INT activity.");
}

void loop(void)
{
  /* Get a new sensor event */
  /* Reading data clears the interrupts. */
  sensors_event_t event;
  accel.getEvent(&event);
  delay(10);

  if (g_tap_count ==1) {
      Serial.println("Single tap detected!");
      Serial.println(g_tap_count);
      /* Clear the interrupt by check the source register.. */
      uint8_t source = accel.checkInterrupts();
      /* Decrement the local interrupt counter. */
      g_tap_count=0;
  }
  if (g_tap_count ==2) {
      Serial.println("Double tap detected!");
      Serial.println(g_tap_count);
      /* Clear the interrupt by check the source register.. */
      uint8_t source = accel.checkInterrupts();
      /* Decrement the local interrupt counter. */
      g_tap_count=0;
  }

}


Thank you in advance to anyone that can put me out of my misery

OverwatchGirl
 
Posts: 10
Joined: Mon Jun 06, 2016 7:06 am

Re: adxl343 double tap?!!

by OverwatchGirl on Sat Aug 17, 2019 11:12 am

Anyone?

OverwatchGirl
 
Posts: 10
Joined: Mon Jun 06, 2016 7:06 am

Re: adxl343 double tap?!!

by OverwatchGirl on Sat Aug 17, 2019 1:16 pm

Finally got it working. Just open Adafruit_ADXL343.cpp and change the following lines to have the following values. Double tap works about 80% of the time with these values changed. YMMV, change the values to suit your needs. Page 19 in here for more info (Although it's for the ADXL345, same applies):
https://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf

Code: Select all | TOGGLE FULL SIZE
  writeRegister(ADXL343_REG_INT_ENABLE, 0);     // Disable interrupts to start
  writeRegister(ADXL343_REG_THRESH_TAP, 20);    // 62.5 mg/LSB (so 0xFF = 16 g. 20 = default (how hard you hit it)
  writeRegister(ADXL343_REG_DUR, 300);           // Max tap duration, 625 µs/LSB. 50 = default
  writeRegister(ADXL343_REG_LATENT, 100);         // Tap latency, 1.25 ms/LSB, 0=no double tap. 0=default
  writeRegister(ADXL343_REG_WINDOW, 400);         // Waiting period,  1.25 ms/LSB, 0=no double tap. 0 = default.
  writeRegister(ADXL343_REG_TAP_AXES, 0x7);     // Enable the XYZ axis for tap

OverwatchGirl
 
Posts: 10
Joined: Mon Jun 06, 2016 7:06 am

Please be positive and constructive with your questions and comments.