Programming nextion screen

Hi everyone,

I have been working on nextion screen with Arduino to control a machine. I am using the debug screen to check the codes, Arduino mega seems to get data, but the led does not turn on.

#include "Nextion.h"


NexButton b0 = NexButton(0, 2, "b0");
NexButton b1 = NexButton(0, 3, "b1");
bool led = false; 


NexTouch *nex_listen_list[] = 
{
    &b0,
    &b1,
    NULL
};

void b0PopCallback(void *ptr)
{
    led = true;
}

void b1PopCallback(void *ptr)
{
    led = false;
}


void setup(void)
{    
    Serial.begin(9600);    
    pinMode(13,OUTPUT);
    digitalWrite(13,HIGH);
    delay(500);
    digitalWrite(13,LOW);
 
    nexInit();

    b0.attachPop(b0PopCallback, &b0);
    b1.attachPop(b1PopCallback, &b1);
}

void loop(void)
{   
    if (led){
      digitalWrite(13,HIGH);
    }

    else {digitalWrite(13,LOW);}

    nexLoop(nex_listen_list);
}

Hello @Barahim
Have a read of Using Nextion displays with Arduino

As far as I know there isn't anyone here supporting the official Nextion libraries. There are my methods, set out in that tutorial, and a library by @Seithan , his way and my way are quite different, choose whichever suits you best.

1 Like

Thank you very much sir @PerryBebbington , I used @Seithan library and it works fine.

1 Like