plot accelerometer data

Dependencies:   mbed LSM9DS1_Library_cal

Committer:
chebbi
Date:
Wed Jul 08 11:06:21 2020 +0000
Revision:
3:201ee5790c15
Parent:
1:9e6bd185745d
send acclerometer and gyro and  magnetometer data

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:e693d5bf0a25 1 #include "mbed.h"
4180_1 0:e693d5bf0a25 2 #include "LSM9DS1.h"
chebbi 1:9e6bd185745d 3
4180_1 0:e693d5bf0a25 4 // Earth's magnetic field varies by location. Add or subtract
4180_1 0:e693d5bf0a25 5 // a declination to get a more accurate heading. Calculate
4180_1 0:e693d5bf0a25 6 // your's here:
4180_1 0:e693d5bf0a25 7
4180_1 0:e693d5bf0a25 8
4180_1 0:e693d5bf0a25 9
chebbi 1:9e6bd185745d 10 Serial pc(USBTX, USBRX);
4180_1 0:e693d5bf0a25 11
4180_1 0:e693d5bf0a25 12
4180_1 0:e693d5bf0a25 13
4180_1 0:e693d5bf0a25 14
4180_1 0:e693d5bf0a25 15 int main()
4180_1 0:e693d5bf0a25 16 {
chebbi 1:9e6bd185745d 17
chebbi 1:9e6bd185745d 18 LSM9DS1 IMU(PC4, PC5,0xD6, 0x3C);
4180_1 0:e693d5bf0a25 19 IMU.begin();
4180_1 0:e693d5bf0a25 20 if (!IMU.begin()) {
4180_1 0:e693d5bf0a25 21 pc.printf("Failed to communicate with LSM9DS1.\n");
4180_1 0:e693d5bf0a25 22 }
chebbi 3:201ee5790c15 23 int i=0 ;
4180_1 0:e693d5bf0a25 24 while(1) {
chebbi 1:9e6bd185745d 25
4180_1 0:e693d5bf0a25 26 while(!IMU.accelAvailable());
4180_1 0:e693d5bf0a25 27 IMU.readAccel();
chebbi 1:9e6bd185745d 28
chebbi 3:201ee5790c15 29
chebbi 3:201ee5790c15 30 while( !IMU.gyroAvailable() )
chebbi 3:201ee5790c15 31
chebbi 3:201ee5790c15 32 IMU.readGyro();
chebbi 3:201ee5790c15 33
chebbi 3:201ee5790c15 34
chebbi 3:201ee5790c15 35 //float acc = sqrt(IMU.calcAccel(IMU.ax)*IMU.calcAccel(IMU.ax)+IMU.calcAccel(IMU.ay)*IMU.calcAccel(IMU.ay)+IMU.calcAccel(IMU.az)*IMU.calcAccel(IMU.az));
chebbi 3:201ee5790c15 36
chebbi 3:201ee5790c15 37 //pc.printf("%9f",acc) ;
chebbi 3:201ee5790c15 38 pc.printf("%d",i) ;
chebbi 1:9e6bd185745d 39
chebbi 3:201ee5790c15 40 pc.printf(",") ;
chebbi 3:201ee5790c15 41 pc.printf("%9f",IMU.calcAccel(IMU.ax)) ;
chebbi 3:201ee5790c15 42 pc.printf(",") ;
chebbi 3:201ee5790c15 43 pc.printf("%9f",IMU.calcAccel(IMU.ay)) ;
chebbi 3:201ee5790c15 44 pc.printf(",") ;
chebbi 3:201ee5790c15 45 pc.printf("%9f",IMU.calcAccel(IMU.az)) ;
chebbi 3:201ee5790c15 46 pc.printf(",") ;
chebbi 3:201ee5790c15 47
chebbi 3:201ee5790c15 48
chebbi 3:201ee5790c15 49 pc.printf("%9f",IMU.calcAccel(IMU.gx)) ;
chebbi 3:201ee5790c15 50 pc.printf(",") ;
chebbi 3:201ee5790c15 51 pc.printf("%9f",IMU.calcAccel(IMU.gy)) ;
chebbi 3:201ee5790c15 52 pc.printf(",") ;
chebbi 3:201ee5790c15 53 pc.printf("%9f",IMU.calcAccel(IMU.gz)) ;
chebbi 3:201ee5790c15 54 pc.printf(",") ;
chebbi 3:201ee5790c15 55
chebbi 3:201ee5790c15 56
chebbi 3:201ee5790c15 57 pc.printf("%9f",IMU.calcAccel(IMU.mx)) ;
chebbi 3:201ee5790c15 58 pc.printf(",") ;
chebbi 3:201ee5790c15 59 pc.printf("%9f",IMU.calcAccel(IMU.my)) ;
chebbi 3:201ee5790c15 60 pc.printf(",") ;
chebbi 3:201ee5790c15 61 pc.printf("%9f",IMU.calcAccel(IMU.mz)) ;
chebbi 3:201ee5790c15 62 pc.printf("%\n\r") ;
chebbi 3:201ee5790c15 63
chebbi 3:201ee5790c15 64 i++ ;
chebbi 1:9e6bd185745d 65 wait(0.1) ;
chebbi 1:9e6bd185745d 66
chebbi 1:9e6bd185745d 67
chebbi 1:9e6bd185745d 68
chebbi 1:9e6bd185745d 69
chebbi 1:9e6bd185745d 70
4180_1 0:e693d5bf0a25 71 }
4180_1 0:e693d5bf0a25 72 }
4180_1 0:e693d5bf0a25 73