delay 10s
Dependencies: HX711 DHT DS1820
main.cpp@4:809b9c3a1739, 2020-11-22 (annotated)
- Committer:
- nextzero
- Date:
- Sun Nov 22 17:43:42 2020 +0000
- Revision:
- 4:809b9c3a1739
- Parent:
- 3:91c06faa6963
- Child:
- 5:df7af32714c0
bruh;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ismatel77 | 0:2e0fc2c1e24c | 1 | #include "mbed.h" |
ismatel77 | 0:2e0fc2c1e24c | 2 | #include "DHT.h" |
ismatel77 | 0:2e0fc2c1e24c | 3 | #include "DS1820.h" |
ismatel77 | 0:2e0fc2c1e24c | 4 | |
ismatel77 | 0:2e0fc2c1e24c | 5 | #define DHT_DATA_PIN D4 |
nextzero | 3:91c06faa6963 | 6 | #define DHT_DATA_PIN D5 |
ismatel77 | 0:2e0fc2c1e24c | 7 | |
nextzero | 3:91c06faa6963 | 8 | |
nextzero | 3:91c06faa6963 | 9 | DS1820 ds1820_1(D3); // substitute D8 with the actual pin name connected to the DS1820 sensor |
nextzero | 3:91c06faa6963 | 10 | DS1820 ds1820_2(D6); |
nextzero | 4:809b9c3a1739 | 11 | float temp1 = 0; |
nextzero | 4:809b9c3a1739 | 12 | float temp2 = 0; |
ismatel77 | 0:2e0fc2c1e24c | 13 | int result = 0; |
ismatel77 | 0:2e0fc2c1e24c | 14 | |
nextzero | 3:91c06faa6963 | 15 | DHT sensor1(DHT_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype) |
nextzero | 3:91c06faa6963 | 16 | DHT sensor2(DHT_DATA_PIN, DHT22); //DHT(PinName pin, eType DHTtype) |
nextzero | 3:91c06faa6963 | 17 | HX711 loadcell(D12, D11); |
nextzero | 3:91c06faa6963 | 18 | |
ismatel77 | 0:2e0fc2c1e24c | 19 | Serial pc(USBTX, USBRX); // tx, rx |
ismatel77 | 0:2e0fc2c1e24c | 20 | Serial device(D1, D0); // tx, rx |
ismatel77 | 0:2e0fc2c1e24c | 21 | |
ismatel77 | 0:2e0fc2c1e24c | 22 | int main() |
ismatel77 | 0:2e0fc2c1e24c | 23 | { |
ismatel77 | 0:2e0fc2c1e24c | 24 | int error = 0; |
ismatel77 | 0:2e0fc2c1e24c | 25 | float h = 0.0f, c = 0.0f; |
ismatel77 | 0:2e0fc2c1e24c | 26 | pc.baud(9600); |
ismatel77 | 0:2e0fc2c1e24c | 27 | device.baud(9600); |
ismatel77 | 0:2e0fc2c1e24c | 28 | |
nextzero | 3:91c06faa6963 | 29 | if (!ds1820_1.begin()){ |
ismatel77 | 0:2e0fc2c1e24c | 30 | pc.printf("No DS1820 sensor found!\r\n"); |
ismatel77 | 0:2e0fc2c1e24c | 31 | } |
ismatel77 | 0:2e0fc2c1e24c | 32 | else{ |
ismatel77 | 0:2e0fc2c1e24c | 33 | pc.printf("DS1820 sensor found!\r\n"); |
ismatel77 | 0:2e0fc2c1e24c | 34 | } |
ismatel77 | 0:2e0fc2c1e24c | 35 | |
nextzero | 3:91c06faa6963 | 36 | float valeurTare = loadcell.getValue(); |
nextzero | 3:91c06faa6963 | 37 | |
ismatel77 | 0:2e0fc2c1e24c | 38 | while(1) { |
nextzero | 3:91c06faa6963 | 39 | float valeur = loadcell.getValue(); |
nextzero | 3:91c06faa6963 | 40 | float balance = ((double)valeur - (double)valeurTare)/21500; |
nextzero | 3:91c06faa6963 | 41 | //pc.printf("Weight = %.2f\r\n", balance); |
ismatel77 | 0:2e0fc2c1e24c | 42 | |
nextzero | 3:91c06faa6963 | 43 | ds1820_1.startConversion(); // start temperature conversion from analog to digital |
nextzero | 3:91c06faa6963 | 44 | ds1820_2.startConversion(); // start temperature conversion from analog to digital |
ismatel77 | 0:2e0fc2c1e24c | 45 | ThisThread::sleep_for(1000);// let DS1820 complete the temperature conversion |
nextzero | 3:91c06faa6963 | 46 | |
nextzero | 4:809b9c3a1739 | 47 | result = ds1820_1.read(temp1); // read temperature from DS1820 and perform cyclic redundancy check (CRC) |
nextzero | 4:809b9c3a1739 | 48 | result = ds1820_2.read(temp1); |
nextzero | 3:91c06faa6963 | 49 | |
nextzero | 3:91c06faa6963 | 50 | error1 = sensor1.readData(); //read error value |
nextzero | 3:91c06faa6963 | 51 | error2 = sensor2.readData(); //read error value |
ismatel77 | 0:2e0fc2c1e24c | 52 | |
nextzero | 4:809b9c3a1739 | 53 | c_int = sensor1.ReadTemperature(CELCIUS); |
nextzero | 4:809b9c3a1739 | 54 | h_int = sensor1.ReadHumidity(); |
nextzero | 4:809b9c3a1739 | 55 | |
nextzero | 4:809b9c3a1739 | 56 | c_ext = sensor2.ReadTemperature(CELCIUS); |
nextzero | 4:809b9c3a1739 | 57 | h_ext = sensor2.ReadHumidity(); |
nextzero | 3:91c06faa6963 | 58 | |
nextzero | 4:809b9c3a1739 | 59 | c_moyenne_int =(c_int + temp1 + temp2)/3; |
nextzero | 4:809b9c3a1739 | 60 | |
nextzero | 4:809b9c3a1739 | 61 | // pc.printf("temperature = %4.2f\r\n", c); // on affiche les valeurs sur teraTerm pour debug |
nextzero | 4:809b9c3a1739 | 62 | //pc.printf("Humidite = %4.2f\r\n", h); |
nextzero | 3:91c06faa6963 | 63 | |
nextzero | 3:91c06faa6963 | 64 | |
nextzero | 4:809b9c3a1739 | 65 | 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 | 1:b811fd6ee6f5 | 66 | wait(10.0f); |
ismatel77 | 0:2e0fc2c1e24c | 67 | } |
ismatel77 | 0:2e0fc2c1e24c | 68 | } |