Nextion 3.2 Basic + Mega 2560 issue

Using a basic Nextion module with three pages and driving using a Mega 2560. The page changes are coded on the Module itself and so they happen with no issues. However I am trying the current loaded page with Easy Nextion library and I have a problem. First page upon booting works OK and then choosing Page also is fine. But thats all - it gets permanently stuck on page two even though actual pages change as per user. So whats wrong ? Code is below :

// MCU : Mega2560 Board

#include "EasyNextionLibrary.h"

// Create Objects..
EasyNex myNex(Serial1);

unsigned long pageRefreshMillis, pageRefreshInterval = 1000;

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//                SETUP
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

void setup() {

  myNex.begin(9600);
  Serial.begin(9600);
  delay(1000);                         // Let the Nextion initialize, load Page 0 and show it for 1000ms

  myNex.writeStr("page 1");            // Load page 1

}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//                LOOP
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

void loop() {

  myNex.NextionListen();               // Process Nextion events as they happen.
                                       // Page 1 PreInitialized with printh 23 02 50 01, page2 with printh 23 02 50 02 and page3 with printh 23 02 50 03

  if ((millis() - pageRefreshMillis) > pageRefreshInterval) {
    if (myNex.currentPageId == 1) {
      refreshPage1();
    } else if (myNex.currentPageId == 2) {
      refreshPage2();
    } else if (myNex.currentPageId == 3) {
      refreshPage3();
    }
    pageRefreshMillis = millis();
  }

}

//*****************************************

void refreshPage1() {
  Serial.println( "I am on Page 1" );
}

void refreshPage2() {
  Serial.println( "I am on Page 2" );
}

void refreshPage3() {
  Serial.println( "I am on Page 3" );
}

//******************************************

@PerryBebbington

Thanks @Ballscrewbob

@Ardubit the Easy Nextion Library is the creation of @Seithan , so he is the best person to help you. His methods for dealing with a Nextion display are different to mine; he can hep with his, I can help with mine.

Thanks,

I am a bit lost on the reply. I never addressed my query to anyone specifically. I am fully aware of your method also ... and for this case I already have sent a mail to Seithan. Waiting for a response but I am not sure if he can respond to personal mails.

What happened is that @Ballscrewbob saw your post was about Nextion so he brought it to my attention because he knows that I know about them. When I looked I realised that you really need @Seithan to help you, not me, so I mentioned him so he sees it.

Best way to get someone to look at your question is to use @ and their username. Many people on here ignore PMs from people they don't know, some ignore PMs from people they do know!

1 Like

@PerryBebbington Thanks for the clarification. Appreciate that ! I have used your method for single page projects as its very easy. But when it comes to multipage projects with many buttons I get into a spin with the nested switch cases :wink: Sure its a problem with me and nothing wrong in your approach.

For what it's worth I find nested switch cases a lot easier to follow in MPLABX, the IDE used for PIC, than in the Arduino IDE. MPLABX indents each case more and it has vertical lines to show what aligns with what.

I've tried to think of a way to make them easier to follow but not come up with anything.

Ok here is an update on the issue posted by me.

When using the EasyNextion library I see that one should not place a tick ( basically to select it ) mark in the " Send Component ID " for any object like button. I think since the Library handles the button events based on the special characters sent by them, enabling this also messes up the process.

Once I removed the tick marks from these fields, the project is up and running with no issues.

I have also copied this to @Seithan for his point of view.

Thanks to all those who helped !!

You can configure the Arduino IDE "code formatter".
Personally, I use 4-spaces (no tabs) for indentation.

Life is very easy when you just press ctrl-T and everything is beautified.
Most importantly the indentation shows your logic flow.
You instantly see parentheses or braces mis-match.

David.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.