Nextion Display How to read Device Return Data

Hi

First time I've used this forum, I'm using an Arduino Mega 2560 connected to a 3.5" Nextion screen.

I've searched the internet for anybody talking about reading the Nextion displays return data and only really found the Nextion instruction information but nothing about how to actually read that data, how can I read that data?

Problem is I can update gauges, number controls fine, then send the file end block, but when I use say t0.setText(buffer) with string data, with or without the file end block of (OxFF) I alway get return err.

The text control does update with the correct data, so it works, but I'd rather not be getting errors back. So if i could read the returned data it would help fix it, as the display must not be happy with something I'm sending, it's not the page No, ID or length of data, all these fields are correct.

Hello X-Wing,
Welcome to the forum.

Please read 'how to use this forum - please read', then post some actual code, stating what you expect it to do and what it does instead. The information in your post is too vague to know for sure what you are doing. I can be certain that if you send to a Nextion exactly what you posted it will return an error.

There is plenty of information on this site about Nextion displays, including my tutorial 'Using Nextion displays with Arduino.

in this topic you can find that you want

This is the part of the topic:

Seithan:
How to change components’ attributes at Nextion from Arduino:
For every component on Nextion, we can chance only attributes that are showed with GREEN color when Nextion is “running”
with the following prototype .= . If attribute is text, the value must be inside <" “> quotes.
Supposing we want to send to component t3 the text < HELLO > the command for Nextion is < t3.txt=“HELLO” >, from Arduino, we write < Serial.print(“t3.txt=“HELLO””) >;
When we type <”> means that <"> is a character and it’s going to print it over serial as character. Else <"> is a STRUCTURE.
To change the font color t3, we write on Nextion: < t3.pco=BLUE > or < t3.pco=<31> >
From Arduino:< Serial.print(“t3.pco=BLUE”); > or < Serial.print(“t3.pco=31”); >
TIP: The exact names of the attributes and the values they can get, can be found on Nextion Editor at the attribute menu of any object.

Don’t forget after every command sent to Nextion you must send the following

Serial.print("\xFF\xFF\xFF");

You could download the .ino and .HMI files of the topic to see the examples.

Hi

Thanks for your replies, I wasn’t clear about my question. Say I have a TFT file with 10 pages and one of the pages has 24 txtboxes on, the code runs fine on the Arduino and the Nextion no errors or issues.
Then I make several changes to the TFT and the sketch, thinking all is well, but later, get errors from the Nextion, I know the page I’m getting these on as the Sketch tracks page loaded, but I’ve now got 24 txt boxes any one, or more, could be the issue, they’re all working as well, to make this worse.

The Nextion does return errors to the sketch serial monitor, but just saying complete with errors if you look at the Nextion instruction set at the bottom they list the error codes they return.

I’ve fixed the issue I had now, but it took so much time I’ve searched You Tube and internet for anybody that talks about reading back the error codes but found nothing.

Q. If I could read these error codes it might make fixing the above issue easier as it might give the control name, ID and a basic idea of why it’s not happy. Seeing the topics on here talk about Nextion somebody must be thinking about reading the return data, I’m not sure how to do that serial.read into a buffer I’m guessing.

Q. If I could read these error codes it might make fixing the above issue easier as it might give the control name, ID and a basic idea of why it's not happy. Seeing the topics on here talk about Nextion somebody must be thinking about reading the return data, I'm not sure how to do that serial.read into a buffer I'm guessing.

Speaking only for myself I have never found the need to read the return codes in my program so I have never built code into my projects to read them. You can use the simulator in the Nextion editor, it shows the return codes in the 'Simulator Return' window.

Something I did do in my early experiments with Nextion is to use the serial port on my laptop (you need an RS232 to TTL converter) to read the data going between the controller and Nextion and display it in a PuTTY window, which was useful. I have also had a separate Arduino connected to my PC with a short program taking input from a serial Rx and displaying it in the serial monitor. Connect the serial Rx to whichever serial data you want to monitor.

I can't imagine it is difficult to embed into your Arduino program something that separates the return codes from the actual data and sends the return codes to the serial monitor, especially if you use my methods, which deliberately use 0xaa at the start instead of 0xff at the end of each bloc of data. Should be simple enough to utilise that difference to strip out the return codes.

Not a promise but I will keep this in mind for the next update on my tutorial, I am looking for things to add to part 4.

These things are trash. If all you want to use them with is Arduino, or if all you want to do is display data (and not drive anything) with them, they may be fine. It's very easy to update elements on the display, but as soon as you start trying to get anything back from them it's so much trial and error it gets old quick.

The Arduino libraries, at a glance, look like they are handling all the common stuff pretty well. Anyone using those libraries should be very thankful to the people who developed them.

If you are trying to use them with any other system directly via serial, and hoping to use them to drive something, it's going to be a lot of extra work to figure out how to make sense of what they're sending. There is no standardization for the data that they send, and it's hit an miss if they do you the courtesy of using a byte or two to describe what they're sending.

I fought with one for a few hours, basically hitting buttons, seeing what it sent, and writing code around that, until I had what should have been a basic working system only to find out that hitting a button 1 time would send the string that I told it to, and hitting a second and any number of times after that would send that string and some other data. I don't know what that data was because that was my breaking point. I chucked it in a drawer to be used with some AVR/Arduino project maybe some day.

If you have component limitation, and you really need to offload the graphics and ui, they may be worth it. Otherwise, I recommend budgeting the resources to use standard displays.

If you're stuck using one, Instruction Set - Nextion , will have about 10% of what you need. It has SOME of the error codes, but even those tend to be vague.

Edit: To be fair, that page will have probably 90% of what you need, but the other 10% is just going to have to be greped out at a serial console.

@acecase,

Perhaps you should try the methods I set out in using Nextion displays with Arduino, which do not use the Nextion return codes. I don't accept your assessment of Nextion displays as 'trash'. If you use my methods they work perfectly well.

In reply #4 I said:

I can't imagine it is difficult to embed into your Arduino program something that separates the return codes from the actual data and sends the return codes to the serial monitor, especially if you use my methods, which deliberately use 0xaa at the start instead of 0xff at the end of each bloc of data. Should be simple enough to utilise that difference to strip out the return codes.

Not a promise but I will keep this in mind for the next update on my tutorial, I am looking for things to add to part 4.

I have implemented code to read the return codes and send them to the serial monitor. See part 4 of the tutorial.