plot accelerometer data
Dependencies: mbed LSM9DS1_Library_cal
main.cpp@1:9e6bd185745d, 2020-06-25 (annotated)
- Committer:
- chebbi
- Date:
- Thu Jun 25 09:19:10 2020 +0000
- Revision:
- 1:9e6bd185745d
- Parent:
- 0:e693d5bf0a25
- Child:
- 3:201ee5790c15
plot ;
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:9e6bd185745d | 23 | |
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 | 1:9e6bd185745d | 29 | 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 | 1:9e6bd185745d | 30 | |
chebbi | 1:9e6bd185745d | 31 | pc.printf("%9f\n",acc) ; |
chebbi | 1:9e6bd185745d | 32 | wait(0.1) ; |
chebbi | 1:9e6bd185745d | 33 | |
chebbi | 1:9e6bd185745d | 34 | |
chebbi | 1:9e6bd185745d | 35 | |
chebbi | 1:9e6bd185745d | 36 | |
chebbi | 1:9e6bd185745d | 37 | |
4180_1 | 0:e693d5bf0a25 | 38 | } |
4180_1 | 0:e693d5bf0a25 | 39 | } |
4180_1 | 0:e693d5bf0a25 | 40 |