Arduino Mega 2560 Nextion 7" and recvRetNumber

Good Day Everyone,

I have seen this topic touched upon a few times, but I am unable to get past the errors.

I am presently using the Nextion Standard 7 inch screen with a single button on it for bt0. The Arduino has a small program on it.

When I first power on the arduinoand I am monitoring the serial port, I get

recvRetCommandFinished err recvRetCommandFinished err setup done

And pressing the single button on the Nextion, I get.

[1652:0,1,bt0] b0PopCallback ptr=1652 recvRetNumber err

I have tried the 0.7.0 libraries, the https://github.com/itead/ITEADLIB_Arduino_Nextion libraries, and have had no luck getting past this.

I originally had an issue where I must have changed the baud rate on the Nextion, but used the rest command and it is now back to 9600.

I am at a loss. Does anyone have any other suggestions they may be able to provide. (Code noted below)

Thank you in advance.

Ken

include "Nextion.h"

NexDSButton bt0 = NexDSButton(0, 1, "bt0");

int ledPin = 5;

char buffer[100] = {0};

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

void bt0PopCallback(void *ptr) { uint32_t dual_state; NexDSButton *btn = (NexDSButton *)ptr; dbSerialPrintln("b0PopCallback"); dbSerialPrint("ptr="); dbSerialPrintln((uint32_t)ptr); memset(buffer, 0, sizeof(buffer));

bt0.getValue(&dual_state);

if(dual_state) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }

void setup(void) { nexInit();

bt0.attachPop(bt0PopCallback, &bt0);

dbSerialPrintln("setup done"); pinMode(ledPin, OUTPUT); }

void loop(void) { nexLoop(nex_listen_list); }

Hello kderector, Welcome to the forum.

Please read 'how to use this forum - please read' (there's a clue in the title) then go back to your original post and post your code as instructed.

If you try out the example in 'Using Nextion displayes with Arduino' at the top of the displays forum you will see it demonstrates a method of reading a button on a Nextion and running code on the Arduino specific to the button. I'm sorry but I can't offer any help with any Nextion libraries.

Thank you Perry,

I will go back and check the how to use the forum. My Apologies. This had worked in the past, so I am not sure what happened. My biggest concern is that I damaged the Nextion board somehow.

Thank you again sir,

Ken

Update to displaying code as per "how to use this forum".

#include "Nextion.h"


NexDSButton bt0 = NexDSButton(0, 1, "bt0");


int ledPin = 5;


char buffer[100] = {0};


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



void bt0PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;
    dbSerialPrintln("b0PopCallback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));
    
    bt0.getValue(&dual_state);
   
    if(dual_state) 
    {
        digitalWrite(ledPin, HIGH);
    }
    else
    {
        digitalWrite(ledPin, LOW);
    }
}

void setup(void)
{    
    nexInit();

    bt0.attachPop(bt0PopCallback, &bt0);

    dbSerialPrintln("setup done"); 
    pinMode(ledPin, OUTPUT);
}

void loop(void)
{   
    nexLoop(nex_listen_list);
}