Start a new topic

Connect two (or more) Nextion touchscreens to one Arduino

Is it possible with the library to connect more than one Nextion interface to an Arduino Mega with multiple serial ports? I wish for multiple screens with mostly the same functions. Thank You, Jim

It is surely possible in general, to connect as many serial devices to your Arduino as much GPIO's you have available for free.

But not without "rework" the existing library. How much you must "rework" depends on what exactly you mean with "same functions".


Hi, I have 2 touchscreens working on an Arduino MEGA, up to 4 could be "simply" connected to the serial ports of the Arduino MEGA.  

#include <Nextion.h>

Nextion myNextion(Serial1, 9600); //TOUCH A ---> TX to pin 18 and RX to pin 19
Nextion myNext(Serial2, 9600); //TOUCH B ---> TX to pin 16 and RX to pin 17

void setup() {
  Serial1.begin(9600);   //TOUCH A
  Serial2.begin(9600);   //TOUCH B



Thanks Filipe for the response. I am a newbie, can you explain a bit more? do you run separate code for each screen? if so, then do you locate it just after the serial begin?

Your MCU code becomes a bit more complex to handle the multiple screens ... BUT

in Filipe Lopes example:

  either the serial1 or serial2 says which RX/TX pair to send on, and

  either myNextion or myNext provides an distinction for the main class (lines 3 and lines 4)

It would be a matter of keeping the two clear in your mind

  myNextion or serial1 is going to the first Nextion device

  myNext or serial2 is going to the second Nextion device

  serial is going to debug

I'm sorry, I don't get it.

I created a simple 1 page program for the Nextion touchscreen with three buttons. My arduino program controls three outputs based upon the state of those buttons. I started with the fishtank program as an example. I used NexButton for two of the buttons and NexPicture for the third. This all works.

If I add the lines

Nextion myNextion(Serial1, 9600);
Nextion myNext(Serial2, 9600);

I get the error: "Nextion' does not name a type

I would assume that the Filipe code example allows me to interface with the screens one at a time. But I could use some help to implement it. I don't see how any of this changes the definition of NexSerial from Serial2 to anything else?

If you have a simple Nextion HMI file with only three buttons, you can use a simpler solution than the Arduino library for the communication with the Nextion display.

You can just send simple commands from the Nextion, for instance in the 'Touch Press Event' window:


You write similar code with "b"/"B" and "c"/"C" for button 2 and 3.

Then in your Arduino code you just check which character is received:


while (Serial1.available() > 0) {
  char char1 =;
  if (char1 == 'a') {
    // Add your code for the case where button 1 is in status 0
  } else if (char1 == 'A') {
    // Add your code for the case where button 1 is in status 1 
  } else if (char1 == 'b') {
    // Add your code for the case where button 2 is in status 0
  // etc. for other buttons 
  // Send character to Serial Monitor
  Serial.print("Character received from Nextion 1 = ");


NB: I have not tested the code, it just shows the principle solution.

Perhaps mastering one Nextion device and mastery of your MCU serials should be completed before attempting to do multiple Nextion controls.

@Raphael, it would be unnecessary to add so much extra processing to everything in the HMIs

If you use more than one serial (Serial1, Serial2, Serial3) and you define your Arduino side variables appropriately as Filipe has done, your Arduino already knows which Nextion touch events are coming in from. based on which SerialX it arrived on.  There certainly is much more to consider in how you define your routines for each nextion HMI.

@Jim,  I believe Filipe may also be using a different library based on software serial.

If you are using the IteadLib, you'd need to duplicate various aspects, beyond scope at the moment

It's nice to have different possibilities :-)

Based on my experience so far, I can use "print" commands in Touch Press Event window without problem. It doesn't seem to be too much extra processing for the Nextion. And my HMI file contains much more than one page with three buttons :-)


The main topic is about multiple Nextion devices, each on their own serial - just to clarify.

Adding a new nextion device on a different serial pair and synchronizing is more complex than a button

There are several library issues to accomplish

@ Jim Cramer

If you can show us some HMI files or screenshots of your project so far, maybe it will be easier for us to understand where you are and what you want to achieve.

Thanks everyone for your input.


First of all, I embarked on this to determine whether or not an Arduino mega and three Nextion screens could handle my project without slowing to a crawl, becoming slow to respond. If a user presses a button, they expect the action to take place more or less (seemingly) instantly. I have a commercial project which can be accomplished a number of ways, I am hoping this is one of them.


 If the library supported three screens, I could start with a few buttons and go from there, loading up the features I want, which involves pages of stuff. All the while looking for responsiveness. (If I have to, I can always use one Arduino per screen) I put together the hardware on a board to work with and test this out. I can make one screen do whatever I want with the Arduino (whatever I have tried so far). Now I realize that taking care of the multi-screen issue alone will take up time I don't have, and I then I will still have to make the whole project work, it's time I don't really have. I have programmed a multitude of devices going back to ASM on an 8080A, I can figure it out. Time is my enemy.


Being a commercial project, I have always intended to hire out some programming, but it looks like to even get to proof of concept I need hired help. I don't wish to disclose the project at this point, but there is a good example that will suit my needs. The fish tank project. Think of the fish tank with three screens that can control the same tank. Make the tank light dimmable (think slider), and the heater setpoint controlled on the screens (up/down buttons, set temp, current temp). If RTC is implemented, it needs to be set in one place for all screens. Forget the actual graphics, but most buttons will require images to get look and feel I want, and I have a designer for that. There’s more, but first I want to see if anyone is: A) interested in doing this B) has enough experience to do it promptly and C) has the time to work on it right away. Also let me know what you need. I don’t see a PM function on this board, I am open to suggestions on how to communicate. I am willing to share some (maybe all) of the library work that comes out of this project, but I will likely want a NDA from whomever I work with.

Thanks again everyone for your input.

Hi, I dont have too much time to explain, but right now I am using the NEXTION 5'' and they communicate to each other, they are connected to an Arduino MEGA and other 2 serial devices are connected to the other 2 remaining serial pins of the MEGA.

I am using this NEXTION library 

and it works pretty well for me on all the projects I made so far.

Here is an example how I send info to both screens:



Hope somehow I could help

I can be contacted at ---------------- if you wish Nextion side programming

I don't believe that setting up three serials on an Arduino is that difficult to accomplish

- I believe it is only a matter of playing with the config and attention to details for which HMI variables are declared with each serial for each Nextion.

However, I always retain all of my IP for any created work  - if that is some type of deal breaker, I can let you explore any other offers, but I am curious what kind of arrangement you had in mind.

Can two screens command same pins  ? thanks

Login or Signup to post a comment