Start a new topic

How to hook in to "Postinitialized Event" from Arduino side?

Im my Arduino code, I would like to get a notification when the postinitialized event of a page is run.

What kind of code is needed on the HMI side for that?

How can I then listen to this event ("command"/"notification") in my loop-funtion on Arduino side and react accordingly since nexListen only listens to touch events?

I want users to input float values in a certain range only. But I cannot compare float values on Nextion side since floating values are not supported. So I need to do the modelling checking on the Arduino side in the page controller.

The post initialization event is run when the page is loaded

Catching the page change notification from Nextion Instruction Set requires sendme

You would need to add the functionality into your lib

Examine the touch 0x65, and follow the pattern for 0x66

Float is not supported Nextion side, but 32 bit signed integers are.

Therefore holding value in Variable nextion side where var * 1000 can be compared

for display purposes n0=var.val/1000 and n1=var.val%1000

Using two number components for float allows to reconstruct for compare


A bit more coding Nextion side - but certainly possible

Thank you very much for the very helpful and precise tips! With 'sendme' in the postinitialize code of the page, it works like a charme!
For the sake of online documentation for other users: Attached you can find my simple test code which listens not only to touch events but also postinitialize events.


#include "Nextion.h"

NexTouch *nex_listen_list[] = {

void nexLoopExt(NexTouch *nex_listen_list[]) {
  static uint8_t __buffer[10];
  uint16_t i;
  uint8_t c;  
  while(nexSerial.available() > 0) {   
    c =;
    // Check for touch events
    if(c == 0x65) {
      if(nexSerial.available() >= 6) {
        __buffer[0] = c;  
        for(i = 1; i < 7; i++) {
          __buffer[i] =;
        __buffer[i] = 0x00;
        if(0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) {
          NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3]);
    // Check for sendme events
    if(c == 0x66) {
      if(nexSerial.available() >= 4) {
        __buffer[0] = c;  
        for(i = 1; i < 5; i++) {
          __buffer[i] =;
        __buffer[i] = 0x00;  
      if(0xFF == __buffer[2] && 0xFF == __buffer[3] && 0xFF == __buffer[4]) {
          dbSerial.print("Postinitialize PageID ");
          dbSerial.println(__buffer[1], HEX);

void setup() {

void loop() {



The only "action" you have taken in your test code is to send it to your debug serial that it has indeed occurred, but is immediately lost to the Arduino. So ...

If you created a global scope variable

byte NextionPage;

And in your code put


Then your code will also have this page for any other logic it may be useful for.

Also sendme only needs to be sent once, and not each page.

You could add to NexHardware.cpp NexInit() function


then it doesn't need to be declared in the HMI design

Login or Signup to post a comment