Arduino ADXL 345 debug

I recently purchased an ADXL 345. But whenever I try to run any code, it always comes back with the startup of the ADXL 345 failed. For example, in this code

#include <Wire.h>
#include <ADXL345.h>


ADXL345 accel(ADXL345_STD);

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!accel.start()) {
    Serial.println("start: failed");
    while(1) {
      delay(100);
    }
  }
}

void loop() {
  if (accel.update()) {
    Serial.print(accel.getX());
    Serial.print(",");
    Serial.print(accel.getY());
    Serial.print(",");
    Serial.print(accel.getZ());
    Serial.println("");
  } else {
    Serial.println("update failed");
    while(1) {
      delay(100);
    }
  }
  delay(300);
}
}

(In this code I had SDA connected to the SDA pin and SCL connected to the SCL pin).

When I ran this code all it came back with was start: failed, I tried this multiple times (with a few library's) but nothing worked.

Do you know any way I could fix this? (Any suggestion helps)

Which Arduino board are you using and how is the sensor connected to it and powered ?

I'm using the uno and it is powered with 5v, and connected to gnd. The SCL is connected to the SCL pin on the uno and the SDA with the SDA pin on the uno.

I also tried an I2C scanner of the ADXL 345 and that came back as no sensor found, so its definitely an I2C issue.

Please post a link to the ADXL345 module you have.

Does it have the required logic level converters for use with a 5V Arduino?

GY-291 ADXL345 Angle Acceleration Sensor Module Arduino IIC/SPI Transmission | eBay

That is a 3.3V sensor, and requires a bidirectional logic level shifter to connect to a 5V Arduino.

Better to use a 3.3V Arduino!

Ok, I'll switch it to 3.3v and see how it goes.

The issue is still persisting.

I'm not sure what you mean by bidirectional logic level shifter

Click on the link in post #7, or do an internet search for "bidirectional logic level shifter".

It is possible that you have damaged the module by connecting it to a 5V Arduino.

1 Like

alright, thanks

I used the logic level shifter and it still isn’t working. Any way I can see if my adxl345 is damaged?

Provided that the wiring is correct and the code is correct, "not working" could indicate that the sensor, or the processor, or both have been damaged.

However, you not posted evidence that either the wiring or the code is correct.

With a new I2C device, always run the I2C Address Scanner program first, to check whether communication is working, and the sensor is detected at an expected I2C address.

Yeah I tried the i2c scanner and it said that no i2c address was found. Here are all the wirings:

Arduino UNO: Logic shifter: ADXL345:
A4. B3. SDA
A5. B2. SCL
GND. GND GND
5V HV. VCC

Here is the I2c code aswell:

#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

You forgot to mention which logic level shifter you are using, and text is no substitute for a wiring diagram.

Most level shifters require both a 5V and 3.3V connection. Post a link to the logic level shifter product page, and a closeup, focused photo of your setup.

Make sure all header pin connections are cleanly soldered, with no solder bridges or in complete solder joints.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.