Unofficial Nextion/TJC User Forum

Changing Nextion values from Arduino

Hello, I am dealing with a problem.

I need to change the value of a Nextion screen number variable externally. I wrote this code to make this update via Arduino, here’s the code:

#include <SoftwareSerial.h>
SoftwareSerial Nex(5, 6);

void setup() {
// put your setup code here, to run once:
pinMode(0,INPUT);
pinMode(1,INPUT);
Serial.begin(9600);
Nex.begin(9600);
Nex.print(“cmisdrm.gubredoz.val=”");
Nex.print(“30”);
Nex.print(""");
Nex.write(0xff);
Nex.write(0xff);
Nex.write(0xff);
Nex.println(“END”);
}
cmisdrm is the page name and gubredoz is the number I need to change. I am compiling the code, however no change occurs in the screen. What should I do? I believe I arranged the Tx and Rx nodes well, would it work if I change it? Thank you.

Swapping the Tx and Rx wires is a good way to kill a Nextion :smile: (Don’t ask how I know.)

I find it easier to convert numbers to String, so your code will be as follows:
(note - I have put your numeric value as variable xxx)

#include <SoftwareSerial.h>
SoftwareSerial Nex(5, 6);

void setup() {
// put your setup code here, to run once:
pinMode(0,INPUT);
pinMode(1,INPUT);
Serial.begin(9600);
Nex.begin(9600);
int xxx=30;
Nex.print(“cmisdrm.gubredoz.val=”+String(xxx)+"\xFF\xFF\xFF");
}

Also - if you are sending to a screen not being shown, you may need to make sure the page and variables are global.

ulasus23

When you send a command from your arduino (or from a Picaxe like I did), don’t forget all your commands must finish with THREE 255 (or FF), not TWO

Of course, the variables you want to modify with your Arduino, must be GLOBAL variable.

With my DIY project to control my heating, it works very fine

Below my example with a Picaxe :
Serout SortieNextion,T9600_16, (“rtc5=”,b1,b2,b3,255,255,255)

Best regards

RovDan

1 Like

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