Ero alla ricerca di un progetto semplice per autocostruirsi una stazione meteo e sono incappato in un tutorial avvincente in italiano che prevede l'uso di una display touchscreen 480x320, un bmp280, un dth22 (io ho usato il dht11), un modulo RTC ed un Arduino Mega.
Ho modificato il progetto iniziale separandolo in due colonne: a dx temperatura e umidità indoor col Dth11 e a sx la Pressione, l'umidità e la temperatura outdoor col bmp280.
Il mio problema è che non so come far apparire il dato dell'umidità del bmp280 sul touchscreen.
Di seguito provo a postare lo sketch (ho tolto alcune parti meno importanti perchè il forum mi diceva che superavo i 9000 caratteri), nella speranza di non commettere qualche violazione:
#include "BMP280.h"
#include "Wire.h"
#include "DHT.h"
#include <DS3231.h>
#define DHTPIN 52
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BMP280 bmp;
DS3231 rtc(SDA, SCL);
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define YP A2
#define XM A3
#define YM 8
#define XP 9
#define TS_MINX 130
#define TS_MAXX 905
#define TS_MINY 75
#define TS_MAXY 930
#define MINPRESSURE 10
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GRAY 0x8410
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
Time tempo;
double Temp, Pres, t, h, zeta, TempMed, t1, t2, t3, t4, p1, p2, p3, p4, h1, h2, h3, h4;
boolean buttonEnabled01 = true;
boolean buttonEnabled02 = true;
boolean buttonEnabled03 = true;
bool h12;
bool PM;
void setup()
{
bmp.begin();
dht.begin();
bmp.setOversampling(4);
rtc.begin();
//rtc.setDOW(TUESDAY); // Imposta il giorno della settimana
//rtc.setTime(23, 46, 00); // Impostail l'orario 12:00:00 (formato 24 ore)
//rtc.setDate(07, 07, 2020); // Imposta la data nel formato dd, mm, aaaa
Serial.begin(9600);
tft.reset();
uint16_t identifier = 0x9486;
Serial.print("TFT Display: ");
Serial.println(identifier);
tft.begin(identifier);
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.fillRect(0,100, 480, 5, WHITE); //linea orizzontale bianca che in originale era (0,100, 480, 5, WHITE)
tft.fillRect(0,0, 480, 100, BLACK); //sfondo del rettango superiore Stazione Meteo Via Negrotto
}
void loop()
{
TSPoint p = ts.getPoint();
if (p.z > ts.pressureThreshhold){
p.x = map (p.x , TS_MINX, TS_MAXX, 0, 480 );
p.y = map (p.y , TS_MINY, TS_MAXY, 0, 320 );
Serial.print ("x= ");
Serial.println(p.x);
Serial.print ("y= ");
Serial.println(p.y);
delay(500);
if(p.x>320 && p.x<480 && p.y>210 && p.y<320 && buttonEnabled01) //bottone in basso a dx
{
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillRect(0,105, 480, 220, BLACK);
tempday();
delay (5000);
tft.fillRect(0,105, 480, 220, BLACK);
Home();
}
if(p.x>320 && p.x<480 && p.y>150 && p.y<250 && buttonEnabled02) //bottone al centro a dx
{
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillRect(0,105, 480, 220, BLACK);
humday();
delay (5000);
tft.fillRect(0,105, 480, 220, BLACK);
Home();
}
if(p.x>0 && p.x<240 && p.y>0 && p.y<100 && buttonEnabled03)
{
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillRect(0,105, 480, 220, BLACK);
presday();
delay (5000);
tft.fillRect(0,105, 480, 220, BLACK);
Home();
}
}
if (p.z == 0) {
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Home();
}
}
void Home(){
Data();
drop();
tempo = rtc.getTime();
for (int n=100; n<315; n++){
tft.fillRect(240,n, 5, 5, WHITE); //barra separatrice verticale temperatura
}
tft.fillRect(0,210, 480, 5, WHITE); //barra orizzontale che separa umidità da pressione
if (tempo.hour == 0 && tempo.min == 0 && tempo.sec > 0 && tempo.sec < 4){
tft.fillRect(300,5, 480, 25, BLUE);
tft.setCursor(300, 5);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(3);
tft.println(rtc.getDOWStr());
}
else {
tft.setCursor(300, 5);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(3);
tft.println(rtc.getDOWStr());
}
tft.setCursor(300, 37);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(3);
tft.print(rtc.getTimeStr());
tft.setCursor(300, 72);
tft.setTextColor(YELLOW, BLACK);
tft.setTextSize(3);
tft.print(rtc.getDateStr());
// Pressione
tft.setCursor(10,5);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("Pressione");
tft.setCursor(7,15); //sposta la scritta indoor (se aumenta sposta a dx, se aumenta sposta in basso)
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.println("outdoor");
tft.setCursor(10,50);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(5);
tft.println(Pres);
tft.setCursor(150,75);
tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.println("mBar");
// Umidità indoor
tft.setCursor(260,110); //sposta la scritta umidità
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("Umidita'");
tft.setCursor(257,133); //sposta la scritta indoor (se aumenta sposta a dx, se aumenta sposta in basso)
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("indoor");
tft.setCursor(260,160); //sposta il numero in orizzontale e in verticale
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(5);
tft.println(h);
tft.setCursor(410,182);
tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.println("%");
// Umidità outdoor
tft.setCursor(10,110); //sposta la scritta umidità
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("Umidita'");
tft.setCursor(7,133); //sposta la scritta indoor (se aumenta sposta a dx, se aumenta sposta in basso)
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.println("outdoor");
tft.setCursor(10,160); //sposta il numero in orizzontale e in verticale
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(5);
tft.println(zeta);
tft.setCursor(160,182);
tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.println("%");
// Temperatura indoor
tft.setCursor(260,220);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("Temp.");
tft.setCursor(257,243); //sposta la scritta indoor (se aumenta sposta a dx, se aumenta sposta in basso)
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("indoor");
tft.setCursor(260,270);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(5);
tft.println(TempMed);
tft.setCursor(410,272);
tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.println("C");
// Temperatura outdoor
tft.setCursor(10,220);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("Temp.");
tft.setCursor(7,243); //sposta la scritta indoor (se aumenta sposta a dx, se aumenta sposta in basso)
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.println("outdoor");
tft.setCursor(10,270);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(5);
tft.println(Temp);
tft.setCursor(160,272);
tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.println("C");
if (TempMed < 10){
termo00();
}
else if (TempMed >= 10 && TempMed < 28 ) {
termo01();
}
else {
termo02();
}
}
void Data(){
h = dht.readHumidity();
t = dht.readTemperature();
char misurazione = bmp.startMeasurment(); //se attivato il monitor seriale mostra la temperatura del bmp
misurazione = bmp.getTemperatureAndPressure(Temp,Pres); //se attivato il monitor seriale mostra la temperatura del bmp
TempMed = (t); //se disattivato non compare la temperatura indoor su display
Temp = (Temp); //se disattivato non compare la temperatura su display
Serial.print("Temperatura BMP= ");
Serial.print(Temp);
Serial.print(" C\t");
Serial.print("Pressione = ");
Serial.print(Pres);
Serial.println(" mBar");
Serial.print("Humidity = ");
Serial.print(zeta);
Serial.println("%");
Serial.print("Temperatura DHT11: ");
Serial.print(t);
Serial.print("C, Umidità : ");
Serial.print(h);
Serial.println("%");
memo();
}