Start a new topic

How to use 2 nextion screens in 1 MEGA

Hi guys,


I got one Nextion screen working on pins 10 and 11 with Softserial. 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, any idea how to create a nextio_b.h?

  

#include <Nextion.h>
#include <SoftwareSerial.h>

SoftwareSerial nextion(8, 9);// Nextion TX to pin 10 and RX to pin 11 of Arduino
Nextion myNextion(nextion, 9600);

SoftwareSerial nextion_b(10, 11);// Nextion TX to pin 8 and RX to pin 9 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);
}
 

  

Any help would be appreceated.

Login or Signup to post a comment