Embedded systems project

Dependencies:   mbed C12832 LSM6DS3

Committer:
lpeltoni
Date:
Tue Nov 05 13:18:13 2019 +0000
Revision:
5:8a233e9b04db
Parent:
4:7c5d90d151b6
Embedded systems project

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"
lpeltoni 4:7c5d90d151b6 5 #include "C12832.h"
beanmachine44 0:9632b831b6c1 6
beanmachine44 0:9632b831b6c1 7 // refresh time. set to 500 for part 2 and 50 for part 4
beanmachine44 0:9632b831b6c1 8 #define REFRESH_TIME_MS 1000
beanmachine44 0:9632b831b6c1 9
beanmachine44 0:9632b831b6c1 10 // Verify that the pin assignments below match your breadboard
beanmachine44 0:9632b831b6c1 11
lpeltoni 4:7c5d90d151b6 12 C12832 lcd(PA_7, PA_5, PA_9, PA_1, PA_0);
lpeltoni 4:7c5d90d151b6 13 LSM6DS3 sensor(PF_0, PF_1);
beanmachine44 0:9632b831b6c1 14
5hel2l2y 1:acf696b18c52 15 //Init Serial port and LSM6DS3 chip
beanmachine44 0:9632b831b6c1 16 void setup()
beanmachine44 0:9632b831b6c1 17 {
beanmachine44 0:9632b831b6c1 18 // Use the begin() function to initialize the LSM9DS0 library.
beanmachine44 0:9632b831b6c1 19 // You can either call it with no parameters (the easy way):
5hel2l2y 3:c450734baa8b 20 // SLEEP
5hel2l2y 3:c450734baa8b 21 //uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
5hel2l2y 3:c450734baa8b 22 // imu.G_POWER_DOWN, imu.A_POWER_DOWN);
5hel2l2y 3:c450734baa8b 23 // LOWEST
5hel2l2y 3:c450734baa8b 24 //uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
5hel2l2y 3:c450734baa8b 25 // imu.G_ODR_13_BW_0, imu.A_ODR_13);
5hel2l2y 3:c450734baa8b 26 // HIGHEST
lpeltoni 4:7c5d90d151b6 27 uint16_t status = sensor.begin(sensor.G_SCALE_2000DPS, sensor.A_SCALE_8G,
lpeltoni 4:7c5d90d151b6 28 sensor.G_ODR_1660, sensor.A_ODR_6660);
beanmachine44 0:9632b831b6c1 29
beanmachine44 0:9632b831b6c1 30 //Make sure communication is working
lpeltoni 4:7c5d90d151b6 31 lcd.cls();
lpeltoni 4:7c5d90d151b6 32 lcd.locate(0,3);
lpeltoni 4:7c5d90d151b6 33 lcd.printf("LSM6DS3 WHO_AM_I's returned: 0x%X\r\n", status);
lpeltoni 4:7c5d90d151b6 34 wait(1.0);
lpeltoni 4:7c5d90d151b6 35 lcd.locate(0,15);
lpeltoni 4:7c5d90d151b6 36 lcd.printf("Should be 0x69\r\n");
lpeltoni 4:7c5d90d151b6 37 wait(1.0);
beanmachine44 0:9632b831b6c1 38 }
beanmachine44 0:9632b831b6c1 39
beanmachine44 0:9632b831b6c1 40 int main()
beanmachine44 0:9632b831b6c1 41 {
beanmachine44 0:9632b831b6c1 42 setup(); //Setup sensor and Serial
lpeltoni 4:7c5d90d151b6 43 lcd.cls();
lpeltoni 4:7c5d90d151b6 44 lcd.locate(0,3);
lpeltoni 4:7c5d90d151b6 45 lcd.printf("\r\n----Mitataan!----\r\n");
lpeltoni 4:7c5d90d151b6 46 wait(1.0);
beanmachine44 0:9632b831b6c1 47
beanmachine44 0:9632b831b6c1 48 while (true)
beanmachine44 0:9632b831b6c1 49 {
lpeltoni 4:7c5d90d151b6 50 sensor.readTemp();
lpeltoni 4:7c5d90d151b6 51 lcd.cls();
lpeltoni 4:7c5d90d151b6 52 lcd.locate(0,3);
lpeltoni 4:7c5d90d151b6 53 lcd.printf("Temp:\r\n");
lpeltoni 4:7c5d90d151b6 54 lcd.locate(15,15);
lpeltoni 4:7c5d90d151b6 55 lcd.printf("TC: %2f\r\n", sensor.temperature_c);
lpeltoni 4:7c5d90d151b6 56 wait(1.0);
lpeltoni 4:7c5d90d151b6 57 lcd.cls();
lpeltoni 4:7c5d90d151b6 58 lcd.locate(15,15);
lpeltoni 4:7c5d90d151b6 59 lcd.printf("TF: %2f\r\n", sensor.temperature_f);
lpeltoni 4:7c5d90d151b6 60 wait(2.0);
beanmachine44 0:9632b831b6c1 61
lpeltoni 4:7c5d90d151b6 62 sensor.readAccel();
lpeltoni 4:7c5d90d151b6 63 lcd.cls();
lpeltoni 4:7c5d90d151b6 64 lcd.locate(0,3);
lpeltoni 4:7c5d90d151b6 65 lcd.printf("Accel:\r\n");
lpeltoni 4:7c5d90d151b6 66 lcd.locate(15, 15);
lpeltoni 4:7c5d90d151b6 67 lcd.printf("AX: %2f\r\n", sensor.ax);
lpeltoni 4:7c5d90d151b6 68 wait(1.0);
lpeltoni 4:7c5d90d151b6 69 lcd.cls();
lpeltoni 4:7c5d90d151b6 70 lcd.locate(15,15);
lpeltoni 4:7c5d90d151b6 71 lcd.printf("AY: %2f\r\n", sensor.ay);
lpeltoni 4:7c5d90d151b6 72 wait(1.0);
lpeltoni 4:7c5d90d151b6 73 lcd.cls();
lpeltoni 4:7c5d90d151b6 74 lcd.locate(15,15);
lpeltoni 4:7c5d90d151b6 75 lcd.printf("AZ: %2f\r\n", sensor.az);
lpeltoni 4:7c5d90d151b6 76 wait(1.0);
lpeltoni 4:7c5d90d151b6 77 wait(2.0);
beanmachine44 0:9632b831b6c1 78
lpeltoni 4:7c5d90d151b6 79 sensor.readGyro();
lpeltoni 4:7c5d90d151b6 80 lcd.cls();
lpeltoni 4:7c5d90d151b6 81 lcd.locate(0,3);
lpeltoni 4:7c5d90d151b6 82 lcd.printf("Gyro:\r\n");
lpeltoni 4:7c5d90d151b6 83 lcd.locate(15, 15);
lpeltoni 4:7c5d90d151b6 84 lcd.printf("GX: %2f\r\n", sensor.gx);
lpeltoni 4:7c5d90d151b6 85 wait(1.0);
lpeltoni 4:7c5d90d151b6 86 lcd.cls();
lpeltoni 4:7c5d90d151b6 87 lcd.locate(15, 15);
lpeltoni 4:7c5d90d151b6 88 lcd.printf("GY: %2f\r\n", sensor.gy);
lpeltoni 4:7c5d90d151b6 89 wait(1.0);
lpeltoni 4:7c5d90d151b6 90 lcd.cls();
lpeltoni 4:7c5d90d151b6 91 lcd.locate(15, 15);
lpeltoni 4:7c5d90d151b6 92 lcd.printf("GZ: %2f\r\n\r\n", sensor.gz);
lpeltoni 4:7c5d90d151b6 93 wait(2.0);
beanmachine44 0:9632b831b6c1 94
beanmachine44 0:9632b831b6c1 95 wait_ms(REFRESH_TIME_MS);
beanmachine44 0:9632b831b6c1 96 }
beanmachine44 0:9632b831b6c1 97 }