Start a new topic

get page number from nextion display to arduino.

if anyone having problem to get the current page number of the nextion display here is a quick method i used. First download the nextion library from:https://github.com/itead/ITEADLIB_Arduino_Nextion.


Extract the libray in the: document/arduino/libraries


when you sucessfully extract the library,you should replace the nexHardware.cpp and nexHardware.h in the library. i uploaded a file below, just download it and extract replace in the library.


When you have successfully replace the two file, restart arduino ide(close and reopen it).


The arduino code below to call the function sendCurrentPageId():

  

//Declarartion of button, text.....
//when successfully edit the library run the code in arduino compile it and upload :)
 
uint8_t number = 0;//will store the page number.
 
void set up(){
//call to button, text etc...
 
}
 
void loop() {
// do not worry worry about the nowtime and update, just paste it in the loop like this.
  unsigned long nowtime = millis(); 
    unsigned long update = 0;
    if (nowtime > update)
    {
        pagenumber();
        update += 10000;
    }
    nexLoop(nex_Listen_List);
}
 
void pagenumber()
 
{
    sendCurrentPageId(&number);// call the method to get the page number.
 
 
switch(number){// use a switch statement for each page. 
         
        case 0:    //for page0
          dbSerialPrintln(number);// print the page number again for testing.
       // do something
        break;
         
           case 1:    //for page1
          dbSerialPrintln(number);// print the page number again for testing.
          // do something
            break;
           
           case 2:    //for page0
          dbSerialPrintln(number);// print the page number again for testing.
       // do something
        break;
 
       }// close switch statement.
 delay(100);
}

  if successfully you will get the page number on the serial monitor(loop). 

Hope this help. Thanks to Raphaël, Justin Sykes. 


The following post help me a lot:

http://support.iteadstudio.com/support/discussions/topics/11000001142

http://support.iteadstudio.com/support/discussions/topics/1000062463






rar

1 person likes this idea
Login or Signup to post a comment