Connecting 2 ADXL345 sensors to UNO

Hi there !

My project is to connect two ADXL 345 accelerometers to arduino through I2C interface. I have managed to code as shown below. The problem is that I am unable to get the X,Y,Z data of both sensors at the same time together as output; instead the serial print gives the below output and stops printing further.

OUTPUT of below code:-

CLEARSHEET
LABEL,Time,X0,Y0,Z0,X1,Y1,Z1
DATA,TIME,-4,12,255

As I am new to arduino and also as I do not have much knowledge of any programming languages, I am unable to find out the problem in the code.

I would be very happy if someone could suggest the errors and the solution to the problem I have.

Thanks !

#include <Wire.h>

#define accel_module (0x53)
#define accel_mod (0x1D)

byte values[6];
byte buff[6];
char output[512];
char out[512];

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

Serial.println("CLEARSHEET"); // for PLX-DAQ data to excel sheet
Serial.println("LABEL,Time,X0,Y0,Z0,X1,Y1,Z1");

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

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

void loop(){
  
int xyzregister = 0x32;
int x, y, z;

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

Wire.beginTransmission(accel_module);
Wire.requestFrom(accel_module, 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 %d %d", x, y, z);*/
Serial.print("DATA,TIME,");
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(","); 
Serial.print(z);

/*Serial.write(10);*/


////// 2nd ADXL345

int xyzreg = 0x32;
int x1, y1, z1;

Wire.beginTransmission(accel_mod);
Wire.write(xyzreg);
Wire.endTransmission();

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

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

x1 = (((int)buff[1]) << 8) | buff[0];    ///////change values to buff
y1 = (((int)buff[3]) << 8) | buff[2];
z1 = (((int)buff[5]) << 8) | buff[4];

Serial.print(x1);
Serial.print(";");
Serial.print(y1);
Serial.print(";");
Serial.println(z1);

delay(100);
}

From the data sheet:

With the ALT ADDRESS pin high, the 7-bit I2C address for the device is 0x1D, followed by the R/W bit. This translates to 0x3A for a write and 0x3B for a read. An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read.

Is the ALT ADDRESS pin broken out on your module? Is one ALT ADDRESS pin high and the other low? If the ALT ADDRESS pin is not broken out and you can't set the 2 addresses differently, you could use the SPI interface. Then you just need 2 chip selects to differentiate which accel that you want to talk to.

I do have 2 ADXL 345 sensors connected with SDO pin of one sensor high and another low (grounded).

The problem that I am facing is only in the program where I am unable to get output from both sensors at the same time simultaneously.