Unofficial Nextion/TJC User Forum

Cannot communicate with my NX4827K043_011

Help! I Cannot communicate with my NX4827K043_011.

I had a smaller version some time ago which failed rather quickly and was returned. I then bought the model I mentioned above for a project I was working on. Unfortunately, I am unable to communicate with it at all. I am using a MEGA 2560 and have the device connected to Tx2/Rx2 on the Mega. I have tried to experiment with a very basic one page and one text label (t0) to see if I can send a text to it using the following simple program on the Arduino IDE:

void setup() {
Serial2.begin(9600);
}

void loop() {
Serial2.print(“t0.txt=”");
Serial2.print(“Test”);
Serial2.print(""");
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
}

I have also used bauds=9600 on the display page to ensure the device was set at 9600 baud.

Further to the above I have connected the Tx2 on my Arduino Mega to my nScope Oscilloscope and getting a decent waveform so I assume all the Mega’s I’ve tried are working. Oddly enough though I am getting the exact waveform back on the Nextion Tx, which is at the exact timing of the Mega Tx and without the Nextion Tx being connected to the Mega!

I’m by no means an expert, but would like to know if my above simple sketch should work and if not how can I test easily the Nextion is receiving data.

I guess that when setting an appropriate bkcmd value, you should get a qualified error message as a return value. Not sure, but I guess that your handling of the quotes which should be sent over serial is causing the error. I think they should be escaped.

Fjodor is correct.
Quotes need to be escaped, like so;

eg:

 // Update Status 
  Serial.print("main.status.txt=");  
  Serial.print("\"");           
  Serial.print(Status);      
  Serial.print("\"");           
  Serial.write(0xFF);
  Serial.write(0xFF);
  Serial.write(0xFF);

From the MCU I am sending a text string ‘Status’ to a Nextion text object ‘status’ on the Nextion page called ‘main’ .

Thank you so much for your reply but the Arduino Mega gave me an error on compilation :slight_smile:

‘Status’ was not declared in this scope’

I then tried it with quotes around “Status” which the IDE accepted but still no response on the Nextion.

I modified my simple test program as follows:

void setup() {
Serial2.begin(9600);

}

void loop() {
Serial2.print(“main.status.txt=”);
Serial2.print(""");
Serial2.print(“Status”);
Serial2.print(""");
Serial2.write(0xFF);
Serial2.write(0xFF);
Serial2.write(0xFF);
}

Thanks again :-).

Status was a variable in that example.
You would need to declare it, and assign a value.

Likewise, you would need to have a page called main and a text object called status to accept what the MCU is sending it.

What I posted was an example on how to delimit quotes.

Thanks, I misunderstood, I will give it another go.

I struggle with so many quotes so use \22
The following code works for me.

void setup() {
Serial2.begin(9600);
}

void loop() {
Serial2.print(“t0.txt=\x22This is a test\x22\xFF\xFF\xFF”);//print plain text
delay(2000);

String myText = “Hello world”;
Serial2.print(“t0.txt=\x22Text: “+myText+”\x22\xFF\xFF\xFF”);//print variable
delay(2000);
}

1 Like

Hi Bobj,

Thanks for your suggestion. I have tried your sketch, which loads okay on the Aduino Mega, but still no joy.

I feel that I have a dud display! I had one before and never had this problem until it failed so I reckon I’ll cut my losses as I’ve had it too long to return now but thanks for your time.

Before you bin the display

Silly questions I know - but…
check you are using pins Mega pins 16 & 17
swap TX & RX over.
Also is there any action with the Mega when you are in Nextion Debug mode?
Regards,
Bob

Another thought
Try a different Mega serial port. You need to switch to ‘Serial.print’ to seem messages in Debug window

Hi Bob,

I have the pins in 16 & 17 and did swap them around just in case :-).

When I upload in editor I get the following error:

Connection failed
Forced interupt!

It prints okay in the IDE Monitor.

As suggested I will try another serial and let you know.

I’ve tried on Serial1 and still no joy :-(.

Would the character encoding option in the Editor setup make any difference by any chance?

Don’t know about character encoding.
I presume you have uploaded a tft file to the nextion with a valid text box
Bob


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).