// Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain // Connect pin 1 (on the left) of the sensor to +5V // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 // to 3.3V instead of 5V! // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor #include "DHT.h" #include // Core graphics library #include // Hardware-specific library //#define __SAM3X8E__ //#define (__SAM3X8E__) //#define USE_ADAFRUIT_SHIELD_PINOUT #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2, Labled LCD_RS #define LCD_WR A1 // LCD Write goes to Analog 1 #define LCD_RD A0 // LCD Read goes to Analog 0 #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin //==========color chart=========== #define BLACK 0xFFFF //65523-65535 #define BLUE 0xFFE0 //65504-65522 #define BRIGHTBLUE 0xFD20 #define GREEN 0xF81F #define CYAN 0xF800 #define LIGHTBLUE 0xF400 #define BLUE2 0xAFE5 #define GRAY1 0x8410 #define RED 0x07FF //define BRIGHT_RED 0x???? #define GRA 0x4208 #define WHITE3 0x1000 #define W+PINK4 0x0D00 #define W+PINK3 0x0C00 #define W+PINK2 0x0B00 #define W+PINK 0x0A00 #define WHITE2 0x0800 #define MAGENTA 0x07E0 #define PINK3 0x0500 #define PINK2 0x0400 #define PINK 0x03E0Y2 #define YELLOW 0x001F //11-32 #define WHITE 0x0000 #define TESTCOL 0xF71F Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Refer to Lib/Header Files. #define DHTPIN 0 // what digital pin we're connected to // Uncomment whatever type you're using! //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Initialize DHT sensor. // Note that older versions of this library took an optional third parameter to // tweak the timings for faster processors. This parameter is no longer needed // as the current DHT reading algorithm adjusts itself to work on faster procs. DHT dht(DHTPIN, DHTTYPE); void setup() { dht.begin(); tft.reset(); //Reset TFT LCD Shield delay(20); // Let Display Chip Settle, Delay 20mS tft.begin(0x9341); //Start ILI9341 tft.fillScreen(WHITE); // Clear Screen to BLACK. tft.setRotation(3); } void loop() //==========Gather data============ { // Wait a few seconds between measurements. delay(6000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { //Serial.println("Failed to read from DHT sensor!"); return; } // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); { tft.setCursor(20,20); tft.setTextColor(BLUE); tft.setTextSize(3); tft.fillScreen(WHITE); //tft.setTextColor(RED); //------------Print data to display---------- tft.setTextColor(MAGENTA); tft.print("Humid: "); tft.setTextColor(BLUE); tft.print(h); tft.println(" %"); tft.println(" --------------"); tft.setTextColor(RED); tft.println(" Temps: "); tft.setTextColor(BLUE); tft.print(" "); tft.print(t); tft.println(" C\t"); tft.print(" "); tft.print(f); tft.println(" F\t"); tft.print(" "); tft.println(); tft.setTextColor(RED); tft.print(" "); tft.println("Heat index: "); tft.setTextColor(BLUE); tft.print(" "); tft.print(hic); tft.println(" C\t "); tft.print(" "); tft.print(hif); tft.println(" F\t "); } }