LSM303DLH 3D Compass and Accelerometer Carrier with Voltage Regulators

LSM303DLH 3D Compass and Accelerometer Carrier with Voltage Regulators
Pololu item #: 1250 0 in stock

This product has been discontinued.

The LSM303DLH combines a digital 3-axis accelerometer and 3-axis magnetometer into a single package that is ideal for making a tilt-compensated compass. The six independent readings, whose sensitivities can be set in the ranges of ±2 to ±8 g and ±1.3 to ±8.1 gauss, are available through an I²C interface. This LSM303 carrier board includes voltage regulators and a level-shifting circuit that allows operation from 2.6 to 5.5 V, and the 0.1" pin spacing makes it easy to use with standard solderless breadboards and 0.1" perfboards.

 Description Specifications (7) Pictures (5) Resources (7) FAQs (1) 
Why are some of my magnetometer readings -4096?
When the magnetometer reads -4096, it means the sensor reading is overflowing at the current gain setting.

From section 9.2.4 of the LSM303DLH datasheet (599k pdf):

In the event the ADC reading overflows or underflows for the given channel, or if there is a math overflow during the bias measurement, this data register will contain the value -4096 in 2’s complement form. This register value clears after the next valid measurement is made.

To avoid overflowing, try reducing the gain by setting the three gain-setting bits in CRB_REG_M. If you are using our Arduino library, insert this code into the setup method after compass.enable(); to get the lowest gain (largest sensor input field range) possible:

  Wire.beginTransmission(0x3C >> 1);
  Wire.send(0x01);
  // see table 62 in the datasheet for other gain_setting values
  byte gain_setting = 0b11100000; 
  Wire.send(gain_setting); 
  Wire.endTransmission();