delay 10s

Dependencies:   HX711 DHT DS1820

Committer:
nextzero
Date:
Sun Nov 22 18:18:30 2020 +0000
Revision:
7:4894e844911e
Parent:
6:5edb45f97ffe
Child:
8:b4756746d196
UE

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 7:4894e844911e 39 if (!ds1820_2.begin()){
nextzero 7:4894e844911e 40 pc.printf("No DS1820 sensor found!\r\n");
nextzero 7:4894e844911e 41 }
nextzero 7:4894e844911e 42 else{
nextzero 7:4894e844911e 43 pc.printf("DS1820 sensor found!\r\n");
nextzero 7:4894e844911e 44 }
nextzero 7:4894e844911e 45
nextzero 3:91c06faa6963 46 float valeurTare = loadcell.getValue();
nextzero 3:91c06faa6963 47
ismatel77 0:2e0fc2c1e24c 48 while(1) {
nextzero 3:91c06faa6963 49 float valeur = loadcell.getValue();
nextzero 3:91c06faa6963 50 float balance = ((double)valeur - (double)valeurTare)/21500;
nextzero 5:df7af32714c0 51 pc.printf("Weight = %.2f\r\n", balance);
ismatel77 0:2e0fc2c1e24c 52
nextzero 3:91c06faa6963 53 ds1820_1.startConversion(); // start temperature conversion from analog to digital
nextzero 3:91c06faa6963 54 ds1820_2.startConversion(); // start temperature conversion from analog to digital
ismatel77 0:2e0fc2c1e24c 55 ThisThread::sleep_for(1000);// let DS1820 complete the temperature conversion
nextzero 3:91c06faa6963 56
nextzero 4:809b9c3a1739 57 result = ds1820_1.read(temp1); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
nextzero 7:4894e844911e 58 result = ds1820_2.read(temp2);
nextzero 3:91c06faa6963 59
nextzero 3:91c06faa6963 60 error1 = sensor1.readData(); //read error value
nextzero 3:91c06faa6963 61 error2 = sensor2.readData(); //read error value
ismatel77 0:2e0fc2c1e24c 62
nextzero 4:809b9c3a1739 63 c_int = sensor1.ReadTemperature(CELCIUS);
nextzero 4:809b9c3a1739 64 h_int = sensor1.ReadHumidity();
nextzero 4:809b9c3a1739 65
nextzero 4:809b9c3a1739 66 c_ext = sensor2.ReadTemperature(CELCIUS);
nextzero 4:809b9c3a1739 67 h_ext = sensor2.ReadHumidity();
nextzero 3:91c06faa6963 68
nextzero 4:809b9c3a1739 69 c_moyenne_int =(c_int + temp1 + temp2)/3;
nextzero 4:809b9c3a1739 70
nextzero 5:df7af32714c0 71 pc.printf("temperature_int = %4.2f\r\n", c_moyenne_int); // on affiche les valeurs sur teraTerm pour debug
nextzero 5:df7af32714c0 72 pc.printf("Humidite_int = %4.2f\r\n", h_int);
nextzero 5:df7af32714c0 73 pc.printf("temperature_ext = %4.2f\r\n", c_ext); // on affiche les valeurs sur teraTerm pour debug
nextzero 5:df7af32714c0 74 pc.printf("Humidite_ext = %4.2f\r\n", h_ext);
nextzero 7:4894e844911e 75 pc.printf("ds1 = %4.2f\r\n", temp1); // on affiche les valeurs sur teraTerm pour debug
nextzero 7:4894e844911e 76 pc.printf("ds2 = %4.2f\r\n", temp2);
nextzero 5:df7af32714c0 77
nextzero 3:91c06faa6963 78
nextzero 3:91c06faa6963 79
nextzero 6:5edb45f97ffe 80 device.printf("AT$SF=%02X%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 7:4894e844911e 81 wait(10.0f);
ismatel77 0:2e0fc2c1e24c 82 }
ismatel77 0:2e0fc2c1e24c 83 }