Unofficial Nextion/TJC User Forum

How to read a Nextion variable from a Arduino or Picaxe?

Hi,

I buid a DIY project to control my house’heater. The GUI Nextion works fine.

However, I am stopped, because I am unable to read a Nextion variable or a Nextion Textbox properties, from my Picaxe 20M2 with the serial.

What is the syntax for that. I see nothing in the Nextion documentation.

However, lighting a led from the Nextion Button works fine…

Many thanks for your help

Best regards,

RovDan

How are you sending the variable or textbox properties to the MCU?

For a project like this a set button would be the way I would do it.
With two text box for example
in the set button Touch Press Event(0)
prints t0.txt,0
prints t1.txt,0
When you press the set button nextion will send the text in the two text boxes

Many thanks Paul and Elf for your reply.

In the meantime, I spent all my evening studing and testing the “Get” instruction, and I successed.

To read a nextion number variable var1, whose content is 600 and located on page1 : my Picaxe must send for example :
Serout SortieNextion,T9600_16, (“get page1.var1.var”,255,255,255)

The Nextion reply is : 113,88,2,0,0 (in decimal, I prefer than in Hex)
113 is the Nextion Code of the decimal reply ($71)
88 is 600 mod 256
2 is 600/256
0,0 are used only on greater variables. Nextion allows to send up to 4 bytes numbers.

To read a nextion Button Caption Bn1, whose caption is “ON” and located on page2 : my Picaxe must send :
Serout SortieNextion,T9600_16, (“get page2.Bn1.txt”,255,255,255)

The Nextion reply is : 112,79,78 (In decimal)
112 is the Nextion Code of the text reply ($70)
79 is ASCII of the character “O”
78 is ASCII of the character “N”

One more time, thanks for the replies. I go on to my heating control project.
Maybe, I posted my messagein the wrong Thread. If somebody can move it…

Best regards,

RovDan

If you have a number of text boxes you would need to send a lot of requests.
If you created a timer that is not enabled and put the prints in the timer
all you need to do is enable that timer , in the timer code you disable it at the end.
There are a lot of examples in my How to use Reparse mode.

Hi Paul, It’s a good idea to use a timer to enable number of objects. I note this tip !

Today, I went on my project. I noticed that sending a request for read any variable works (see upper) … only if this variable was a “global” variable. It seems not working when the variable is “normal”.

Useless to say, I spent a lot of time before understanding this…

Best regards,

RovDan

Its a long road to learning about these displays as the information is so little.
They only expect a page to be used while on display and globals use up ram where other variables free up ram when not in use. The display can do a lot of the converting of variables , maths and logical work before sending it to the serial port. In my case I completely did away with needing another micro in between my solar inverters and the display.


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).