9DOF IMU01a pololu

I am trying to get the data from a 9DOF IMU01a (pololu). the only thing I have is zeros 000000000000000 :slight_smile: 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.

thx for your help

Run the i2c_scanner
http://playground.arduino.cc/Main/I2cScanner
Perhaps you can dump the output in a post, so we can see the output.

Thx I have a sensor on 0x1E witch is the same as B0011110. So it was not the problem.

your i2c scanner should see at least two and probably three different i2c addresses.

there is 3 adress:

0x18
0x1E
0x69

I'm trying to talk to B0011110 or 0x1E

the output of the program is attach to this post.

Sensor reading.bmp (3.52 MB)

The scanner did find everything. That is good.

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.

You can use a library.
This is the most simple code that I could find : http://blog.solutions-cubed.com/lsm303-compass-tilt-compensation/
(Just ignore the accelerometer and tilt-compensation).

now I understand. thx for the more basic exemple you could find :blush:

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?