![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
main.cpp@6:16ba206a4253, 2020-06-04 (annotated)
- Committer:
- raketitch
- Date:
- Thu Jun 04 15:24:30 2020 +0000
- Revision:
- 6:16ba206a4253
- Parent:
- 3:c450734baa8b
- Child:
- 7:e5f8936d11af
04/06/2020 17:23
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" |
raketitch | 6:16ba206a4253 | 4 | #include "LSM6DS3.h" //sensor |
raketitch | 6:16ba206a4253 | 5 | #include "LCD_DISCO_F746NG.h" //LCD Screen |
raketitch | 6:16ba206a4253 | 6 | #include "TS_DISCO_F746NG.h" //Touch Screen |
beanmachine44 | 0:9632b831b6c1 | 7 | |
beanmachine44 | 0:9632b831b6c1 | 8 | // refresh time. set to 500 for part 2 and 50 for part 4 |
raketitch | 6:16ba206a4253 | 9 | #define REFRESH_TIME_MS 500 |
beanmachine44 | 0:9632b831b6c1 | 10 | |
beanmachine44 | 0:9632b831b6c1 | 11 | // Verify that the pin assignments below match your breadboard |
raketitch | 6:16ba206a4253 | 12 | LSM6DS3 sensor(PB_9, PB_8); //SCL, SDA |
raketitch | 6:16ba206a4253 | 13 | LCD_DISCO_F746NG lcd; |
raketitch | 6:16ba206a4253 | 14 | TS_DISCO_F746NG ts; |
raketitch | 6:16ba206a4253 | 15 | Serial pc(USBTX, USBRX); // tx, rx |
raketitch | 6:16ba206a4253 | 16 | |
raketitch | 6:16ba206a4253 | 17 | //prototypes |
raketitch | 6:16ba206a4253 | 18 | void setup(); |
raketitch | 6:16ba206a4253 | 19 | void lcd_print(uint16_t x, uint16_t y, char* text); |
raketitch | 6:16ba206a4253 | 20 | void lcd_print(uint16_t x, uint16_t y, char* text, float data); |
raketitch | 6:16ba206a4253 | 21 | |
raketitch | 6:16ba206a4253 | 22 | //Global Data |
raketitch | 6:16ba206a4253 | 23 | char text[30]; |
raketitch | 6:16ba206a4253 | 24 | |
raketitch | 6:16ba206a4253 | 25 | |
raketitch | 6:16ba206a4253 | 26 | |
raketitch | 6:16ba206a4253 | 27 | using namespace std; |
raketitch | 6:16ba206a4253 | 28 | |
raketitch | 6:16ba206a4253 | 29 | int main() |
raketitch | 6:16ba206a4253 | 30 | { |
raketitch | 6:16ba206a4253 | 31 | //Init Serial port and LSM6DS3 chip |
raketitch | 6:16ba206a4253 | 32 | setup(); |
raketitch | 6:16ba206a4253 | 33 | pc.printf("\r\n------ LSM6DS3 Demo -----------\r\n"); |
raketitch | 6:16ba206a4253 | 34 | |
raketitch | 6:16ba206a4253 | 35 | TS_StateTypeDef TS_State; |
raketitch | 6:16ba206a4253 | 36 | |
raketitch | 6:16ba206a4253 | 37 | uint16_t i; |
beanmachine44 | 0:9632b831b6c1 | 38 | |
raketitch | 6:16ba206a4253 | 39 | while (true) |
raketitch | 6:16ba206a4253 | 40 | { |
raketitch | 6:16ba206a4253 | 41 | i = 0; |
raketitch | 6:16ba206a4253 | 42 | //lcd.Clear(LCD_COLOR_BLACK); |
raketitch | 6:16ba206a4253 | 43 | |
raketitch | 6:16ba206a4253 | 44 | sensor.readTemp(); |
raketitch | 6:16ba206a4253 | 45 | |
raketitch | 6:16ba206a4253 | 46 | lcd_print(0, i, "temperature : %0.3f", sensor.temperature_c); |
raketitch | 6:16ba206a4253 | 47 | i++; |
raketitch | 6:16ba206a4253 | 48 | |
raketitch | 6:16ba206a4253 | 49 | sensor.readAccel(); |
raketitch | 6:16ba206a4253 | 50 | |
raketitch | 6:16ba206a4253 | 51 | lcd_print(0, i, "acc X : %0.3f", sensor.ax); |
raketitch | 6:16ba206a4253 | 52 | i++; |
raketitch | 6:16ba206a4253 | 53 | lcd_print(0, i, "acc Y : %0.3f", sensor.ay); |
raketitch | 6:16ba206a4253 | 54 | i++; |
raketitch | 6:16ba206a4253 | 55 | lcd_print(0, i, "acc Z : %0.3f", sensor.az); |
raketitch | 6:16ba206a4253 | 56 | i++; |
beanmachine44 | 0:9632b831b6c1 | 57 | |
raketitch | 6:16ba206a4253 | 58 | sensor.readGyro(); |
raketitch | 6:16ba206a4253 | 59 | |
raketitch | 6:16ba206a4253 | 60 | lcd_print(0, i, "gyro X : %0.3f", sensor.gx); |
raketitch | 6:16ba206a4253 | 61 | i++; |
raketitch | 6:16ba206a4253 | 62 | lcd_print(0, i, "gyro Y : %0.3f", sensor.gy); |
raketitch | 6:16ba206a4253 | 63 | i++; |
raketitch | 6:16ba206a4253 | 64 | lcd_print(0, i, "gyro Z : %0.3f", sensor.gz); |
raketitch | 6:16ba206a4253 | 65 | |
raketitch | 6:16ba206a4253 | 66 | ts.GetState(&TS_State); |
raketitch | 6:16ba206a4253 | 67 | |
raketitch | 6:16ba206a4253 | 68 | if(TS_State.touchDetected) |
raketitch | 6:16ba206a4253 | 69 | { |
raketitch | 6:16ba206a4253 | 70 | pc.printf("touched"); |
raketitch | 6:16ba206a4253 | 71 | } |
raketitch | 6:16ba206a4253 | 72 | |
raketitch | 6:16ba206a4253 | 73 | wait_ms(REFRESH_TIME_MS); |
raketitch | 6:16ba206a4253 | 74 | } |
raketitch | 6:16ba206a4253 | 75 | } |
raketitch | 6:16ba206a4253 | 76 | |
beanmachine44 | 0:9632b831b6c1 | 77 | void setup() |
beanmachine44 | 0:9632b831b6c1 | 78 | { |
5hel2l2y | 3:c450734baa8b | 79 | // HIGHEST |
raketitch | 6:16ba206a4253 | 80 | uint16_t status = sensor.begin(sensor.G_SCALE_2000DPS, sensor.A_SCALE_8G, |
raketitch | 6:16ba206a4253 | 81 | sensor.G_ODR_1660, sensor.A_ODR_6660); |
beanmachine44 | 0:9632b831b6c1 | 82 | |
beanmachine44 | 0:9632b831b6c1 | 83 | //Make sure communication is working |
5hel2l2y | 1:acf696b18c52 | 84 | pc.printf("LSM6DS3 WHO_AM_I's returned: 0x%X\r\n", status); |
5hel2l2y | 1:acf696b18c52 | 85 | pc.printf("Should be 0x69\r\n"); |
raketitch | 6:16ba206a4253 | 86 | |
raketitch | 6:16ba206a4253 | 87 | lcd.SetBackColor(LCD_COLOR_BLACK); |
raketitch | 6:16ba206a4253 | 88 | lcd.SetTextColor(LCD_COLOR_WHITE); |
raketitch | 6:16ba206a4253 | 89 | lcd.SetFont(&Font12); |
raketitch | 6:16ba206a4253 | 90 | |
raketitch | 6:16ba206a4253 | 91 | pc.printf("LDSM6DS3 Init\r\n"); |
raketitch | 6:16ba206a4253 | 92 | lcd_print(0, 0, "Init LSM6DS3"); |
raketitch | 6:16ba206a4253 | 93 | |
raketitch | 6:16ba206a4253 | 94 | pc.printf("LCD Init\r\n"); |
raketitch | 6:16ba206a4253 | 95 | lcd_print(0, 1, "LCD init"); |
raketitch | 6:16ba206a4253 | 96 | |
raketitch | 6:16ba206a4253 | 97 | |
beanmachine44 | 0:9632b831b6c1 | 98 | } |
beanmachine44 | 0:9632b831b6c1 | 99 | |
raketitch | 6:16ba206a4253 | 100 | void lcd_print(uint16_t x, uint16_t y, char* toto) |
beanmachine44 | 0:9632b831b6c1 | 101 | { |
raketitch | 6:16ba206a4253 | 102 | char txt[30]; |
raketitch | 6:16ba206a4253 | 103 | sprintf((char*)txt, (const char*) toto); |
raketitch | 6:16ba206a4253 | 104 | lcd.DisplayStringAt(x, LINE(y), (uint8_t *)&txt, LEFT_MODE); |
raketitch | 6:16ba206a4253 | 105 | } |
beanmachine44 | 0:9632b831b6c1 | 106 | |
raketitch | 6:16ba206a4253 | 107 | void lcd_print(uint16_t x, uint16_t y, char* toto, float data) |
raketitch | 6:16ba206a4253 | 108 | { |
raketitch | 6:16ba206a4253 | 109 | char txt[30]; |
raketitch | 6:16ba206a4253 | 110 | sprintf((char*)txt, (const char*) toto, data); |
raketitch | 6:16ba206a4253 | 111 | lcd.DisplayStringAt(x, LINE(y), (uint8_t *)&txt, LEFT_MODE); |
beanmachine44 | 0:9632b831b6c1 | 112 | } |