Lourdès Abou-tayeh / Mbed 2 deprecated Capteur1

Dependencies:   mbed

Committer:
louatayehh
Date:
Mon Sep 06 11:30:37 2021 +0000
Revision:
1:94d75a291f23
Parent:
0:c23b55e3ca7d
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 1:94d75a291f23 11 BMP280 bmp(i2c); //address par défaut= 0x77
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 1:94d75a291f23 28 //déclaration 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 BMPPressure = bmp.getPressure();
louatayehh 0:c23b55e3ca7d 35 bluetooth.printf("Pressure: %f\r\n",BMPPressure);
louatayehh 0:c23b55e3ca7d 36
louatayehh 0:c23b55e3ca7d 37 can.write(CANMessage(BMP_TMP_ID, (char*)&BMPTemp, sizeof(BMPTemp)/sizeof(char)));
louatayehh 1:94d75a291f23 38 wait(0.1); //Besoin de temps pour que la data arrive de façon nette
louatayehh 0:c23b55e3ca7d 39 can.write(CANMessage(BMP_PRES_ID, (char*)&BMPPressure, sizeof(BMPPressure)/sizeof(char)));
louatayehh 0:c23b55e3ca7d 40 wait(0.1);
louatayehh 0:c23b55e3ca7d 41 }
louatayehh 0:c23b55e3ca7d 42 }