CIao a tutti,
sto cercando di inviare i dati temperatura e umidita allo schermo nextion.
per non occupare la seriale ho usato la funzione millis come vedrete ma purtroppo non arriva nulla.
i due "riquadri" che dovrebbero ricevere il dato si chiamano rispettivamente temperatura e umidita e sono a pagina 2.
dalle info che ho reperito in rete sembra che pero la pagina e l ID degli oggetti in questo caso non serva al contrario ad esempio dei pulsanti.
vi allego lo sketh.
avete qualche suggerimento?
#include <Nextion.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float temperature = 0.0f;
float humidity = 0.0f;
NexDSButton bt0 = NexDSButton(0, 17, "bt0");
NexDSButton bt1 = NexDSButton(0, 18, "bt1");
NexDSButton bt2 = NexDSButton(0, 19, "bt2");
NexDSButton bt3 = NexDSButton(0, 20, "bt3");
NexDSButton bt4 = NexDSButton(0, 21, "bt4");
NexDSButton bt5 = NexDSButton(0, 22, "bt5");
NexDSButton bt6 = NexDSButton(0, 24, "bt6");
uint32_t statoboiler = 0;
uint32_t statocino = 0 ;
uint32_t statoriscalda = 0 ;
uint32_t statofornello = 0 ;
uint32_t statopresa1 = 0 ;
uint32_t statopresa2 = 0 ;
uint32_t statocarica = 0 ;
unsigned long t1, dt1;
NexTouch *nex_listen_list[] = {
&bt0,
&bt1,
&bt2,
&bt3,
&bt4,
&bt5,
&bt6,
NULL
};
void setup() {
dht.begin();
delay(10000);
Serial.begin(9600);
nexInit();
bt0.attachPop(boiler, &bt0);
bt1.attachPop(cino, &bt1);
bt2.attachPop(riscalda, &bt2);
bt3.attachPop(fornello, &bt3);
bt4.attachPop(presa1, &bt4);
bt5.attachPop(presa2, &bt5);
bt6.attachPop(carica, &bt6);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop() {
dt1 = millis() - t1;
nexLoop(nex_listen_list);
if( dt1 > 200 ) {
readSensor();
sendHumidityToNextion();
sendTemperatureToNextion();
t1 = millis();
}
}
void readSensor()
{
humidity = dht.readHumidity();
temperature = dht.readTemperature();
}
void sendHumidityToNextion()
{
String command = "umidita.txt=\"" + String(humidity, 1) + "\"";
Serial.print(command);
endNextionCommand();
}
void sendTemperatureToNextion()
{
String command = "temperatura.txt=\"" + String(temperature, 1) + "\"";
Serial.print(command);
endNextionCommand();
}
void endNextionCommand()
{
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void boiler(void *ptr)
{
bt0.getValue(&statoboiler);
if (statoboiler == 1)
{
digitalWrite(2, LOW);
}
else
{
digitalWrite(2, HIGH);
}
}
void cino(void *ptr)
{
bt1.getValue(&statocino);
if (statocino == 1)
{
digitalWrite(3, LOW);
}
else
{
digitalWrite(3, HIGH);
}
}
void riscalda(void *ptr)
{
bt2.getValue(&statoriscalda);
if (statoriscalda == 1)
{
digitalWrite(4, LOW);
}
else
{
digitalWrite(4, HIGH);
}
}
void fornello(void *ptr)
{
bt3.getValue(&statofornello);
if (statofornello == 1)
{
digitalWrite(5, LOW);
}
else
{
digitalWrite(5, HIGH);
}
}
void presa1(void *ptr)
{
bt4.getValue(&statopresa1);
if (statopresa1 == 1)
{
digitalWrite(6, LOW);
}
else
{
digitalWrite(6, HIGH);
}
}
void presa2(void *ptr)
{
bt5.getValue(&statopresa2);
if (statopresa2 == 1)
{
digitalWrite(7, LOW);
}
else
{
digitalWrite(7, HIGH);
}
}
void carica(void *ptr)
{
bt6.getValue(&statocarica);
if (statocarica == 1)
{
digitalWrite(8, LOW);
}
else
{
digitalWrite(8, HIGH);
}
}