#include <Wire.h>
byte a;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
// z-axis accelerometer
Wire.beginTransmission(0xA6); // the last bit of the address is write
Wire.send(0x36); //arduino seeks the correct register (z-axis value)
Wire.endTransmission();
Wire.requestFrom(0xA7,1); //arduino requests the value from the register of z-axis
//the last bit of the address is read
a=Wire.receive(); //the slave (IMU) sends the data
Serial.println("z-axis");
Serial.println(a,BIN);
}
I can’t understand why the serial output of arduino is always 0. i made the correct links and i don’t know if the mistake is about the serial.println part or about the I2C protocol part.
You have the incorrect I2C address for the part. The confusing bit (no pun intended) is that the Wire library takes care of the read/write bit automatically for you. This means that you need to drop the low bit and shift the address bits to the right by one position. In your case the address you would need to use is 0x53 (0xA6 or 0xA7 shifted right one position after dropping the low bit).
But i changed the code as you suggested, and the output of the z-axis is always zero.
Now the address that I’using is 0x53.
I also write the comand Wire.available() and it shows me that the IMU wants to send to arduino a byte, but the read value is zero, and this is impossible because it should read 9.81m/s^2.
Maybe I use the wrong register, but i checked it many times on the data sheet (linked above) and the z-axis register is 0x36 (for the first byte, the second one needs 0x37).
To call this register I use the comand Wire.send(0x36) is it correct??