Hi everybody,
I’m trying to display the temperature and the humidity values from my sensors on the Nextion display but the code I found doesn’t work and it’s complicated to find something for Photon.
I found some things, but the code doesn’t works (all the videos are for arduino)…
My display is plug like this :
+5v --> VIN
TX --> TX
RX --> RX
GND --> GND
It’s a simple 3.2" Nextion display (same one the first video).
And here is my code, I have 4 temperature sensor plus 1 humidity sensor.
// This #include statement was automatically added by the Particle IDE.
#include <ITEADLIB_Nextion.h>
////// LIBRARIES ///////
#include <Adafruit_DHT.h>
////// TEMPERATURE ///////
int chaudHaut = A0;
int chaudBas = A1;
int froidHaut = A2;
int froidBas = A3;
double tempChaudHaut = 0.0;
double tempChaudBas = 0.0;
double tempFroidHaut = 0.0;
double tempFroidBas = 0.0;
////// HUMIDITY ///////
#define DHTPIN A4
#define DHTTYPE DHT11
int humidity;
DHT dht(DHTPIN, DHTTYPE);
////// RELAYS ///////
////// DISPLAY ///////
NexText txt_tempch = NexText(0, 4, "tempch");
NexText txt_humi = NexText(0, 8, "humi");
char buffer[100] = {0};
char buffer2[100] = {0};
void setup() {
////// TEMPERATURE ///////
Particle.variable("tempch", &tempChaudHaut, DOUBLE);
Particle.variable("tempcb", &tempChaudBas, DOUBLE);
Particle.variable("tempfh", &tempFroidHaut, DOUBLE);
Particle.variable("tempfb", &tempFroidBas, DOUBLE);
pinMode(chaudHaut, INPUT);
pinMode(chaudBas, INPUT);
pinMode(froidHaut, INPUT);
pinMode(froidBas, INPUT);
////// HUMIDITY ///////
dht.begin();
////// DISPLAY ///////
nexInit();
}
void loop() {
/////////////////////////////////////////////////////////////// TEMPERATURE ///////////////////////////////////////////////////////////////
////////// Sonde chaud haut //////////
int readingCH = analogRead(chaudHaut);
double voltageCH = (readingCH * 3.3) / 4095.0;
tempChaudHaut = (voltageCH - 0.5) * 100;
////////// Sonde chaud bas //////////
int readingCB = analogRead(chaudBas);
double voltageCB = (readingCB * 3.3) / 4095.0;
tempChaudBas = (voltageCB - 0.5) * 100;
////////// Sonde froid haut //////////
int readingFH = analogRead(froidHaut);
double voltageFH = (readingFH * 3.3) / 4095.0;
tempFroidHaut = (voltageFH - 0.5) * 100;
////////// Sonde froid bas //////////
int readingFB = analogRead(froidBas);
double voltageFB = (readingFB * 3.3) / 4095.0;
tempFroidBas = (voltageFB - 0.5) * 100;
/////////////////////////////////////////////////////////////// HUMIDITY ///////////////////////////////////////////////////////////////
humidity = dht.getHumidity();
Spark.publish("humidity", String(humidity) + "%");
delay(3000000);
/////////////////////////////////////////////////////////////// RELAYS ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////// DISPLAY ///////////////////////////////////////////////////////////////
txt_tempch.setText(buffer);
txt_humi.setText(buffer2);
}
If somebody can help that would be great, that driving me crazy.
All the best