Start a new topic

NexNumber update problem

Hi, been playing around with my Nextion for a while now, got gauges working and page switching from a button connected to my Arduino Mega 2560.


My problem is now when i use NexNumber and i toggle to page id 3 i can see my temperature number sent from my arduino, but it never updates unless i toggle the pages back and fourth a few times.


I use this line to set the number, inne refers to a float.


 n0.setValue(inne);


In nextion editor I have set n0 to global, also page is global.


My gauges work and updates on the same page, but not my NexNumber.


Can anyone point me in the right direction? :)


Do not set page to global.  Waste of memory space Nextion side.

Fully qualify globals Arduino side

NexNumber myNumber = NexNumber(0,3,"page0.n0");


NexNumber myNumber = NexNumber(0,3,"n0");

    as it is parsed in setValue function will look for n0 of current page.

NexNumber myNumber = NexNumber(0,3,"page0.n0");

    as it is parsed in setValue function will look for only the page0.n0


Don't forget to read the library code, it is part of your code ...


NexNumber.cpp:

bool NexVariable::setValue(uint32_t number)
{
    char buf[10] = {0};
    String cmd;
    
    utoa(number, buf, 10);
    cmd += getObjName();
    cmd += ".val=";
    cmd += buf;

    sendCommand(cmd.c_str());
    return recvRetCommandFinished();
}

 

NexHardware.cpp: 

 

void sendCommand(const char* cmd)
{
    while (nexSerial.available())
    {
        nexSerial.read();
    }
    
    nexSerial.print(cmd);
    nexSerial.write(0xFF);
    nexSerial.write(0xFF);
    nexSerial.write(0xFF);
}

 

 So when you see how you setValue is being parsed, you'll see why it is important (or minimally useful) to fully qualify the objname when declaring your global variables.



1 person likes this

Also note, that besides a few globals:


ONLY Current Page is in Nextion Memory, all others are DUMPED to make room for Current Page.

It is sloppy and lazy programming to update variables and access pages that aren't in memory.


Page PreInitialization Event - occurs BEFORE page changes

Existing page is DUMPED, Loading page is loaded as per the fixed HMI design

Page PostInitialization Event - occurs AFTER page is loaded

Nextion then loops and waits for one of:

  - touch interrupt from the screen, lookup object under touch point (press/release)

  - timer event triggered, execute code lines in timer

  - command coming in over serial

  - IO interrupt, execute any events if IO was configured with binding


I am not saying I am not sometimes (or even often) lazy,

   but I know where my errors resulting from such sloppy code comes from.



1 person likes this
Login or Signup to post a comment