Projet d'interfaçage - LSM6DS3 : Test de Stabilité Quentin NOIRET LP MECSE 2020 -------------------------------------------------- L’application réalisée permet de tester la stabilité d’un système (ex : drone) en affichant différents seuils d’inclinaison en fonction des valeurs de l’accéléromètre.

Dependencies:   Interfacage_MECSE_LSM6DS3 mbed LSM6DS3

Revision:
6:16ba206a4253
Parent:
3:c450734baa8b
Child:
7:e5f8936d11af
--- a/main.cpp	Thu Jun 04 12:16:51 2020 +0000
+++ b/main.cpp	Thu Jun 04 15:24:30 2020 +0000
@@ -1,60 +1,112 @@
 // LSM6DS3 Demo
 
 #include "mbed.h"
-#include "LSM6DS3.h"
+#include "LSM6DS3.h"            //sensor 
+#include "LCD_DISCO_F746NG.h"   //LCD Screen
+#include "TS_DISCO_F746NG.h"    //Touch Screen
 
 // refresh time. set to 500 for part 2 and 50 for part 4
-#define REFRESH_TIME_MS 1000
+#define REFRESH_TIME_MS 500
 
 // Verify that the pin assignments below match your breadboard
-LSM6DS3 imu(p30, p7);
+LSM6DS3 sensor(PB_9, PB_8); //SCL, SDA
+LCD_DISCO_F746NG lcd;
+TS_DISCO_F746NG ts;
+Serial pc(USBTX, USBRX); // tx, rx
+
+//prototypes
+void setup();
+void lcd_print(uint16_t x, uint16_t y, char* text);
+void lcd_print(uint16_t x, uint16_t y, char* text, float data);
+
+//Global Data
+char text[30];
+
+
+
+using namespace std;
+
+int main()
+{
+    //Init Serial port and LSM6DS3 chip
+    setup(); 
+    pc.printf("\r\n------ LSM6DS3 Demo -----------\r\n");
+    
+    TS_StateTypeDef TS_State;
+    
+    uint16_t i;
 
-Serial pc(p9, p11);
+    while (true)
+    {
+        i = 0;
+        //lcd.Clear(LCD_COLOR_BLACK);
+        
+        sensor.readTemp();
+        
+        lcd_print(0, i, "temperature : %0.3f", sensor.temperature_c);
+        i++;
+        
+        sensor.readAccel();
+        
+        lcd_print(0, i, "acc X : %0.3f", sensor.ax);
+        i++;
+        lcd_print(0, i, "acc Y : %0.3f", sensor.ay);
+        i++;
+        lcd_print(0, i, "acc Z : %0.3f", sensor.az);
+        i++;
 
-//Init Serial port and LSM6DS3 chip
+        sensor.readGyro();
+        
+        lcd_print(0, i, "gyro X : %0.3f", sensor.gx);
+        i++;
+        lcd_print(0, i, "gyro Y : %0.3f", sensor.gy);
+        i++;
+        lcd_print(0, i, "gyro Z : %0.3f", sensor.gz);
+        
+        ts.GetState(&TS_State);
+        
+        if(TS_State.touchDetected)
+        {
+            pc.printf("touched");
+        }
+        
+        wait_ms(REFRESH_TIME_MS);
+    }
+}
+
 void setup()
 {
-    // Use the begin() function to initialize the LSM9DS0 library.
-    // You can either call it with no parameters (the easy way):
-    // SLEEP
-    //uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
-//                                imu.G_POWER_DOWN, imu.A_POWER_DOWN);
-    // LOWEST
-    //uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
-//                                imu.G_ODR_13_BW_0, imu.A_ODR_13);
     // HIGHEST
-    uint16_t status = imu.begin(imu.G_SCALE_2000DPS, imu.A_SCALE_8G,
-                                imu.G_ODR_1660, imu.A_ODR_6660);
+    uint16_t status = sensor.begin(sensor.G_SCALE_2000DPS, sensor.A_SCALE_8G,
+                                sensor.G_ODR_1660, sensor.A_ODR_6660);
 
     //Make sure communication is working
     pc.printf("LSM6DS3 WHO_AM_I's returned: 0x%X\r\n", status);
     pc.printf("Should be 0x69\r\n");
+    
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.SetFont(&Font12);
+    
+    pc.printf("LDSM6DS3 Init\r\n");
+    lcd_print(0, 0, "Init LSM6DS3");
+    
+    pc.printf("LCD Init\r\n");
+    lcd_print(0, 1, "LCD init");
+    
+    
 }
 
-int main()
+void lcd_print(uint16_t x, uint16_t y, char* toto)
 {
-    setup();  //Setup sensor and Serial
-    pc.printf("\r\n------ LSM6DS3 Demo -----------\r\n");
+    char txt[30];
+    sprintf((char*)txt, (const char*) toto);
+    lcd.DisplayStringAt(x, LINE(y), (uint8_t *)&txt, LEFT_MODE);
+}
 
-    while (true)
-    {
-        imu.readTemp();
-        pc.printf("Temp:\r\n");
-        pc.printf("TC: %2f\r\n", imu.temperature_c);
-        pc.printf("TF: %2f\r\n", imu.temperature_f);
-        
-        imu.readAccel();
-        pc.printf("Accel:\r\n");
-        pc.printf("AX: %2f\r\n", imu.ax);
-        pc.printf("AY: %2f\r\n", imu.ay);
-        pc.printf("AZ: %2f\r\n", imu.az);
-
-        imu.readGyro();
-        pc.printf("Gyro:\r\n");
-        pc.printf("GX: %2f\r\n", imu.gx);
-        pc.printf("GY: %2f\r\n", imu.gy);
-        pc.printf("GZ: %2f\r\n\r\n", imu.gz);
-       
-        wait_ms(REFRESH_TIME_MS);
-    }
+void lcd_print(uint16_t x, uint16_t y, char* toto, float data)
+{
+    char txt[30];
+    sprintf((char*)txt, (const char*) toto, data);
+    lcd.DisplayStringAt(x, LINE(y), (uint8_t *)&txt, LEFT_MODE);
 }