BrentSeidel / BBS-BBB-Ada

A collection of Ada sources for working with Linux based embedded computers, such as the BeagleBone Black or Raspberry Pi
GNU General Public License v3.0
7 stars 3 forks source link

Magnetometer readings out of range #2

Closed BrentSeidel closed 8 years ago

BrentSeidel commented 8 years ago

The outputs from the LSM303DLHC are often outside the expected range of +/-1.3 Gauss. The accelerometer readings on the other hand are sensible.

BrentSeidel commented 8 years ago

Close re-reading of the data sheet shows that the acceleration values are two byte values with the LSB in the lower addressed register (i.e. for x-acceleration the LSB is in address 16#28# while the MSB is in 16#29#). On the other hand, the magnetometer values are reversed (i.e. x-magnetomer has LSB in address 16#04# and MSB in 16#03#). The software was written assuming that both were the same.

BrentSeidel commented 8 years ago

Change the read function for uint16 in the i2c package to two functions: readm1 and readm2 for MSB first and MSB second reads. Updated L3GD20H and LSM303DLHC packages to use the new routines where appropriate. Things should work now with the latest commit, but as always, no guarantees.