Detecting taps using multiple ADXL345

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Scherady
 
Posts: 1
Joined: Sun Jul 14, 2019 5:21 am

Detecting taps using multiple ADXL345

Post by Scherady »

I am writing an Arduino code for an ESP32 with multiple ADXL345 and I would like to detect single and double taps on:
1. any one of the ADXLs alone or
2. any combination of the ADXLs simultaneously.

I started with the following code.

Can you help?

Thank you.

Code: Select all

#include <Wire.h>
#include <Adafruit_ADXL345_U.h>
#include <Adafruit_sensor.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
#define TCAADDR 0x70

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

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

void loop() {
  // put your main code here, to run repeatedly:

      for (uint8_t t=0; t<5; t++) {
          tcaselect(t);
          Serial.println();
          Serial.print("Sensor no : ");
          Serial.println(t);

          /* Get a new sensor event */
          sensors_event_t event;
          accel.getEvent(&event);
           
          /* Display the results (acceleration is measured in m/s^2) */
          Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
          Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
          Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
      }
}

void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”