Is there anywhere else in your program where you successfully read a number field from the Nextion? Perhaps a reading in a trigger function?
Is there any where in the program where you successfully read a text field?
Can you read any trigger functions?
All the buttons on Nextion are setup with trigger functions and Arduino is executing those functions accordingly.
ex:
void trigger1(){
/* Create a button on Nextion
* Write in the Touch Release Event of the button
* this command: printh 23 02 54 01
* Every time the button is pressed, the trigger1() function will run
* and the code inside will be executed once
*/
if(digitalRead(48) == LOW){
digitalWrite(48, HIGH);
Serial.println ("Power button ON");
player.playSpecified(1);
}else if(digitalRead(48) == HIGH){
digitalWrite(48, LOW);
Serial.println ("Power button OFF");
player.playSpecified(2);
digitalWrite(8, LOW);
digitalWrite(2, LOW);
myNex.writeNum("bt1.val", 0);
}
I have not been successful yet reading text or number from fields on the Nextion, however, I can send data to text and number field to the Nextion using the serial1.print method.
Ex:
Serial1.print("t1.txt=\""); // Changing the value of box t1
Serial1.print(celsius); // celsius read the temperature from the sensor and output in Celcius
Serial1.print("\"");
Serial1.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial1.write(0xff);
Serial1.write(0xff);
Do you have this line at the start of loop()
myNex.NextionListen();
Yes, first line after the void loop(){
If you indeed have a systematic issue with reading anything from the Nextion, I would investigate the Nextion Tx to Arduino Rx connection.
Nextion TX connected to Arduino RX (D19) and Nextion RX connected to Arduino TX (D18).
Checked for continuity from Nextion to Arduino and all good.
I am however using a Screw Terminal Block Shield Board for Arduino MEGA-2560 R3 and screw Terminal to D19 on Arduino test ok.
Does the Mega Serial port which is reading from the Nextion work with a different input source? Have you tested it with a feedback loop from another port on the Mega?
Serial1 is dedicated to Nextion display. I will need to try another serial port to see if there is a problem with Serial1...
The Nextion serial is at 3.3v and its possible that the signal level is not high enough for the Mega. Do you have an oscilloscope or logic analyser to examine the Serial levels from the Nextion?
I will check the Nextion TX with my oscilloscope to investigate potential problem with signal...
Do you have a level shifter you can use between the Nextion and the Arduino?
Not sure what's this, is it something to step up signal from 3.3v to 5v?
Do I have to do anything on the Nextion side for it to send data to Arduino? Trigger commands or something?
Thanks again for your effort...