I am trying to get the data from a 9DOF IMU01a (pololu). the only thing I have is zeros 000000000000000 from all sensors. I plug the SCL in A5 of my arduino uno, SDA in A4, Vin in 5 volt and Ground in Ground.
this is my code:
#include <Wire.h>
int Xlow = 0;
int Xhigh = 0;
int axeX = 0;
void setup()
{
 Wire.begin(); // i2c bus
 Serial.begin(9600);
Â
}
void loop()
{
 Wire.beginTransmission(B0011110); //(address magnetometre)
 Xlow = Wire.requestFrom(0x03,8); // adress axe X Low magnetometre
 Xhigh = Wire.requestFrom(0x04,8); // adress axe X High magnetometre
 Wire.endTransmission();
 axeX = Xlow << 8 | Xhigh;
 Serial.println( String(axeX , DEC) );
 delay(50);
}
there the data sheet from pololu:
register mapping p. 21 and 22
the adress of the sensors :
The gyro, accelerometer, and magnetometer each have separate slave addresses on the I²C bus. The gyro and accelerometer’s 7-bit slave addresses have their least significant bit (LSb) determined by the voltage on the SA0_G and SA0_A pins, respectively. The carrier board pulls SA0_G to 1.8 V and SA0_A to ground through 4.7k? resistors, setting the gyro’s slave address to 1101001b and the accelerometer’s slave address to 0011000b by default. If the gyro’s selected slave address happens to conflict with some other device on your I²C bus, you can drive SA0_G low to set the LSb to 0; similarly, you can drive SA0_A high (by connecting it to 1.8 V) to set the LSb of the accelerometer’s slave address to 1. The magnetometer’s slave address is 0011110b and cannot be changed.
Can you have a look at examples for Wire.requestFrom(address,number);
The "number" is the number of bytes, I think you want 2 bytes.
After Wire.requestFrom(), you have to do Wire.available() to check if you did receive 2 bytes, and after that read the bytes with Wire.read().
I wrote this code it always give me the same number 4112 for axeX, 16 for Xlow and Xhigh
#include <Wire.h>
int Xlow = 0;
int Xhigh = 0;
int axeX = 0;
void setup()
{
Wire.begin();
 Serial.begin(9600);
}
void loop()
{
 Â
 Wire.requestFrom(0x1E,2); //magnetometer adress,request 2 bytes
 while(Wire.available())
 {
 Xlow = Wire.read();
 Xhigh = Wire.read();
  axeX = Xlow << 8 | Xhigh;
  Serial.println( axeX );
 }
 delay(500);
}
You can not just read from and hoping that you get the right numbers.
The chip has internal registers, you have to write the address of the internal register before you can read the data from that register.
And I think the chip also needs some initialization.
while(Wire.available())
{
Xlow = Wire.read();
Xhigh = Wire.read();
While there is at least one byte to read, read two of them. Does that REALLY seem like a good idea?