0
votes

I've problem with Nextion NX4024T032_011. I can send data to it from Nextion to Arduino , but the problem is Tx led in arduino blinks. Where as data from arduino is not accepted by Nextion as far i observed On Serial port i can only see "recvRetCommandFinished err" just after opening Serial-Monitor:recvRetCommandFinished err

The GUI Created in nextion is : Nextion GUI

If I Press the button in Serial monitor I am able to view : Serial Output but the number is not printed and incremented or decremented in display

I'm using this libary: Nextion library for Arduino mega 2560 with communication using Serial2

NexConfig.h

#define nexSerial Serial2

Arduino Code :

    #include "Nextion.h"

void t0PopCallback(void *ptr);
void b0PopCallback(void *ptr);
void b1PopCallback(void *ptr);

NexText t0 = NexText(0, 3, "t0");
NexButton b0 = NexButton(0, 1 ,"b0");
NexButton b1 = NexButton(0, 2, "b1");

char buffer[100] = {0};

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

void t0PopCallback(void *ptr)
{
    dbSerialPrintln("t0PopCallback");
    t0.setText("50");
}

void b0PopCallback(void *ptr)
{
    uint16_t len;
    uint16_t number;

    dbSerialPrintln("b0PopCallback");

    memset(buffer, 0, sizeof(buffer));
    t0.getText(buffer, sizeof(buffer));

    number = atoi(buffer);
    number += 1;

    memset(buffer, 0, sizeof(buffer));
    itoa(number, buffer, 10);

    t0.setText(buffer);

    digitalWrite(LED_BUILTIN, HIGH);
}

void b1PopCallback(void *ptr)
{
    uint16_t len;
    uint16_t number;

    dbSerialPrintln("b1PopCallback");

    memset(buffer, 0, sizeof(buffer));
    t0.getText(buffer, sizeof(buffer));

    number = atoi(buffer);
    number -= 1;

    memset(buffer, 0, sizeof(buffer));
    itoa(number, buffer, 10);

    t0.setText(buffer);

    digitalWrite(LED_BUILTIN, LOW);
}

void setup(void)
{
    pinMode(LED_BUILTIN,OUTPUT); 

    nexInit();
    t0.attachPop(t0PopCallback);
    b0.attachPop(b0PopCallback);
    b1.attachPop(b1PopCallback);
    dbSerialPrintln("setup done");
}

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

Any tips for changing that err to OK in recvRetCommandFinished err

1

1 Answers

0
votes

This is the return of the function "recvRetCommandFinished()" in the NexHardware.cpp

If you analyse this file, you will find out when you receive this string:

recvRetCommandFinished err

That means the arduino couldn't read the response from the serial that Nextion is attached to, specified in NexConfig.h

I had a similar issue, and when I revised my hardware connections, I could figured out what was happen on the electronics, not on sketch.