delay 10s

Dependencies:   HX711 DHT DS1820

Committer:
nextzero
Date:
Sun Nov 22 18:04:18 2020 +0000
Revision:
5:df7af32714c0
Parent:
4:809b9c3a1739
Child:
6:5edb45f97ffe
4 capteur + poids;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ismatel77 0:2e0fc2c1e24c 1 #include "mbed.h"
ismatel77 0:2e0fc2c1e24c 2 #include "DHT.h"
ismatel77 0:2e0fc2c1e24c 3 #include "DS1820.h"
nextzero 5:df7af32714c0 4 #include "HX711.h"
ismatel77 0:2e0fc2c1e24c 5
nextzero 5:df7af32714c0 6 #define DHT1_DATA_PIN D4
nextzero 5:df7af32714c0 7 #define DHT2_DATA_PIN D5
ismatel77 0:2e0fc2c1e24c 8
nextzero 3:91c06faa6963 9
nextzero 3:91c06faa6963 10 DS1820 ds1820_1(D3); // substitute D8 with the actual pin name connected to the DS1820 sensor
nextzero 3:91c06faa6963 11 DS1820 ds1820_2(D6);
nextzero 4:809b9c3a1739 12 float temp1 = 0;
nextzero 4:809b9c3a1739 13 float temp2 = 0;
ismatel77 0:2e0fc2c1e24c 14 int result = 0;
ismatel77 0:2e0fc2c1e24c 15
nextzero 5:df7af32714c0 16 DHT sensor1(DHT1_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype)
nextzero 5:df7af32714c0 17 DHT sensor2(DHT2_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype)
nextzero 3:91c06faa6963 18 HX711 loadcell(D12, D11);
nextzero 3:91c06faa6963 19
ismatel77 0:2e0fc2c1e24c 20 Serial pc(USBTX, USBRX); // tx, rx
ismatel77 0:2e0fc2c1e24c 21 Serial device(D1, D0); // tx, rx
ismatel77 0:2e0fc2c1e24c 22
ismatel77 0:2e0fc2c1e24c 23 int main()
ismatel77 0:2e0fc2c1e24c 24 {
nextzero 5:df7af32714c0 25 int error1 = 0;
nextzero 5:df7af32714c0 26 int error2 = 0;
nextzero 5:df7af32714c0 27 float h_int = 0.0f, c_int = 0.0f,c_moyenne_int = 0.0f,h_ext = 0.0f,c_ext =0.0f;
nextzero 5:df7af32714c0 28 float valeur = 0.3f,balance=0.2f;
ismatel77 0:2e0fc2c1e24c 29 pc.baud(9600);
ismatel77 0:2e0fc2c1e24c 30 device.baud(9600);
ismatel77 0:2e0fc2c1e24c 31
nextzero 3:91c06faa6963 32 if (!ds1820_1.begin()){
ismatel77 0:2e0fc2c1e24c 33 pc.printf("No DS1820 sensor found!\r\n");
ismatel77 0:2e0fc2c1e24c 34 }
ismatel77 0:2e0fc2c1e24c 35 else{
ismatel77 0:2e0fc2c1e24c 36 pc.printf("DS1820 sensor found!\r\n");
ismatel77 0:2e0fc2c1e24c 37 }
ismatel77 0:2e0fc2c1e24c 38
nextzero 3:91c06faa6963 39 float valeurTare = loadcell.getValue();
nextzero 3:91c06faa6963 40
ismatel77 0:2e0fc2c1e24c 41 while(1) {
nextzero 3:91c06faa6963 42 float valeur = loadcell.getValue();
nextzero 3:91c06faa6963 43 float balance = ((double)valeur - (double)valeurTare)/21500;
nextzero 5:df7af32714c0 44 pc.printf("Weight = %.2f\r\n", balance);
ismatel77 0:2e0fc2c1e24c 45
nextzero 3:91c06faa6963 46 ds1820_1.startConversion(); // start temperature conversion from analog to digital
nextzero 3:91c06faa6963 47 ds1820_2.startConversion(); // start temperature conversion from analog to digital
ismatel77 0:2e0fc2c1e24c 48 ThisThread::sleep_for(1000);// let DS1820 complete the temperature conversion
nextzero 3:91c06faa6963 49
nextzero 4:809b9c3a1739 50 result = ds1820_1.read(temp1); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
nextzero 4:809b9c3a1739 51 result = ds1820_2.read(temp1);
nextzero 3:91c06faa6963 52
nextzero 3:91c06faa6963 53 error1 = sensor1.readData(); //read error value
nextzero 3:91c06faa6963 54 error2 = sensor2.readData(); //read error value
ismatel77 0:2e0fc2c1e24c 55
nextzero 4:809b9c3a1739 56 c_int = sensor1.ReadTemperature(CELCIUS);
nextzero 4:809b9c3a1739 57 h_int = sensor1.ReadHumidity();
nextzero 4:809b9c3a1739 58
nextzero 4:809b9c3a1739 59 c_ext = sensor2.ReadTemperature(CELCIUS);
nextzero 4:809b9c3a1739 60 h_ext = sensor2.ReadHumidity();
nextzero 3:91c06faa6963 61
nextzero 4:809b9c3a1739 62 c_moyenne_int =(c_int + temp1 + temp2)/3;
nextzero 4:809b9c3a1739 63
nextzero 5:df7af32714c0 64 pc.printf("temperature_int = %4.2f\r\n", c_moyenne_int); // on affiche les valeurs sur teraTerm pour debug
nextzero 5:df7af32714c0 65 pc.printf("Humidite_int = %4.2f\r\n", h_int);
nextzero 5:df7af32714c0 66 pc.printf("temperature_ext = %4.2f\r\n", c_ext); // on affiche les valeurs sur teraTerm pour debug
nextzero 5:df7af32714c0 67 pc.printf("Humidite_ext = %4.2f\r\n", h_ext);
nextzero 5:df7af32714c0 68
nextzero 3:91c06faa6963 69
nextzero 3:91c06faa6963 70
nextzero 4:809b9c3a1739 71 device.printf("AT$SF=%02X%02X%02X%02X\r\n", (char) c_moyenne_int,(char) h_int, (char) c_ext, (char) h_ext,(char) balance); // on envoie les données sur l'antenne
nextzero 5:df7af32714c0 72 wait(20.0f);
ismatel77 0:2e0fc2c1e24c 73 }
ismatel77 0:2e0fc2c1e24c 74 }