AdvRobot_Team / Mbed 2 deprecated LSM9DS1_SPI

Dependencies:   LSM9DS1_ADVRO mbed

Committer:
ChangYuHsuan
Date:
Wed Jun 21 07:14:46 2017 +0000
Revision:
0:a78e30188b92
Child:
1:182761476d79
LSM9DS1 SPI;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ChangYuHsuan 0:a78e30188b92 1 #include "LSM9DS1.h"
ChangYuHsuan 0:a78e30188b92 2
ChangYuHsuan 0:a78e30188b92 3 void timerInterrupt();
ChangYuHsuan 0:a78e30188b92 4
ChangYuHsuan 0:a78e30188b92 5 DigitalOut myled(LED1);
ChangYuHsuan 0:a78e30188b92 6 Serial pc(USBTX, USBRX);
ChangYuHsuan 0:a78e30188b92 7
ChangYuHsuan 0:a78e30188b92 8 Ticker timer1;
ChangYuHsuan 0:a78e30188b92 9 #define PERIOD 10000 // unit: us
ChangYuHsuan 0:a78e30188b92 10
ChangYuHsuan 0:a78e30188b92 11 // IMU in SPI mode
ChangYuHsuan 0:a78e30188b92 12 SPI imuSpi(PC_12, PC_11, PC_10); // MOSI, MISO, SCLK
ChangYuHsuan 0:a78e30188b92 13 DigitalOut agCS(PA_13);
ChangYuHsuan 0:a78e30188b92 14 DigitalOut mCS(PA_14);
ChangYuHsuan 0:a78e30188b92 15 LSM9DS1 imu(&imuSpi, &agCS, &mCS, 0xD6, 0x3C);
ChangYuHsuan 0:a78e30188b92 16
ChangYuHsuan 0:a78e30188b92 17 float dpsZ = 0.0f, degree = 0.0f;
ChangYuHsuan 0:a78e30188b92 18
ChangYuHsuan 0:a78e30188b92 19 int main() {
ChangYuHsuan 0:a78e30188b92 20
ChangYuHsuan 0:a78e30188b92 21 pc.baud(115200);
ChangYuHsuan 0:a78e30188b92 22
ChangYuHsuan 0:a78e30188b92 23 bool status = imu.begin();
ChangYuHsuan 0:a78e30188b92 24 pc.printf("connect or not: %d\n\r", status);
ChangYuHsuan 0:a78e30188b92 25
ChangYuHsuan 0:a78e30188b92 26 imu.calibrate();
ChangYuHsuan 0:a78e30188b92 27
ChangYuHsuan 0:a78e30188b92 28 timer1.attach_us(&timerInterrupt, PERIOD);
ChangYuHsuan 0:a78e30188b92 29
ChangYuHsuan 0:a78e30188b92 30 while(1) {
ChangYuHsuan 0:a78e30188b92 31
ChangYuHsuan 0:a78e30188b92 32 /*myled = 1;
ChangYuHsuan 0:a78e30188b92 33 imu.readGyro();
ChangYuHsuan 0:a78e30188b92 34
ChangYuHsuan 0:a78e30188b92 35 dpsZ = imu.calcGyro(imu.gz);
ChangYuHsuan 0:a78e30188b92 36 degree += dpsZ * 0.01f;
ChangYuHsuan 0:a78e30188b92 37 myled = 0;*/
ChangYuHsuan 0:a78e30188b92 38
ChangYuHsuan 0:a78e30188b92 39 pc.printf("gryo z: %.3f degree: %.3f \n\r", dpsZ, degree);
ChangYuHsuan 0:a78e30188b92 40
ChangYuHsuan 0:a78e30188b92 41 wait(0.01);
ChangYuHsuan 0:a78e30188b92 42 }
ChangYuHsuan 0:a78e30188b92 43 }
ChangYuHsuan 0:a78e30188b92 44
ChangYuHsuan 0:a78e30188b92 45 void timerInterrupt()
ChangYuHsuan 0:a78e30188b92 46 {
ChangYuHsuan 0:a78e30188b92 47 imu.readGyro();
ChangYuHsuan 0:a78e30188b92 48
ChangYuHsuan 0:a78e30188b92 49 dpsZ = imu.calcGyro(imu.gz);
ChangYuHsuan 0:a78e30188b92 50 degree += dpsZ * PERIOD / 1000000.0f;
ChangYuHsuan 0:a78e30188b92 51 }