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

Dependencies:   L3GD20 LSM303DLH mbed-src

Committer:
paulcox
Date:
Wed Oct 15 15:03:11 2014 +0000
Revision:
0:234c3e7cbd28
Tested as working on all Nucleo boards updated to firmware 2j23m6: led blinks and I2C magnetometer heading received properly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
paulcox 0:234c3e7cbd28 1 #include "mbed.h"
paulcox 0:234c3e7cbd28 2 #include "L3GD20.h"
paulcox 0:234c3e7cbd28 3 #include "LSM303DLH.h"
paulcox 0:234c3e7cbd28 4 //PwmOut mypwm(PWM_OUT);
paulcox 0:234c3e7cbd28 5
paulcox 0:234c3e7cbd28 6 DigitalOut myled(LED1);
paulcox 0:234c3e7cbd28 7 //I2C i2c(PB_9, PB_8);
paulcox 0:234c3e7cbd28 8 L3GD20 gyro(PB_9, PB_8);
paulcox 0:234c3e7cbd28 9 LSM303DLH magacc(PB_9, PB_8);
paulcox 0:234c3e7cbd28 10
paulcox 0:234c3e7cbd28 11 int main() {
paulcox 0:234c3e7cbd28 12
paulcox 0:234c3e7cbd28 13 // mypwm.period_ms(10);
paulcox 0:234c3e7cbd28 14 // mypwm.pulsewidth_ms(1);
paulcox 0:234c3e7cbd28 15
paulcox 0:234c3e7cbd28 16
paulcox 0:234c3e7cbd28 17 // int address = 0xd6;
paulcox 0:234c3e7cbd28 18 // int whoami = 0x0f;
paulcox 0:234c3e7cbd28 19 // int temp = 0x26;
paulcox 0:234c3e7cbd28 20 // char data[2];
paulcox 0:234c3e7cbd28 21 // char cmd[1];
paulcox 0:234c3e7cbd28 22 // cmd[0] = whoami;
paulcox 0:234c3e7cbd28 23 // i2c.frequency(100000);
paulcox 0:234c3e7cbd28 24 //magacc.frequency(100000);
paulcox 0:234c3e7cbd28 25
paulcox 0:234c3e7cbd28 26 float x,y,z;
paulcox 0:234c3e7cbd28 27 float hdg;
paulcox 0:234c3e7cbd28 28 int accs[3];
paulcox 0:234c3e7cbd28 29 vector a,m;
paulcox 0:234c3e7cbd28 30 magacc.setOffset(29.50, -0.50, 4.00); // example calibration
paulcox 0:234c3e7cbd28 31 magacc.setScale(1.00, 1.03, 1.21); // example calibration
paulcox 0:234c3e7cbd28 32
paulcox 0:234c3e7cbd28 33 while(1) {
paulcox 0:234c3e7cbd28 34 myled = !myled;
paulcox 0:234c3e7cbd28 35 wait(0.5);
paulcox 0:234c3e7cbd28 36 //i2c.write(address, cmd, 1, true);
paulcox 0:234c3e7cbd28 37 //i2c.read(address, data, 1);
paulcox 0:234c3e7cbd28 38 //printf("I2C data: %x \r\n", data[0]);
paulcox 0:234c3e7cbd28 39 gyro.read(&x,&y,&z);
paulcox 0:234c3e7cbd28 40 printf("x:%f y:%f z:%f\r\n",x,y,z);
paulcox 0:234c3e7cbd28 41 //hdg = magacc.heading();
paulcox 0:234c3e7cbd28 42 //printf("heading: %.2f\r\n",hdg);
paulcox 0:234c3e7cbd28 43 //magacc.read(a,m);
paulcox 0:234c3e7cbd28 44 //magacc.readAcc(accs);
paulcox 0:234c3e7cbd28 45 //printf("Ax %d,Ay %d,Az %d\r\n",accs[0],accs[1],accs[2]);
paulcox 0:234c3e7cbd28 46 //printf("Ax %f,Ay %f,Az %f\r\n",a.x,a.y,a.z);
paulcox 0:234c3e7cbd28 47 hdg = magacc.heading();
paulcox 0:234c3e7cbd28 48 printf("Heading: %.2f\r\n", hdg);
paulcox 0:234c3e7cbd28 49 //printf("Mx %f,My %f,Mz %f\r\n",m.x,m.y,m.z);
paulcox 0:234c3e7cbd28 50 }
paulcox 0:234c3e7cbd28 51 }