ESP32S3 can't connect to ADXL345 Accelerometer on any i2c device

NerdMov
Posts: 5
Joined: Sat Jan 04, 2025 2:43 pm

ESP32S3 can't connect to ADXL345 Accelerometer on any i2c device

Postby NerdMov » Wed Jan 15, 2025 11:19 am

Hi guys,
I'm trying to use the accelerometer ADXL345 on my ESP32S3 with no results! It's always give to me ("Ooops, no ADXL345 detected ... Check your wiring!") when I initialized it on function !accel.begin() and obviously doesn't work. I have no idea how can it be possibile. I'm missing something for sure because they both works with other modules!

Here all the steps I tried:

1) same error on a PCB and on a breadboard with diffrent ESP32S3 and ADXL345
5780747525257545527.jpg
5780747525257545527.jpg (142.14 KiB) Viewed 391 times
2) Wiring ok. I tested with a multimeter
3) The ESP32S3 works perfectly I tried with some led and other module on same pin so the wiring it's ok.
4) The ADXL345 works too, I tried with the example code on a Arduino Nano
5) Change with different begin value: Serial.begin(115200) and Serial.begin(9600); No works
6) I tried with my code and with the example code. Nothing works.
7) I tried with pin define. no work

Code: Select all

#define I2C_SDA_PIN 5
#define I2C_SCL_PIN 6

Code: Select all

Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);

  if (!accel.begin()) {
    Serial.println("No ADXL345 detected");
    //while (1);
  }
  Serial.println("ADXL345 initialized");

Here the example code:

Code: Select all

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <ESP32Servo.h>
#include <esp_now.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void displaySensorDetails(void)
{
  sensor_t sensor;
  accel.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" m/s^2");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void displayDataRate(void)
{
  Serial.print  ("Data Rate:    "); 
  
  switch(accel.getDataRate())
  {
    case ADXL345_DATARATE_3200_HZ:
      Serial.print  ("3200 "); 
      break;
    case ADXL345_DATARATE_1600_HZ:
      Serial.print  ("1600 "); 
      break;
    case ADXL345_DATARATE_800_HZ:
      Serial.print  ("800 "); 
      break;
    case ADXL345_DATARATE_400_HZ:
      Serial.print  ("400 "); 
      break;
    case ADXL345_DATARATE_200_HZ:
      Serial.print  ("200 "); 
      break;
    case ADXL345_DATARATE_100_HZ:
      Serial.print  ("100 "); 
      break;
    case ADXL345_DATARATE_50_HZ:
      Serial.print  ("50 "); 
      break;
    case ADXL345_DATARATE_25_HZ:
      Serial.print  ("25 "); 
      break;
    case ADXL345_DATARATE_12_5_HZ:
      Serial.print  ("12.5 "); 
      break;
    case ADXL345_DATARATE_6_25HZ:
      Serial.print  ("6.25 "); 
      break;
    case ADXL345_DATARATE_3_13_HZ:
      Serial.print  ("3.13 "); 
      break;
    case ADXL345_DATARATE_1_56_HZ:
      Serial.print  ("1.56 "); 
      break;
    case ADXL345_DATARATE_0_78_HZ:
      Serial.print  ("0.78 "); 
      break;
    case ADXL345_DATARATE_0_39_HZ:
      Serial.print  ("0.39 "); 
      break;
    case ADXL345_DATARATE_0_20_HZ:
      Serial.print  ("0.20 "); 
      break;
    case ADXL345_DATARATE_0_10_HZ:
      Serial.print  ("0.10 "); 
      break;
    default:
      Serial.print  ("???? "); 
      break;
  }  
  Serial.println(" Hz");  
}

void displayRange(void)
{
  Serial.print  ("Range:         +/- "); 
  
  switch(accel.getRange())
  {
    case ADXL345_RANGE_16_G:
      Serial.print  ("16 "); 
      break;
    case ADXL345_RANGE_8_G:
      Serial.print  ("8 "); 
      break;
    case ADXL345_RANGE_4_G:
      Serial.print  ("4 "); 
      break;
    case ADXL345_RANGE_2_G:
      Serial.print  ("2 "); 
      break;
    default:
      Serial.print  ("?? "); 
      break;
  }  
  Serial.println(" g");  
}

void setup(void) 
{
//#ifndef ESP8266
 // while (!Serial); // for Leonardo/Micro/Zero
//#endif
  Serial.begin(115200);
  Serial.println("Accelerometer Test"); Serial.println("");
  
  /* 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);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_16_G);
  // accel.setRange(ADXL345_RANGE_8_G);
  // accel.setRange(ADXL345_RANGE_4_G);
  // accel.setRange(ADXL345_RANGE_2_G);
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
  
  /* Display additional settings (outside the scope of sensor_t) */
  displayDataRate();
  displayRange();
  Serial.println("");
}

void loop(void) 
{
  /* 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 ");
  delay(500);
}
Last edited by NerdMov on Thu Jan 16, 2025 1:44 pm, edited 1 time in total.

NerdMov
Posts: 5
Joined: Sat Jan 04, 2025 2:43 pm

Re: ESP32S3 can't connect to ADXL345 Accelerometer

Postby NerdMov » Thu Jan 16, 2025 1:44 pm

I also try the i2c scanner and I can't find any device. I tried with different board.

Andrea

Who is online

Users browsing this forum: No registered users and 65 guests