arduinoprojects

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

dhtnew_array.ino (2462B)


      1 //
      2 //    FILE: dhtnew_array.ino
      3 //  AUTHOR: Rob Tillaart
      4 // VERSION: 0.1.4
      5 // PURPOSE: DHTNEW library test sketch for Arduino
      6 //     URL: https://github.com/RobTillaart/DHTNew
      7 
      8 // HISTORY:
      9 // 0.1.0    2020-04-25 initial version
     10 // 0.1.1    2020-04-30 replaced humidity and temperature with functions
     11 // 0.1.2    2020-06-08 improved error handling
     12 // 0.1.3    2020-06-15 match 0.3.0 error handling
     13 // 0.1.4    2020-11-09 wait for read handling
     14 // 
     15 // DHT PIN layout from left to right
     16 // =================================
     17 // FRONT : DESCRIPTION
     18 // pin 1 : VCC
     19 // pin 2 : DATA
     20 // pin 3 : Not Connected
     21 // pin 4 : GND
     22 
     23 #include <dhtnew.h>
     24 
     25 DHTNEW kitchen(4);
     26 DHTNEW living(5);
     27 DHTNEW outside(6);
     28 
     29 DHTNEW ar[3] = { kitchen, living, outside };
     30 
     31 void setup()
     32 {
     33   Serial.begin(115200);
     34   Serial.println("dhtnew_array.ino");
     35   Serial.print("LIBRARY VERSION: ");
     36   Serial.println(DHTNEW_LIB_VERSION);
     37   Serial.println();
     38 
     39   for (int idx = 0; idx < 3; idx++)
     40   {
     41     test(idx);
     42   }
     43 }
     44 
     45 void loop()
     46 {
     47   for (int idx = 0; idx < 3; idx++)
     48   {
     49     test(idx);
     50   }
     51   Serial.println();
     52 }
     53 
     54 void test(int idx)
     55 {
     56   // READ DATA
     57   uint32_t start = micros();
     58   int chk = ar[idx].read();
     59   uint32_t stop = micros();
     60 
     61   Serial.print(idx);
     62   Serial.print(",\t");
     63 
     64   switch (chk)
     65   {
     66     case DHTLIB_OK:
     67       Serial.print("OK,\t");
     68       break;
     69     case DHTLIB_ERROR_CHECKSUM:
     70       Serial.print("Checksum error,\t");
     71       break;
     72     case DHTLIB_ERROR_TIMEOUT_A:
     73       Serial.print("Time out A error,\t");
     74       break;
     75     case DHTLIB_ERROR_TIMEOUT_B:
     76       Serial.print("Time out B error,\t");
     77       break;
     78     case DHTLIB_ERROR_TIMEOUT_C:
     79       Serial.print("Time out C error,\t");
     80       break;
     81     case DHTLIB_ERROR_TIMEOUT_D:
     82       Serial.print("Time out D error,\t");
     83       break;
     84     case DHTLIB_ERROR_SENSOR_NOT_READY:
     85       Serial.print("Sensor not ready,\t");
     86       break;
     87     case DHTLIB_ERROR_BIT_SHIFT:
     88       Serial.print("Bit shift error,\t");
     89       break;
     90     case DHTLIB_WAITING_FOR_READ:
     91       Serial.print("Waiting for read,\t");
     92       break;
     93     default:
     94       Serial.print("Unknown: ");
     95       Serial.print(chk);
     96       Serial.print(",\t");
     97       break;
     98   }
     99 
    100   // DISPLAY DATA
    101   Serial.print(ar[idx].getHumidity(), 1);
    102   Serial.print(",\t");
    103   Serial.print(ar[idx].getTemperature(), 1);
    104   Serial.print(",\t");
    105   uint32_t duration = stop - start;
    106   Serial.print(duration);
    107   Serial.print(",\t");
    108   Serial.println(ar[idx].getType());
    109   delay(500);
    110 }
    111 
    112 // -- END OF FILE --