Arduino Nano not uploading data to Nextion Display

Hi I am relatively new to using C++,
I have a little bit of experience using the Arduino IDE but I am a bit stumped when trying to connect a Nextion 3.2 LCD screen :thinking:

I have looked at a fair few tutorials but whenever I try to upload the code it doesn't do anything :pensive:

Any help would be most appreciated :slightly_smiling_face:

Nextion Editor:

Wiring:

  • LCD 5v to 5v in
  • Arduino VIN to 5v in
  • LCD GND & Arduino GND to Ground
  • LCD TX to Arduino RX (Pin 2)
  • LCD RX to Arduino TX (Pin 1)

Code:

#include <Nextion.h>
int variable1 = 0;

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

void loop() {

variable1++; //increase value of variable

if (variable1 == 201) { variable1 =0; } //Reset when reach 201

// Update Number
Serial.print("n0.val=");
Serial.print(variable1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

//Update Progress bar
Serial.print("j0.val=");
Serial.print(variable1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

//update gauge
Serial.print("va0.val=");
Serial.print(variable1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

//update text to Hot! once reach certain value
if (variable1 > 99) {
Serial.print("t0.txt=");
Serial.print(""");
Serial.print("Hot!");
Serial.print(""");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
} else {
Serial.print("t0.txt=");
Serial.print(""");
Serial.print("Normal");
Serial.print(""");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

//Hide Progress bar once reach certain value
if (variable1 > 119) {
Serial.print("vis j0,0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
} else {
Serial.print("vis j0,1");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

// Change Progress bar colour once reach certain value
if (variable1 > 49) {
Serial.print("j0.pco=63488");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
} else {
Serial.print("j0.pco=1024");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

}

Hello @Ralphyboy
Welcome.

Please can you read How to get the best out of this forum, then go back and edit your code to include code tags </> as per the instructions. Code tags make the code easier to read and stop the forum software interpreting code as formatting and messing it up.

Your wiring is not easy to see in the photo, so my comments are based on what you said and what I think I can see:

  • LCD 5v to 5v in - OK

  • Arduino VIN to 5v in - No, the 5V pin is where you connect 5V to power the Every, the Vin pin is for about 7V+. If you connect 5V to Vin then the Every is probably running on, maybe, 3V or so.
    LCD GND & Arduino GND to Ground - OK

  • LCD TX to Arduino RX (Pin 2)

  • LCD RX to Arduino TX (Pin 1)

OK but you are confusing 2 different things and treating them as if they are the same. There are 2 ports on a Nano Every: Serial, which is the first serial port, port 0, which is the one you use to upload code over the USB cable to the Nano Every, and also the one used by the serial monitor. In your code where you have, for example:

Serial.print("n0.val=");
Serial.print(variable1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

You are sending data to the serial monitor on your PC, not to the Nextion. Nowhere in your code are you sending anything to Serial1, which is your Nextion. You need:

void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}

Next, everywhere in your code that you want to send something to the Nextion replace Serial.xxx with Serial1.xxx

How are you putting the configuration from the the Nextion editor on to the Nextion? You can't do it with things wired they way you have them because the PC is connected to Serial and the Nextion to Serial1, the Nextion editor cannot talk to the Nextion. Simplest is to use a micro SD card, as per my tutorial Using Nextion displays with Arduino

You have included nextion.h in your code; are you intending to use the Nextion libraries? If so I will warn you that to the best of my knowledge there is on one who currently answers questions on here who helps with the Nextion libraries. If you use my methods I will help you, but there are other options suggested in the tutorial. My tutorial uses a Mega, but you can substitute a Nano Every; Serial1 on the Every and the Mega work the same (different pin numbers), so my Mega code should be OK with your Every (please tell me if it's not).

Enjoy.

1 Like

Sorry about that i shall read how to get the best of the forum now.

I have updated my Serials to Serial1 and my display is now working :grin:
I have also moved my wire from VIN to the 5V pin.

The reason I had nexiton.h on there was from when i was trying different ways to send code over from other tutorials, like NexText, but it didnt like it... i just missed removing that part.

Thanks a lot, you have been a great help!

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.