1
votes

I've got a problem with Nextion NX4024T032_011. I can send data to it from Arduino Uno or Leonardo but seems that Nextion is not sending data to Arduino when I'm pressing a button (Rx diode on Arduino board is not blinking). On Serial port I can only see "recvRetCommandFinished err" just after opening Serial-Monitor: recvRetCommandFinished err

According to me, Nextion button is set-up properly. Nextion button

I'm using this library: https://github.com/itead/ITEADLIB_Arduino_Nextion but I've modified it a little. I changed this line in NexConfig.h:

 #define nexSerial Serial2

to:

#include <SoftwareSerial.h>
extern SoftwareSerial HMISerial;
#define nexSerial HMISerial

Arduino Code:

    /*
How to use Nextion library:
https://create.arduino.cc/projecthub/tsavascii/nextion-lcd-communicate-with-arduino-uno-188a44
*/
#include "Nextion.h"
SoftwareSerial HMISerial(10, 11);

#define ledPin 13

NexButton b0 = NexButton(0, 1, "b0");
NexButton b1 = NexButton(0, 7, "b1");
NexButton b0_page2 = NexButton(0, 1, "b0");
NexNumber n1 = NexNumber(0, 5, "n0");
NexText t0 = NexText(0, 2, "t0");
NexText t1 = NexText(0, 6, "t1");
NexText t2 = NexText(0, 3, "t2");

int myInt=0;
NexTouch *nex_listen_list[] = {&b1,NULL};
  /*
    Difference between Serial write and print:
    https://arduino.stackexchange.com/questions/10088/what-is-the-difference-between-HMISerial-write-and-HMISerial-print-and-when-are-they
  */

void b1PushCallback(void *ptr)
{
  digitalWrite(ledPin, HIGH);
}

void b1PopCallback(void *ptr)
{
  digitalWrite(ledPin, LOW);  
}

void nextionPrint(String objectName, String value)
{
  objectName = objectName + "=\""+ value + "\"";
  HMISerial.print(objectName);
  HMISerial.write(0xff);
  HMISerial.write(0xff);
  HMISerial.write(0xff);
}

void nextionPrint(String objectName,int value)
{
  objectName = objectName + "=";
  HMISerial.print(objectName);
  HMISerial.print(value);
  HMISerial.write(0xff);
  HMISerial.write(0xff);
  HMISerial.write(0xff);
}

void setup() 
{
  pinMode(ledPin,OUTPUT);
  nexInit();
  digitalWrite(ledPin,LOW);
  b1.attachPush(b1PushCallback); //button press
  b1.attachPop(b1PopCallback); //button release
  nextionPrint("t1.txt", "Arduino Text");
}

void loop() 
{   
    nexLoop(nex_listen_list);
    
    ++myInt;
    
    nextionPrint("n0.val", myInt);
    
    if(myInt>254)
    {
      myInt=0;  
    }

    if(HMISerial.available())
    {
      Serial.println(HMISerial.read());
    }
    
    delay(500);
}

Any tips why I can't get any data from Nextion?

2

2 Answers

0
votes

First, recheck the page ID and Object Id for 2 buttons you declared. NexButton b0 = NexButton(0, 1, "b0"); NexButton b0_page2 = NexButton(0, 1, "b0");

How can two buttons on page 0 have same Object ID 1?

Also, recheck Tx and Rx connections. Tx to Rx & Rx to Tx. I hope this will solve your issue.

0
votes

Are you confident about the physical pin Arduino that you are using? I do always enough confusion so I have to resume my notes about the pin name of the IDE, the pin number of the MCU and the pin number of the board. In my sketch I've wrote:

SoftwareSerial HMISerial(10, 11); // RX, TX

I'm using Arduino Nano and I receive data from Nextion (BLUE wire) at the pin labeled D10 (the 3rd from the USB connector); I transmit data to Nextion (YELLOW wire) at the pin labeled D11 (the 2nd from the USB connector).

It's not a great help but it's all what now I can do. Good luck.