delay 10s
Dependencies: HX711 DHT DS1820
Diff: main.cpp
- Revision:
- 3:91c06faa6963
- Parent:
- 1:b811fd6ee6f5
- Child:
- 4:809b9c3a1739
diff -r d277d69a9888 -r 91c06faa6963 main.cpp --- a/main.cpp Sun Oct 18 17:32:23 2020 +0000 +++ b/main.cpp Sun Nov 22 17:33:57 2020 +0000 @@ -3,14 +3,19 @@ #include "DS1820.h" #define DHT_DATA_PIN D4 +#define DHT_DATA_PIN D5 -DS1820 ds1820(D3); // substitute D8 with the actual pin name connected to the DS1820 sensor + +DS1820 ds1820_1(D3); // substitute D8 with the actual pin name connected to the DS1820 sensor +DS1820 ds1820_2(D6); float temp = 0; int result = 0; -DHT sensor(DHT_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype) +DHT sensor1(DHT_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype) +DHT sensor2(DHT_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype) +HX711 loadcell(D12, D11); + Serial pc(USBTX, USBRX); // tx, rx - Serial device(D1, D0); // tx, rx int main() @@ -20,38 +25,40 @@ pc.baud(9600); device.baud(9600); - if (!ds1820.begin()){ + if (!ds1820_1.begin()){ pc.printf("No DS1820 sensor found!\r\n"); } else{ pc.printf("DS1820 sensor found!\r\n"); } + float valeurTare = loadcell.getValue(); + while(1) { + float valeur = loadcell.getValue(); + float balance = ((double)valeur - (double)valeurTare)/21500; + //pc.printf("Weight = %.2f\r\n", balance); - ds1820.startConversion(); // start temperature conversion from analog to digital + ds1820_1.startConversion(); // start temperature conversion from analog to digital + ds1820_2.startConversion(); // start temperature conversion from analog to digital ThisThread::sleep_for(1000);// let DS1820 complete the temperature conversion - result = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) - error = sensor.readData(); //read error value + + result1 = ds1820_1.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + result2 = ds1820_2.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + + error1 = sensor1.readData(); //read error value + error2 = sensor2.readData(); //read error value - c = sensor.ReadTemperature(CELCIUS); - h = sensor.ReadHumidity(); + c1 = sensor1.ReadTemperature(CELCIUS); + h1 = sensor1.ReadHumidity(); + c2 = sensor2.ReadTemperature(CELCIUS); + h2 = sensor2.ReadHumidity(); + pc.printf("temperature = %4.2f\r\n", c); // on affiche les valeurs sur teraTerm pour debug pc.printf("Humidite = %4.2f\r\n", h); - - switch (result) { - case 0: // no errors -> 'temp' contains the value of measured temperature - pc.printf("temp DS18B20 = %3.1f\r\n", temp); - break; - - case 1: // no sensor present -> 'temp' was not updated - pc.printf("no sensor present\n\r"); - break; - - case 2: // CRC error -> 'temp' was not updated - pc.printf("CRC error\r\n"); - } - device.printf("AT$SF=%02X%02X%02X\r\n", (char) c,(char) h, (char) temp); // on envoie les données sur l'antenne + + + device.printf("AT$SF=%02X%02X%02X%02X\r\n", (char) c,(char) h, (char) temp, (char) poids); // on envoie les données sur l'antenne wait(10.0f); } }