I've got a problem with Nextion NX4024T032_011. I can send data to it from Arduino Uno or Leonardo but seems that Nextion is not sending data to Arduino when I'm pressing a button (Rx diode on Arduino board is not blinking). On Serial port I can only see "recvRetCommandFinished err" just after opening Serial-Monitor: recvRetCommandFinished err
According to me, Nextion button is set-up properly. Nextion button
I'm using this library: https://github.com/itead/ITEADLIB_Arduino_Nextion but I've modified it a little. I changed this line in NexConfig.h:
#define nexSerial Serial2
to:
#include <SoftwareSerial.h>
extern SoftwareSerial HMISerial;
#define nexSerial HMISerial
Arduino Code:
/*
How to use Nextion library:
https://create.arduino.cc/projecthub/tsavascii/nextion-lcd-communicate-with-arduino-uno-188a44
*/
#include "Nextion.h"
SoftwareSerial HMISerial(10, 11);
#define ledPin 13
NexButton b0 = NexButton(0, 1, "b0");
NexButton b1 = NexButton(0, 7, "b1");
NexButton b0_page2 = NexButton(0, 1, "b0");
NexNumber n1 = NexNumber(0, 5, "n0");
NexText t0 = NexText(0, 2, "t0");
NexText t1 = NexText(0, 6, "t1");
NexText t2 = NexText(0, 3, "t2");
int myInt=0;
NexTouch *nex_listen_list[] = {&b1,NULL};
/*
Difference between Serial write and print:
https://arduino.stackexchange.com/questions/10088/what-is-the-difference-between-HMISerial-write-and-HMISerial-print-and-when-are-they
*/
void b1PushCallback(void *ptr)
{
digitalWrite(ledPin, HIGH);
}
void b1PopCallback(void *ptr)
{
digitalWrite(ledPin, LOW);
}
void nextionPrint(String objectName, String value)
{
objectName = objectName + "=\""+ value + "\"";
HMISerial.print(objectName);
HMISerial.write(0xff);
HMISerial.write(0xff);
HMISerial.write(0xff);
}
void nextionPrint(String objectName,int value)
{
objectName = objectName + "=";
HMISerial.print(objectName);
HMISerial.print(value);
HMISerial.write(0xff);
HMISerial.write(0xff);
HMISerial.write(0xff);
}
void setup()
{
pinMode(ledPin,OUTPUT);
nexInit();
digitalWrite(ledPin,LOW);
b1.attachPush(b1PushCallback); //button press
b1.attachPop(b1PopCallback); //button release
nextionPrint("t1.txt", "Arduino Text");
}
void loop()
{
nexLoop(nex_listen_list);
++myInt;
nextionPrint("n0.val", myInt);
if(myInt>254)
{
myInt=0;
}
if(HMISerial.available())
{
Serial.println(HMISerial.read());
}
delay(500);
}
Any tips why I can't get any data from Nextion?