![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Demo for LSM6DS3
Fork of LSM9DS1_Demo by
main.cpp@3:c450734baa8b, 2016-06-20 (annotated)
- Committer:
- 5hel2l2y
- Date:
- Mon Jun 20 19:16:14 2016 +0000
- Revision:
- 3:c450734baa8b
- Parent:
- 1:acf696b18c52
Demo will now be able to test different power modes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
5hel2l2y | 1:acf696b18c52 | 1 | // LSM6DS3 Demo |
beanmachine44 | 0:9632b831b6c1 | 2 | |
beanmachine44 | 0:9632b831b6c1 | 3 | #include "mbed.h" |
5hel2l2y | 1:acf696b18c52 | 4 | #include "LSM6DS3.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 |
5hel2l2y | 1:acf696b18c52 | 10 | LSM6DS3 imu(p30, p7); |
beanmachine44 | 0:9632b831b6c1 | 11 | |
5hel2l2y | 1:acf696b18c52 | 12 | Serial pc(p9, p11); |
beanmachine44 | 0:9632b831b6c1 | 13 | |
5hel2l2y | 1:acf696b18c52 | 14 | //Init Serial port and LSM6DS3 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): |
5hel2l2y | 3:c450734baa8b | 19 | // SLEEP |
5hel2l2y | 3:c450734baa8b | 20 | //uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G, |
5hel2l2y | 3:c450734baa8b | 21 | // imu.G_POWER_DOWN, imu.A_POWER_DOWN); |
5hel2l2y | 3:c450734baa8b | 22 | // LOWEST |
5hel2l2y | 3:c450734baa8b | 23 | //uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G, |
5hel2l2y | 3:c450734baa8b | 24 | // imu.G_ODR_13_BW_0, imu.A_ODR_13); |
5hel2l2y | 3:c450734baa8b | 25 | // HIGHEST |
5hel2l2y | 3:c450734baa8b | 26 | uint16_t status = imu.begin(imu.G_SCALE_2000DPS, imu.A_SCALE_8G, |
5hel2l2y | 3:c450734baa8b | 27 | imu.G_ODR_1660, imu.A_ODR_6660); |
beanmachine44 | 0:9632b831b6c1 | 28 | |
beanmachine44 | 0:9632b831b6c1 | 29 | //Make sure communication is working |
5hel2l2y | 1:acf696b18c52 | 30 | pc.printf("LSM6DS3 WHO_AM_I's returned: 0x%X\r\n", status); |
5hel2l2y | 1:acf696b18c52 | 31 | pc.printf("Should be 0x69\r\n"); |
beanmachine44 | 0:9632b831b6c1 | 32 | } |
beanmachine44 | 0:9632b831b6c1 | 33 | |
beanmachine44 | 0:9632b831b6c1 | 34 | int main() |
beanmachine44 | 0:9632b831b6c1 | 35 | { |
beanmachine44 | 0:9632b831b6c1 | 36 | setup(); //Setup sensor and Serial |
5hel2l2y | 1:acf696b18c52 | 37 | pc.printf("\r\n------ LSM6DS3 Demo -----------\r\n"); |
beanmachine44 | 0:9632b831b6c1 | 38 | |
beanmachine44 | 0:9632b831b6c1 | 39 | while (true) |
beanmachine44 | 0:9632b831b6c1 | 40 | { |
5hel2l2y | 1:acf696b18c52 | 41 | imu.readTemp(); |
5hel2l2y | 1:acf696b18c52 | 42 | pc.printf("Temp:\r\n"); |
5hel2l2y | 1:acf696b18c52 | 43 | pc.printf("TC: %2f\r\n", imu.temperature_c); |
5hel2l2y | 1:acf696b18c52 | 44 | pc.printf("TF: %2f\r\n", imu.temperature_f); |
beanmachine44 | 0:9632b831b6c1 | 45 | |
beanmachine44 | 0:9632b831b6c1 | 46 | imu.readAccel(); |
5hel2l2y | 1:acf696b18c52 | 47 | pc.printf("Accel:\r\n"); |
5hel2l2y | 1:acf696b18c52 | 48 | pc.printf("AX: %2f\r\n", imu.ax); |
5hel2l2y | 1:acf696b18c52 | 49 | pc.printf("AY: %2f\r\n", imu.ay); |
5hel2l2y | 1:acf696b18c52 | 50 | pc.printf("AZ: %2f\r\n", imu.az); |
beanmachine44 | 0:9632b831b6c1 | 51 | |
beanmachine44 | 0:9632b831b6c1 | 52 | imu.readGyro(); |
5hel2l2y | 1:acf696b18c52 | 53 | pc.printf("Gyro:\r\n"); |
5hel2l2y | 1:acf696b18c52 | 54 | pc.printf("GX: %2f\r\n", imu.gx); |
5hel2l2y | 1:acf696b18c52 | 55 | pc.printf("GY: %2f\r\n", imu.gy); |
5hel2l2y | 1:acf696b18c52 | 56 | pc.printf("GZ: %2f\r\n\r\n", imu.gz); |
beanmachine44 | 0:9632b831b6c1 | 57 | |
beanmachine44 | 0:9632b831b6c1 | 58 | wait_ms(REFRESH_TIME_MS); |
beanmachine44 | 0:9632b831b6c1 | 59 | } |
beanmachine44 | 0:9632b831b6c1 | 60 | } |