Hi at all,
i'm trying to create a weather station with arduino mega, MCU 2,8 TFT and DHT11.
I used GRD, 53, 51 digital for - + signal of DHT11.
Everyting works, but after some minutes the screen become white.
Can you tell me where i'm wrong?
Thanks in advance
AC
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#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
#define TS_MINX 158
#define TS_MINY 148
#define TS_MAXX 922
#define TS_MAXY 958
#define YP A1 // Chip Select goes to Analog 3
#define XM A2 // Command/Data goes to Analog 2
#define YM 7 // LCD Write goes to Analog 1
#define XP 6 // LCD Read goes to Analog 0
#include <SPI.h> // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
//#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
int a = 0;
boolean buttonEnabled = true;
#include <DHT.h>
#include <Wire.h>
#include "i2c.h"
#include "i2c_BMP280.h"
BMP280 bmp280;
DHT dht(51, DHT11);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Inizio scansione temperatura ed umidità:");
// Serial.print("Probe BMP280: ");
// if (bmp280.initialize()) Serial.println("Sensor found");
// else {
// Serial.println("Sensor missing");
// while (1) {}
// }
pinMode(53, OUTPUT); //pin 53 USCITA
digitalWrite(53, HIGH);
// onetime-measure:
// bmp280.setEnabled(0);
// bmp280.triggerMeasurement();
dht.begin();
tft.reset(); //hardware reset
uint16_t ID = tft.readID(); //
/* Serial.print("ID = 0x");
Serial.println(ID, HEX);
*/ if (ID == 0xD3D3) ID = 0x9481; // write-only shield
// ID = 0x9329; // force ID
tft.begin(ID);
tft.fillScreen(BLACK);
tft.setRotation(1);
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextSize(2);
tft.println("Aria di Tempesta");
tft.setTextColor(YELLOW); tft.setTextSize(2);
tft.println("");
tft.setTextColor(RED); tft.setTextSize(2);
tft.println("Temperatura e umidita'");
tft.println();
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println(" 0C");
tft.println(" 0%");
//Create Red Button
tft.fillRect(50, 180, 220, 40, RED);
tft.drawRect(50, 180, 220, 40, WHITE);
tft.setCursor(70, 188);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Clicca qui");
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
float t1 = float t = dht.readTemperature();
float h1 = float h = dht.readHumidity();
Serial.print("Temperatura: ");
Serial.println(String(t) + "°C");
Serial.println(String(t1) + "°C");
Serial.print("Umidità: ");
Serial.println(String(h) + "%");
Serial.println(String(h1) + "%");
if (t != t1 || h != h1) {
Serial.println("Diversi");
t = t1;
h = h1;
/* bmp280.awaitMeasurement();
float temperature;
bmp280.getTemperature(temperature);
float pascal;
bmp280.getPressure(pascal);
static float meters, metersold;
bmp280.getAltitude(meters);
metersold = (metersold * 10 + meters)/11;
bmp280.triggerMeasurement();
Serial.print(" Altezza iniziale: ");
Serial.print(metersold);
Serial.print(" m; Altezza: ");
Serial.print(meters);
Serial.print(" Pressure: ");
Serial.print(pascal);
Serial.print(" Pa; T: ");
Serial.print(temperature);
Serial.println("°C");
*/
tft.fillScreen(BLACK);
tft.setRotation(1);
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextSize(2);
tft.println("Aria di Tempesta");
tft.setTextColor(YELLOW); tft.setTextSize(2);
tft.println("");
tft.setTextColor(RED); tft.setTextSize(2);
tft.println("Temperatura e umidita'");
tft.println();
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println(" " + String(t) + "C");
tft.println(" " + String(h) + "%");
//Create Red Button
tft.fillRect(50, 180, 220, 40, RED);
tft.drawRect(50, 180, 220, 40, WHITE);
tft.setCursor(70, 188);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Clicca qui");
}
TSPoint p = ts.getPoint(); //Get touch point
/* if (p.z > ts.pressureThreshhold) {
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\n");
Serial.println(map(p.x, TS_MAXX, TS_MINX, 0, 320));
Serial.println(map(p.y, TS_MAXY, TS_MINY, 0, 240));
}
*/ p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>30 && p.x<80 && p.y>35 && p.y<200 && buttonEnabled)// The user has pressed inside the red rectangle
{
buttonEnabled = false; //Disable button
//This is important, because the libraries are sharing pins
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//Erase the screen
tft.fillScreen(BLACK);
//Draw frame
tft.fillRect(0,0,318,240,BLACK);
tft.drawRect(0,0,318,240,WHITE);
tft.setCursor(50,50);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("OK");
}
}