Nextion display calling page and updating text- Very beginner Question

HI

i am very new to display and programming. I was trying to update a text field on my 2nd page(i renamed it as weather). From the main page, i can able to navigate to 2nd page by clicking button(page navigation is from editor and i am not using Nextion library)

here is my code,

void show_weatherpage(){
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
Serial.println((int)Temperature);
Serial.println((int)Humidity);
mySerial.print(“weather.wetn0.val=” );
mySerial.print((int)Temperature);
//mySerial.print("");
mySerial.print(“weather.wetn1.val=” );
mySerial.print((int)Humidity);
//mySerial.print("");
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
}

if i comment any of ""mySerial.print("weather.wetn** ( meaning updating one field ), display is updating value

If i enable both "mySerial.print(“weather.wetn”, both fields is going blank

Anyone please help me to achieve this

Thanks & Regards,
Ben

Hi @bentech4u and welcome!

The reason is probably that you’re missing the triple mySerial.write(0xff) after the first command (assigning a value to wetn0). You need to add it to every command you’re sending, not just once for a group of commands.
Btw. if you want to share code, you can put ``` before and after a block of code and it will be formatted as code. For inline code like I used it in this post, you can use a single ` before and after the code.

Kind regards,
Max

HI

Thanks for the explanation. you meant to say like below:

void show_weatherpage(){

    Serial.println((int)Temperature);
    Serial.println((int)Humidity);
    mySerial.print("weather.wetn0.val=" );
    mySerial.print((int)Temperature);
    //mySerial.print("");
    mySerial.write(0xff);
    mySerial.write(0xff);
    mySerial.write(0xff);

    mySerial.print(("weather.wetn1.val=" ));
    mySerial.print(((int)Humidity));
    //mySerial.print("");
    mySerial.write(0xff);
    mySerial.write(0xff);
    mySerial.write(0xff);
  }

Exactly! I’m sure if you test it now it will work :wink:

1 Like

wow, it worked…thanks a lot

In Home page( id 0) i want to update date and time, i was trying to get that from NTP,

homepage calling function is called under setup(); . but the text field is not updating, i can able to see that under serial
here is my code:

void show_Homepage(){
  mySerial.print("home.t0.txt=" );
  mySerial.print(timeClient.getSeconds());
  Serial.println(timeClient.getSeconds());
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);
}

is this correct method?

Command looks right… But without knowing your HMI file there’re quite a few possible issues:

  • Is that page currently active? If not, is the component global? Otherwise you can’t access it.
  • Is everything spelled correctly? You called the page “Home”, but wrote “home” in the command. I assume it’s a simple typo in your post here but it would matter for Nextion.
  • How about the txt_maxl attribute of your text component? Is it big enough?

I’d suggest to use the Nextion Simulator/Debugger. Swap your serial ports*, such that the Arduino sends the Nextion commands to your computer. Then, in the Nextion Editor, use the Debug function and set it to MCU Input (bottom left). Now your Arduino can communicate with your HMI application running in the editor. The big advantage is that you can see all the data and commands that have been sent to the (virtual) Nextion as well as any potential error codes.

* You could also use a USB-Serial adapter to connect both serials to your computer at the same time (f.ex. using another Arduino).

While I think debugging with the editor is the easiest solution (because you don’t have to reupload your HMI file every time you make a change), you could also listen for error codes on mySerial and pass them to Serial to see if there are any errors.

Hope that helps!
Max

  • Is that page currently active? If not, is the component global? Otherwise you can’t access it.

Yes, that is the default page . moreover i am calling that function under setup. While testing text are loading to text field.

  • Is everything spelled correctly? You called the page “Home”, but wrote “home” in the
    command. I assume it’s a simple typo in your post here but it would matter for Nextion.

Home is for function and home is the print passing from nextion. Spellings are correct.

  • How about the txt_maxl attribute of your text component? Is it big enough?

it was set to “10”, and i am trying to display (in test) maximum of 2 charactor

HI

i i am printing like below:, text is appearing in text field

 void show_Homepage(){
  mySerial.print("home.t0.txt=\"21\"" );
  mySerial.print(Hours);
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);
  Serial.println(Hours);
}

but if i change that to a variable like below., text field is not updating.

void show_Homepage(){
  mySerial.print("home.t0.txt=" );
  mySerial.print(Hours);
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);
  Serial.println(Hours);
}

anyone please help me to find the issue

Thanks for the help, Actually, it got solved after converting variable to string.

Thanks for the update, glad you solved it. I completely overlooked the missing quotes.

Kind regards,
Max

1 Like