Project tested on all Nucleo boards updated to firmware 2j23m6 with LED blinking and I2C magnetometer heading ok.

Dependencies:   L3GD20 LSM303DLH mbed-src

main.cpp

Committer:
paulcox
Date:
2014-10-15
Revision:
0:234c3e7cbd28

File content as of revision 0:234c3e7cbd28:

#include "mbed.h"
#include "L3GD20.h"
#include "LSM303DLH.h"
//PwmOut mypwm(PWM_OUT);

DigitalOut myled(LED1);
//I2C i2c(PB_9, PB_8);
L3GD20 gyro(PB_9, PB_8);
LSM303DLH magacc(PB_9, PB_8);
   
int main() {
    
//    mypwm.period_ms(10);
 //   mypwm.pulsewidth_ms(1);

 
 //   int address = 0xd6;
 //   int whoami = 0x0f;
 //   int temp = 0x26;
 //   char data[2];
 //   char cmd[1];
 //   cmd[0] = whoami;   
//    i2c.frequency(100000); 
    //magacc.frequency(100000);
   
    float x,y,z;
    float hdg;
    int accs[3];
    vector a,m;
    magacc.setOffset(29.50, -0.50, 4.00); // example calibration
    magacc.setScale(1.00, 1.03, 1.21);    // example calibration  
    
    while(1) {
        myled = !myled;
        wait(0.5);
        //i2c.write(address, cmd, 1, true);
        //i2c.read(address, data, 1);
        //printf("I2C data: %x \r\n", data[0]);
        gyro.read(&x,&y,&z);
        printf("x:%f y:%f z:%f\r\n",x,y,z);
        //hdg = magacc.heading();
        //printf("heading: %.2f\r\n",hdg);
        //magacc.read(a,m);
        //magacc.readAcc(accs);
        //printf("Ax %d,Ay %d,Az %d\r\n",accs[0],accs[1],accs[2]);
        //printf("Ax %f,Ay %f,Az %f\r\n",a.x,a.y,a.z);
        hdg = magacc.heading();
        printf("Heading: %.2f\r\n", hdg);
        //printf("Mx %f,My %f,Mz %f\r\n",m.x,m.y,m.z);
    }
}