Start a new topic

Simple question about changing a page from Arduino

Simply I wish to show page0 or page1 basing on a variable :

the code of the loop part is the following :

void loop() {

  if (test == 0) {; } 

  else {;


Obviously at the beginning I put  --->  int test = 0;

I expected to view only page0 but what's happening is that the screen is continuously changing from page0 to page1.

Here it is how I declared the objects 

NexPage page0 = NexPage(0, 0, "page0");

NexPage page1 = NexPage(1, 0, "page1");


// Declare a text object [page id:0,component id:1, component name: "t0"]

NexText t2 = NexText(0, 3, "t2");

NexText t1 = NexText(0, 2, "t1");

NexText t0 = NexText(1, 1, "t0");

I do not understand what I'm doing wrong because the code is really very simple.

Any help is appreciated.

Sorry.  Arduino code is to match the HMI code running on the Nextion.  This means that you must be aware of codes inside your HMI as well as your code in Arduino.  It isn't obvious that int test = 0 was present in your snippet - so it will  raise questions what else is missing? or present that shouldn't be?

Your loop for example, if you continuously send page page0ÿÿÿ at what point does it overload and reset?  There is no condition on how often to send this and loop iterates fairly quickly.  So assuming nothing is missing - but can we assume all is there?  No, cause where is nexInit(), or nexLoop()?

Thanks for your reply. There is nexInit() and it is in the setup.

Due to the fact that the code is very simple (it' a test just to understand) I enclose the file.

Thanks for your time

(1.68 KB)

Sorry I forgot to enclosed the hmi file too.

(6.18 KB)

Okay.  So your HMI has nothing being sent to your MCU.

Your INO has nothing changing  test

 - So as test is 0, page 1 should show.

NexInit() in NexHardware.cpp as defined sets page 0

So on start NexInit triggers page 0 to be displayed

and in loop() test will set page to page1

Now, if you are getting any more changes than this

it would lead me to believe your Nextion is rebooting.

and going through the two steps (page0 and page1) and rebooting

how can I avoid nextion to reboot?


Reboots can be insufficient power being supplied

Do not supply the Nextion from the MCU 5V

Supply Nextion on its own 5V, and ensure Nextion GND to MCU GND


It was just a problem of variables.

In fact modifying the if test like this :

void loop() {

  if (test == 0) {;

      test = 2;              //   <---------


  else {;}


The 2nd time that Arduino loops it skips the test.

It will be necessary, of course in another function, modify the variable test in order to show the desired page.

I modified accordingly the program I'm developing (using some encoders and their built in push buttons) and it works without any flickering of the display.

Thanks for the time you dedicated me.


Sorry , I forgot to modify the 2nd part of the test :

void loop() {

  if (test == 0) {;

      test = 2;              //   <---------


   if (test == 1) {;

      test = 2;              //   <---------



Login or Signup to post a comment