Lourdès Abou-tayeh / Mbed 2 deprecated Capteur1

Dependencies:   mbed

Committer:
louatayehh
Date:
Mon Sep 06 09:15:22 2021 +0000
Revision:
0:c23b55e3ca7d
Child:
1:94d75a291f23
Capteur 1 : BMP280

Who changed what in which revision?

UserRevisionLine numberNew contents of line
louatayehh 0:c23b55e3ca7d 1 #include "mbed.h"
louatayehh 0:c23b55e3ca7d 2 #include "BMP280.h"
louatayehh 0:c23b55e3ca7d 3
louatayehh 0:c23b55e3ca7d 4 #define BMP_TMP_ID 0x8
louatayehh 0:c23b55e3ca7d 5 #define BMP_PRES_ID 0x9
louatayehh 0:c23b55e3ca7d 6
louatayehh 0:c23b55e3ca7d 7 //declarations
louatayehh 0:c23b55e3ca7d 8 Serial bluetooth(p9, p10); //tx, rx
louatayehh 0:c23b55e3ca7d 9 CAN can(p30,p29); //CAN
louatayehh 0:c23b55e3ca7d 10 I2C i2c(p9,p10); //SDA, SCL
louatayehh 0:c23b55e3ca7d 11 BMP280 bmp(i2c); //Default address = 0x76
louatayehh 0:c23b55e3ca7d 12
louatayehh 0:c23b55e3ca7d 13
louatayehh 0:c23b55e3ca7d 14 int main()
louatayehh 0:c23b55e3ca7d 15 {
louatayehh 0:c23b55e3ca7d 16
louatayehh 0:c23b55e3ca7d 17 //Configuration Serial
louatayehh 0:c23b55e3ca7d 18 bluetooth.baud(56000);
louatayehh 0:c23b55e3ca7d 19 //bluetooth.format(8, SerialBase::None, 1);
louatayehh 0:c23b55e3ca7d 20 //bluetooth.set_flow_control(SerialBase::Disabled, NC, NC);
louatayehh 0:c23b55e3ca7d 21
louatayehh 0:c23b55e3ca7d 22 //Configuration bus CAN
louatayehh 0:c23b55e3ca7d 23 can.frequency(125000); //vitesse du bus CAN 125kHz
louatayehh 0:c23b55e3ca7d 24 can.reset();
louatayehh 0:c23b55e3ca7d 25
louatayehh 0:c23b55e3ca7d 26 //bmp.initialize();
louatayehh 0:c23b55e3ca7d 27
louatayehh 0:c23b55e3ca7d 28 //declaration des variables d'affichage
louatayehh 0:c23b55e3ca7d 29 float BMPTemp = 0;
louatayehh 0:c23b55e3ca7d 30 float BMPPressure = 0;
louatayehh 0:c23b55e3ca7d 31
louatayehh 0:c23b55e3ca7d 32 //affichage de la variable de pression
louatayehh 0:c23b55e3ca7d 33 while(1) {
louatayehh 0:c23b55e3ca7d 34 //BMPTemp = (bmp.getTemperature() - 32) / 1.8f;
louatayehh 0:c23b55e3ca7d 35 BMPPressure = bmp.getPressure();
louatayehh 0:c23b55e3ca7d 36 //bluetooth.printf("Temp: %f, Pressure: %f\r\n",BMPTemp, BMPPressure);
louatayehh 0:c23b55e3ca7d 37
louatayehh 0:c23b55e3ca7d 38 bluetooth.printf("Pressure: %f\r\n",BMPPressure);
louatayehh 0:c23b55e3ca7d 39
louatayehh 0:c23b55e3ca7d 40
louatayehh 0:c23b55e3ca7d 41 can.write(CANMessage(BMP_TMP_ID, (char*)&BMPTemp, sizeof(BMPTemp)/sizeof(char)));
louatayehh 0:c23b55e3ca7d 42 wait(0.1); //Need waits for some reason, without them the data doesnt always arrive in a neat order
louatayehh 0:c23b55e3ca7d 43 can.write(CANMessage(BMP_PRES_ID, (char*)&BMPPressure, sizeof(BMPPressure)/sizeof(char)));
louatayehh 0:c23b55e3ca7d 44 wait(0.1);
louatayehh 0:c23b55e3ca7d 45 }
louatayehh 0:c23b55e3ca7d 46 }