5 years, 10 months ago.

Working With LSM303DLH

I loaded this code straight from the library and hooked up the correct wires. SDA to pin 28 and SCL to pin 27 and Vout (mBed) to Vin (LSM303) and Ground to Ground.


I connected my tilt compass to the mbed controller and started getting strange values.

include the mbed library with this snippet

#include "mbed.h"
#include "LSM303DLH.h"

Serial debug(USBTX,USBRX);
LSM303DLH compass(p28, p27);

int main() {
  float hdg;
  float hdgV;
  vector acc;
  vector mag;
  debug.printf("LSM303DLH Test\x0d\x0a");
  compass.setOffset(0.00,0.00,0.00); // example calibration
  compass.setScale(1.00,1.00,1.00);    // example calibration
  while(1) {
    hdg = compass.heading();
    hdgV = atan2(acc.y,acc.z) * 180/M_PI;
    debug.printf("ACC: %6.2f %6.2f %6.2f Heading: %6.2f %6.2f\n",acc.x,acc.y,acc.z,hdgV,hdg);


I'm not even getting the printf that as in my file.

This is the exact compass I am using https://www.sparkfun.com/products/retired/10888

What is happening?

Be the first to answer this question.