Unofficial Nextion/TJC User Forum

Problems Sending Serial Data

Under the Touch Press Event of my Main page, I do the following:
printh 1 0
page 1

So I am pressing a button to transition from my Main page to my Alarms page.
On my Arduino, I see the following characters captured: 0 and 1 - which looks good.

But then I keep getting characters sent by the Nextion to my Arduino. I only sent two characters. Why would I be receiving more characters than I sent?


printh is to send hexadecimal so if you want to send one and zero you
printh 31 30 as 31 is the hex value for ascii character one and
30 is the hex value for ascii character zero

Best to run the nextion code in the debug and watch the output in the serial
“Simulator Return” box you can chose H hex or S string = normal ascii text

@paulvk That‘s true if you want to send the character 0 or 1. But the way I understood it, he actually wanted to send the value 0/1. If the intention is to send the characters, I wouldn‘t go with ASCII codes since that results in hard-to-read code. Just use prints "1",0 (or "0").

@lsmadeux I can only think of two reasons for ‘unsolicited’ messages/data: either your page 1 contains some sort of print code that gets executed when loading the page. Or your page 1 contains errors that aren‘t detected by the compiler and result in error messages at runtime. Common case are the usage of the p[].b[] arrays.

For both cases there are some less obvious possibilities that are hard to guess without knowing the source.
In case you got a lot of stuff on your page 1, you should look at Nextion2Text which converts the source file into simple text files that can be searched using ‘normal’ text/source editors. This can help a lot when you‘re searching for that one prints among the 100 components on your page.

Edit: By looking at that additional data you can likely gain a lot of info about the origin, too. As @paulvk suggested, this can easily be done with the debugger/simulator.

Kind regards,

Thank you everyone for your comments

This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).