Help! How to use 2 Nextion touch displays with 1 Mega

Hi guys,

I got one Nextion screen working on pins 10 and 11 with Softwareserial. I am now taking my project into a next level and I need 2 touch screens connected to the same Mega.

I tried renaming a second nextion as b but apparently I cannot use the same library for the 2 displays?

#include <Nextion.h>
#include <SoftwareSerial.h>
 
SoftwareSerial nextion(10, 11);// Nextion TX to pin 10 and RX to pin 11 of Arduino
Nextion myNextion(nextion, 9600);
 
SoftwareSerial nextion_b(12, 13);// Nextion TX to pin 12 and RX to pin 13 of Arduino
Nextion myNextion_b(nextion_b, 9600);
 
char rx_message_A[25];
char rx_message_B[25];
 
void setup() {
   
  Serial.begin(9600);   
 
  nextion.begin(9600);
  nextion_b.begin(9600);
   
  myNextion.init();
  myNextion_b.init();
 
}
 
void loop() {
myNextion.listen().toCharArray(rx_message_A, 25);
myNextion_b.listen().toCharArray(rx_message_B, 25);
 
Serial.print(rx_message_A);
Serial.print(rx_message_B);
}

I already tried ITEAD support but no luck, maybe someone here could help me?

I am using this library for Nextion displays which works fine with 1 screen: https://github.com/bborncr/nextion

Thanks in advance.

Filipe

I tried renaming a second nextion as b but apparently I cannot use the same library for the 2 displays?

The code you posted does something. Re-read your post and see if you can figure out what it does.

You expect the code to do something. Re-read your post and see if you can figure out what you expect.

I wasn’t able to.

Why do you want to use SoftwareSerial when you have 4 HardwareSerials?

@PaulS: I want to be able to use 2 touch screens using either SoftwareSerial or Hardware Serial with an arduino Mega. Right now I have 1 touchscreen working fine on pins 10 and 11 SoftwareSerial nextion(10, 11); the other I cannot make it work either Software Serial or Hardware serial.

@Whandall: I know but I connot make it to work with hardware serial, how can I do this function with hardware serial: myNext.listen().toCharArray(rx_message_B, 25); ?

I guess like this

Nextion displayLeft(Serial1, 115200);
Nextion displayRight(Serial2, 115200);

I'm not shure how you make the Nextion communicate with 115200 or better.

PaulS: The code you posted does something. Re-read your post and see if you can figure out what it does.

You expect the code to do something. Re-read your post and see if you can figure out what you expect.

I wasn't able to.

1

The code I posted is supposed to print on the serial monitor the values stored in rx_message A and B but it only works for rx_message A, I get the messages but nothing happens to rx_message B

Whandall:
I guess like this

Nextion displayLeft(Serial1, 115200);

Nextion displayRight(Serial2, 115200);



I'm not shure how you make the Nextion communicate with 115200 or better.

It worked!!

Thanks, your my savier :slight_smile:

I don't even have a Nextion 8)

There was no hint in the documentation? They didn't suggest using HardwareSerial?

follow

Hello, been following this thread with interest. i am using a mega with 2 nextion displays using serial port 1 & 2. On one of the displays i am using the Nextion Library and the other just using direct serial transfer to the display using Serial2.print.

Is there a way of using the Nextion Library for both displays as it would be useful to be able to return data from both displays.

Regards.