Demo for LSM6DS3

Dependencies:   LSM6DS3 mbed

Fork of LSM9DS1_Demo by Eugene Gonzalez

Committer:
5hel2l2y
Date:
Thu Jun 16 20:07:34 2016 +0000
Revision:
1:acf696b18c52
Parent:
0:9632b831b6c1
Child:
3:c450734baa8b
Modified to work with LSM6DS3

Who changed what in which revision?

UserRevisionLine numberNew 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):
beanmachine44 0:9632b831b6c1 19 uint16_t status = imu.begin();
beanmachine44 0:9632b831b6c1 20
beanmachine44 0:9632b831b6c1 21 //Make sure communication is working
5hel2l2y 1:acf696b18c52 22 pc.printf("LSM6DS3 WHO_AM_I's returned: 0x%X\r\n", status);
5hel2l2y 1:acf696b18c52 23 pc.printf("Should be 0x69\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
5hel2l2y 1:acf696b18c52 29 pc.printf("\r\n------ LSM6DS3 Demo -----------\r\n");
beanmachine44 0:9632b831b6c1 30
beanmachine44 0:9632b831b6c1 31 while (true)
beanmachine44 0:9632b831b6c1 32 {
5hel2l2y 1:acf696b18c52 33 imu.readTemp();
5hel2l2y 1:acf696b18c52 34 pc.printf("Temp:\r\n");
5hel2l2y 1:acf696b18c52 35 pc.printf("TC: %2f\r\n", imu.temperature_c);
5hel2l2y 1:acf696b18c52 36 pc.printf("TF: %2f\r\n", imu.temperature_f);
beanmachine44 0:9632b831b6c1 37
beanmachine44 0:9632b831b6c1 38 imu.readAccel();
5hel2l2y 1:acf696b18c52 39 pc.printf("Accel:\r\n");
5hel2l2y 1:acf696b18c52 40 pc.printf("AX: %2f\r\n", imu.ax);
5hel2l2y 1:acf696b18c52 41 pc.printf("AY: %2f\r\n", imu.ay);
5hel2l2y 1:acf696b18c52 42 pc.printf("AZ: %2f\r\n", imu.az);
beanmachine44 0:9632b831b6c1 43
beanmachine44 0:9632b831b6c1 44 imu.readGyro();
5hel2l2y 1:acf696b18c52 45 pc.printf("Gyro:\r\n");
5hel2l2y 1:acf696b18c52 46 pc.printf("GX: %2f\r\n", imu.gx);
5hel2l2y 1:acf696b18c52 47 pc.printf("GY: %2f\r\n", imu.gy);
5hel2l2y 1:acf696b18c52 48 pc.printf("GZ: %2f\r\n\r\n", imu.gz);
beanmachine44 0:9632b831b6c1 49
beanmachine44 0:9632b831b6c1 50 wait_ms(REFRESH_TIME_MS);
beanmachine44 0:9632b831b6c1 51 }
beanmachine44 0:9632b831b6c1 52 }