Hi there,
I come right from another thread ( HERE ) where I struggled to establish serial connection with my Nextion display using a Arduino Micro.
Now that I am here, I can change texte field on the display and do various things, but the core of my project is to display images and change them depending which button (physical push button) will be pressed.
I made a simple sketch and a simple Nextion file.
One image block and one text field and we change both content during Setup.
Ultimately it will have to be changed on Loop but I thought maybe I will have some refresh rate problem, so to start and see if it works let's just update it once during Setup.
Well, guess what ? it didn't work.
The text field got updated with the new value but the image didn't change.
(You can find the project files attached with this post).
Here is my code:
/*
This code is based on the software serial example on Arduino's website
*/
#include <SoftwareSerial.h> //Include the library
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(57600); //open the serial port
while (!Serial) { // wait for serial port to connect. Needed for native USB port only
;
}
Serial.println("Serial On"); //Print this messages when the serial port is connected
mySerial.begin(9600); // set the data rate for the SoftwareSerial port
// We change the image of image box p0
mySerial.print("p0.pic=\"");
mySerial.print("1");
mySerial.print("\"");
mySerial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
mySerial.write(0xff);
mySerial.write(0xff);
Serial.print("img END");
// We change the txt value of text box t0
mySerial.print("t0.txt=\"");
mySerial.print("Monkey");
mySerial.print("\"");
mySerial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
mySerial.write(0xff);
mySerial.write(0xff);
Serial.print("txt END");
}
void loop() { // run over and over
Serial.print("TEST"); // Just to show some activity
delay(1000);
}
Basically, when we import images in the Nextion editor, each image receive a number as an ID.
So by changing the number reference it should change the image:
mySerial.print("p0.pic=\"");
mySerial.print("1");
mySerial.print("\"");
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
On my project file, the default image is 0, and I am changing it to 1 during Setup.
Note that if I type the command p0.pic=1
in the Nextion debug window, it does change the image.
Anybody with experience with images on a Nextion device here ?
I've already tried THIS TUTORIAL but it didn't work on my devices...
testImgChange.zip (12.5 KB)