I am using the Arduino Uno R3 SMD with a 2.8" Nextion Display. Everything was working fine until one day when my code stopped working. I keep getting constant input to the arduino from the nextion display and when I touch the display, the code that is suppose to be received most of the isn't. Sometimes it works but rarely. Here is my code:
if (portOne.available() > 0) { //Check If The Nextion Display Has Sent Us Something
String Received = portOne.readString(); //Save the received String in the Received variable
Serial.println(Received);
Serial.println("");
Why is the Nextion Display sending constant data when the display has not been touched? It use to work perfectly.
The display works perfectly when I connect it to the computer using an FTDI unit inside the Nextion Software.
I stripped my code back to the basics with just the arduino receiving touch inputs from the Nextion Display and it fixed the garbage being received. I will now add other inputs to the code to see what was disturbing my display RX and TX lines. It might be the radio messing it up. Will add more later.
Whandall. If you do not have anything to help solve the problem then why posts a link to a resource that I started out with.. Unless you are trying to rack up your posting points. I also stated that I fixed my issue by going back to the base code. lol
That was my entire code minus the setup lines and declarations. That is why I didn't know why it was spitting out garbage. I was just checking for incoming data and doing a serialprint to see what it was.
I would be more than happy to post my entire arduino code and HMI files of the working arduino/nextion interaction for you if you want. My code works great now. The weird part is that everything was working great for months and then decided not to work now. No code was changed or uploaded to the Arduino.
I am just creating my own thermostat control for a 1934 Chrysler AirTemp Furnace where the controls had stopped working. I designed the new electronics for the furnace and was just wondering why the thermostat was doing weird stuff after awhile.
Here is my code for my interaction with the Nextion Display.
#include <SPI.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
SoftwareSerial portOne(3, 4); //RX, TX
String MyID = "";
String MyVal = "";
String DTS = "";
int RT = EEPROM.read(0); //Room Temperature
int BF = EEPROM.read(1); //Burner Off Temperature
int FO = EEPROM.read(2); //Fan On Temperature
int FF = EEPROM.read(3); //Fan Off Temperature
void setup() {
Serial.begin(115200);
portOne.begin(9600);
}
void loop(){
if (portOne.available() > 0) {
GetNextion();
}
}
void GetNextion() {
String Received = portOne.readString(); //Save the received String in the Received variable
MyID = Received[0];
MyID = MyID + Received[1];
if (MyID == "RT"){ //RT = Room Temperature
MyVal = Received[2];
MyVal = MyVal + Received[3];
if (MyVal != String(RT)){ //If the default Room Temperature has been changed from default.
RT = MyVal.toInt(); //Save it as the new default temperature.
EEPROM.update(0, RT); //Write it to the EEPROM as the new default Room Temperature.
DTS = MyID + MyVal;
//radio.write(DTS.c_str(), DTS.length()); //Send the new default value to the furnace control board in the furnace wirelessly.
Serial.print("Transmitted ");
Serial.println(String(DTS));
Serial.println("");
}
}
if (MyID == "BF"){ //BF is the Burner Off Temperature
MyVal = Received[2];
MyVal = MyVal + Received[3];
MyVal = MyVal + Received[4];
if (MyVal != String(BF)){
BF = MyVal.toInt();
EEPROM.update(1, BF);
DTS = MyID + MyVal;
//radio.write(DTS.c_str(), DTS.length());
Serial.print("Transmitted ");
Serial.println(String(DTS));
Serial.println("");
}
}
if (MyID == "FO"){ //FO is the Fan OnTemperature
MyVal = Received[2];
MyVal = MyVal + Received[3];
MyVal = MyVal + Received[4];
if (MyVal != String(FO)){
FO = MyVal.toInt();
EEPROM.update(2, FO);
DTS = MyID + MyVal;
//radio.write(DTS.c_str(), DTS.length());
Serial.print("Transmitted ");
Serial.println(String(DTS));
Serial.println("");
}
}
if (MyID == "FF"){//FF is the Fan Off Temperature
MyVal = Received[2];
MyVal = MyVal + Received[3];
MyVal = MyVal + Received[4];
if (MyVal != String(FF)){
FF = MyVal.toInt();
EEPROM.update(3, FF);
DTS = MyID + MyVal;
//radio.write(DTS.c_str(), DTS.length());
Serial.print("Transmitted ");
Serial.println(String(DTS));
Serial.println("");
}
}
}
Hopefully I didn't leave anything out.
There is a lot more because the thermostat (Nextion Display) also has the Time, Day Of The Week, the Date (with help from an rtc. There is also inside and outside temperature and humidity readings on the display. It all works wirelessly with the furnace unit inside the furnace with SSR's(Solid State Relays) along with other things.