arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

dhtnew_endless.ino (2713B)


      1 //
      2 //    FILE: DHT_endless.ino
      3 //  AUTHOR: Rob Tillaart
      4 // VERSION: 0.1.3
      5 // PURPOSE: demo
      6 //    DATE: 2020-06-04
      7 //    (c) : MIT
      8 //
      9 // 0.1.0    2020-06-04 initial version
     10 // 0.1.1    2020-06-15 match 0.3.0 error handling
     11 // 0.1.2    2020-09-22 fix typo
     12 // 0.1.3    2020-11-09 wait for read handling
     13 //
     14 // DHT PIN layout from left to right
     15 // =================================
     16 // FRONT : DESCRIPTION
     17 // pin 1 : VCC
     18 // pin 2 : DATA
     19 // pin 3 : Not Connected
     20 // pin 4 : GND
     21 
     22 #include <dhtnew.h>
     23 
     24 DHTNEW mySensor(16);   // ESP 16  UNO 6
     25 
     26 uint32_t count = 0;
     27 uint32_t start, stop;
     28 
     29 uint32_t errors[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     30 
     31 
     32 void setup()
     33 {
     34   Serial.begin(115200);
     35   Serial.println("DHT_endless.ino");
     36   Serial.print("LIBRARY VERSION: ");
     37   Serial.println(DHTNEW_LIB_VERSION);
     38   Serial.println();
     39 }
     40 
     41 void loop()
     42 {
     43   count++;
     44   // show counters for OK and errors.
     45   if (count % 50 == 0)
     46   {
     47     Serial.println();
     48     Serial.println("OK \tCRC \tTOA \tTOB \tTOC \tTOD \tSNR \tBS \tWFR \tUNK");
     49     for (uint8_t i = 0; i < 10; i++)
     50     {
     51       Serial.print(errors[i]);
     52       Serial.print('\t');
     53     }
     54     Serial.println();
     55     Serial.println();
     56   }
     57 
     58   if (count % 10 == 0)
     59   {
     60     Serial.println();
     61     Serial.println("TIM\tCNT\tSTAT\tHUMI\tTEMP\tTIME\tTYPE");
     62   }
     63   Serial.print(millis());
     64   Serial.print("\t");
     65   Serial.print(count);
     66   Serial.print("\t");
     67 
     68   start = micros();
     69   int chk = mySensor.read();
     70   stop = micros();
     71 
     72   switch (chk)
     73   {
     74     case DHTLIB_OK:
     75       Serial.print("OK,\t");
     76       errors[0]++;
     77       break;
     78     case DHTLIB_ERROR_CHECKSUM:
     79       Serial.print("CRC,\t");
     80       errors[1]++;
     81       break;
     82     case DHTLIB_ERROR_TIMEOUT_A:
     83       Serial.print("TOA,\t");
     84       errors[2]++;
     85       break;
     86     case DHTLIB_ERROR_TIMEOUT_B:
     87       Serial.print("TOB,\t");
     88       errors[3]++;
     89       break;
     90     case DHTLIB_ERROR_TIMEOUT_C:
     91       Serial.print("TOC,\t");
     92       errors[4]++;
     93       break;
     94     case DHTLIB_ERROR_TIMEOUT_D:
     95       Serial.print("TOD,\t");
     96       errors[5]++;
     97       break;
     98     case DHTLIB_ERROR_SENSOR_NOT_READY:
     99       Serial.print("SNR,\t");
    100       errors[6]++;
    101       break;
    102     case DHTLIB_ERROR_BIT_SHIFT:
    103       Serial.print("BS,\t");
    104       errors[7]++;
    105       break;
    106     case DHTLIB_WAITING_FOR_READ:
    107       Serial.print("WFR,\t");
    108       errors[8]++;
    109       break;
    110     default:
    111       Serial.print("U");
    112       Serial.print(chk);
    113       Serial.print(",\t");
    114       errors[9]++;
    115       break;
    116   }
    117   // DISPLAY DATA
    118   Serial.print(mySensor.getHumidity(), 1);
    119   Serial.print(",\t");
    120   Serial.print(mySensor.getTemperature(), 1);
    121   Serial.print(",\t");
    122   Serial.print(stop - start);
    123   Serial.print(",\t");
    124   Serial.println(mySensor.getType());
    125 
    126   delay(1000);
    127 }
    128 
    129 
    130 // -- END OF FILE --