Chen Wei Ting
/
middleyuan
read EMG, IMU, encoder
Fork of LSM9DS1_project by
main.cpp@0:9632b831b6c1, 2015-10-19 (annotated)
- Committer:
- beanmachine44
- Date:
- Mon Oct 19 16:52:59 2015 +0000
- Revision:
- 0:9632b831b6c1
- Child:
- 1:b1562831bbaf
Initial commit of LSM9DS1 demo program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beanmachine44 | 0:9632b831b6c1 | 1 | // LSM9DS91 Demo |
beanmachine44 | 0:9632b831b6c1 | 2 | |
beanmachine44 | 0:9632b831b6c1 | 3 | #include "mbed.h" |
beanmachine44 | 0:9632b831b6c1 | 4 | #include "LSM9DS1.h" |
beanmachine44 | 0:9632b831b6c1 | 5 | |
beanmachine44 | 0:9632b831b6c1 | 6 | // refresh time. set to 500 for part 2 and 50 for part 4 |
beanmachine44 | 0:9632b831b6c1 | 7 | #define REFRESH_TIME_MS 1000 |
beanmachine44 | 0:9632b831b6c1 | 8 | |
beanmachine44 | 0:9632b831b6c1 | 9 | // Verify that the pin assignments below match your breadboard |
beanmachine44 | 0:9632b831b6c1 | 10 | LSM9DS1 imu(p9, p10); |
beanmachine44 | 0:9632b831b6c1 | 11 | |
beanmachine44 | 0:9632b831b6c1 | 12 | Serial pc(USBTX, USBRX); |
beanmachine44 | 0:9632b831b6c1 | 13 | |
beanmachine44 | 0:9632b831b6c1 | 14 | //Init Serial port and LSM9DS1 chip |
beanmachine44 | 0:9632b831b6c1 | 15 | void setup() |
beanmachine44 | 0:9632b831b6c1 | 16 | { |
beanmachine44 | 0:9632b831b6c1 | 17 | // Use the begin() function to initialize the LSM9DS0 library. |
beanmachine44 | 0:9632b831b6c1 | 18 | // You can either call it with no parameters (the easy way): |
beanmachine44 | 0:9632b831b6c1 | 19 | uint16_t status = imu.begin(); |
beanmachine44 | 0:9632b831b6c1 | 20 | |
beanmachine44 | 0:9632b831b6c1 | 21 | //Make sure communication is working |
beanmachine44 | 0:9632b831b6c1 | 22 | pc.printf("LSM9DS1 WHO_AM_I's returned: 0x%X\r\n", status); |
beanmachine44 | 0:9632b831b6c1 | 23 | pc.printf("Should be 0x683D\r\n"); |
beanmachine44 | 0:9632b831b6c1 | 24 | } |
beanmachine44 | 0:9632b831b6c1 | 25 | |
beanmachine44 | 0:9632b831b6c1 | 26 | int main() |
beanmachine44 | 0:9632b831b6c1 | 27 | { |
beanmachine44 | 0:9632b831b6c1 | 28 | setup(); //Setup sensor and Serial |
beanmachine44 | 0:9632b831b6c1 | 29 | pc.printf("------ LSM9DS1 Demo -----------\r\n"); |
beanmachine44 | 0:9632b831b6c1 | 30 | |
beanmachine44 | 0:9632b831b6c1 | 31 | while (true) |
beanmachine44 | 0:9632b831b6c1 | 32 | { |
beanmachine44 | 0:9632b831b6c1 | 33 | |
beanmachine44 | 0:9632b831b6c1 | 34 | imu.readAccel(); |
beanmachine44 | 0:9632b831b6c1 | 35 | |
beanmachine44 | 0:9632b831b6c1 | 36 | pc.printf("A: %2f, %2f, %2f\r\n", imu.ax, imu.ay, imu.az); |
beanmachine44 | 0:9632b831b6c1 | 37 | |
beanmachine44 | 0:9632b831b6c1 | 38 | imu.readGyro(); |
beanmachine44 | 0:9632b831b6c1 | 39 | |
beanmachine44 | 0:9632b831b6c1 | 40 | pc.printf("G: %2f, %2f, %2f\r\n", imu.gx, imu.gy, imu.gz); |
beanmachine44 | 0:9632b831b6c1 | 41 | |
beanmachine44 | 0:9632b831b6c1 | 42 | imu.readMag(); |
beanmachine44 | 0:9632b831b6c1 | 43 | |
beanmachine44 | 0:9632b831b6c1 | 44 | pc.printf("M: %2f, %2f, %2f\r\n\r\n", imu.mx, imu.my, imu.mz); |
beanmachine44 | 0:9632b831b6c1 | 45 | |
beanmachine44 | 0:9632b831b6c1 | 46 | wait_ms(REFRESH_TIME_MS); |
beanmachine44 | 0:9632b831b6c1 | 47 | } |
beanmachine44 | 0:9632b831b6c1 | 48 | } |