Connecting 2 ADXL345 Accelerometer sensors over I2C

Hi !
I am working on a project and need to connect 2 accelerometers. ADXL345 is the sensor I am working using. I2C Address and alternate address for the same is 0x1D and 0x53.

If i don’t give an address while initializing the object, it works, but both sensors give same output
If i give address as 0x1D the sensor gives output as 0
If i Give address as 0x53 there is no output.

I want to read the data from both the sensors.

ADXL345 Accelerometer:

Accel2Only.ino (992 Bytes)

To change the I2C address of one of the modules to 0x53, ground the ALT_ADDRESS pin. Details are in the ADXL345 data sheet.

Hi,

I have already connected SDO pin of one sensor to ground and the other sensors SDO pin is connected to 5V.

used I2C scanner sketch and it outputs the addresses as 0x1D and 0x53 for the connected devices.

But it does’t work

According to the github source, the library you are using has a single, hard wired I2C address:

#define ADXL345_DEVICE (0x53) // Device Address for ADXL345

This would never work for two devices.

Ok, I got it !

Is there some other library so I can connect 2 ADXL345 Accelerometers?

If there is, Google can probably find it.

got it done using wire.h only

Thanks for the help !

Great! Please post your code, to help others with the same problem.

1 Like

Following is the code for same

#include<Wire.h>

#define accel_module (0x1d)         // SDO-> Vcc
#define accel_module2 (0x53)       // SDO-> GND

byte values[6];
byte values2[6];
char output[512];
char output2[512];

void getAccelration(int accelSensor, int cal)
{
  int xyzregister = 0x32;
  int x, y, z;

  Wire.beginTransmission(accelSensor);
  Wire.write(0x2D);
  Wire.write(0);
  Wire.endTransmission();
  Wire.beginTransmission(accelSensor);
  Wire.write(0x2D);
  Wire.write(16);
  Wire.endTransmission();
  Wire.beginTransmission(accelSensor);
  Wire.write(0x2D);
  Wire.write(8);
  Wire.endTransmission();

  Wire.beginTransmission(accelSensor);
  Wire.write(xyzregister);
  Wire.endTransmission();

  Wire.beginTransmission(accelSensor);
  Wire.requestFrom(accelSensor, 6);

  int i = 0;
  while(Wire.available())
  {
    values[i] = Wire.read();
    i++;
    }
  Wire.endTransmission();

  x = (((int)values[1]) << 8) | values[0];
  y = (((int)values[3])<< 8) | values[2];
  z = (((int)values[5]) << 8) | values[4];
  sprintf(output, "%d",z-cal);
  Serial.print(output);
  }

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

void loop() 
{
  getAccelration(accel_module, 205); // ********accel 0x1D*********//
  Serial.print("    From2: ");
  getAccelration(accel_module2, 28);  //*******accel 0x53********//

  Serial.println();  
  
  delay(200); 
}

Harinder85:
Hi,

I have already connected SDO pin of one sensor to ground and the other sensors SDO pin is connected to 5V.

used I2C scanner sketch and it outputs the addresses as 0x1D and 0x53 for the connected devices.

But it does't work

Could you please upload closeup photo of the modified sensor?

I am having the same issue. Cannot connect two accelerometers to one Arduino. A photo of connections accompanying your code would be excellent.

The sensors are connected in parallel, so the connections are exactly the same for one or two sensors. Only the address pin is different, and that is not connected to the Arduino.

vjagodnik:
I am having the same issue. Cannot connect two accelerometers to one Arduino. A photo of connections accompanying your code would be excellent.

SDO pin of the accelerometer is used as an alternate address line.
SDO=0 means the address is 0x53
SDO=1 means the address is 0x1d

make SDO pin of one accelerometer high and low for the other.

you can run I2C scanner after connecting the sensors(attached)

I2CScanner.ino (1.26 KB)

Manage to connect but cannot get all 6 values form your code.