Start a new topic

Serial comm between MEGA R3 and Nextion 7" Enhanced Display

Another newbie question. I have these two devices and I used to be able to upload sketches/programs to the display via the Arduino serial port. After firmware update or something I can no longer do this I keep getting timeout errors in IDE and unable to connect errors in Nextion Editor v 0.47. 

I have no idea if it is a problem with my display or Mega or just a simple setting issue. Please anybody?

Your question isn't very clear. Are you talking about...

  1. Uploading Sketch/Arduino c/c++ code from Arduino IDE to the Mega R3 via the Arduino serial port, or...
  2. Uploading HMI/TFT code/firmware from the Nextion IDE to the Nextion Display via the Nextion serial port and a USB/TTL adapter, or...
  3. Serial communication between the serial ports of your already programmed Arduino Mega and your already programmed Nextion Display?
If 1. then it's not a topic for this forum, rather look at the Arduino forums.
If 2. then check the baud rate settings of your display and the Nextion IDE to match, and/or check the serial connection wiring (Rx->Tx and Tx->Rx). When the problem persists, describe your comm setup in a detailed way.
If 3. give a code snippet here which allows others to reproduce the error.

I thought it was clear in the subject, but let me see if I can make it even more clear.

I have a Arduino Mega 2560 R3 from Arduino, not Itead, I have a Nextion Enhanced 7" HMI display, model NX8048K070_011C utilizing the Nextion Editor v0.47 and the Arduino IDE v1.8.3.  My Arduino Mega is connected to my computer using the USB connection provided and the Nextion is connected to the serial pins RX and TX to Mega TX0 (pin 1) and RX0 (pin 0) and to the %v supply of the Mega pins 5V and gnd.  I am a newbie and learning so I have not written any code, only using the examples which came with the editors. I first ran through a few of the examples (CompButton_v0_32.HMI and Utube Tutorial1.hmi). The first time I connected the the boards up I was able to upload the sketches/libraries in this configuration. Yesterday the same configuration did not work. The first day the Nextion Editor uploaded a new firmware to the Display, I believe it was 0.47 to 0.48. There was no need apparently to change pin assignments although I do see that the iTead board uses TX2 and RX2 for serial to the Nextion. I tried those pins on the Mega and no go at all. The baud rate appears to be automatically cycling through the choices from 4800 to 115200 in the Nextion Editor.

When I try to upload the sketch from the Nextion editor via this set up, it searches the different baud rates and then ends with the messages, "Connection failed Forced interrupt", when I try via the IDE Editor I get "avrdude: stk500v2_ReceiveMessage(): timeout" and "avrdude: stk500v2_getsync(): timeout communicating with programmer" all the while the TX and RX serial lights blink as if trying to communicate with the display. I sometimes also get "the selected serial port does not exist or your board is not connected". In the IDE monitor I get the message "recvRetCommandFinished err" twice and then "setup done"

Hope this helps explain better. No Snippets included as the stock no changes ComButton_v0_3s.hmi and .ino were used.

Perhaps I understand better now. You expect the Nextion IDE to upload the .tft file (compiled .hmi file) through the Arduino Mega to the Nextion Display, knowing that the Mega's USB Serial is internally connected to RX0 and TX0 on pins 0 and 1, where you connected the Nextion display. So, basically, both devices, the Mega and the Nextion are in parallel, seen from your computer, which can NOT work. 

!!! Serial is point to point communication, not a bus system !!!

That's why both fail over the same serial, the Mega and the Nextion.

So, if you use Serial0 to communicate between the PC and the Mega, you have to use one of the other Serial ports of the Mega to establish the communication between Mega and Nextion. This is the setup for an already programmed display which will then interact with your Arduino software which you created.

To upload a .tft file to your display from the Nextion IDE, you have to establish temporarily a separate, exclusive serial connection between the PC and the Nextion. This can be done with a separate USB-to-Serial/TTL adapter (i.e. Prolific). Or you can export the .tft file to a microSD card and use that to update the Nextion code.

All these informations are accessible through the Nextion IDE help, out of the fact that you may not connect two devices in parallel on the same serial port, which is common sense.

Steps for creating a Arduino + Nextion application:

1.) Create the .hmi file in the Nextion editor, compile it to obtain a .tft file. Use SD-Card or USB/TTL adapter to upload that from the computer to the Nextion.

2.) Disconnect the Nextion from the Computer and connect it to one of the Arduino's serial ports (NOT the same which is used for communication between Arduino and PC!!!)

3.) Create the sketch which handles communication between Arduino and Nextion in the Arduino IDE. Compile the .ino to obtain a .hex file. Use the Arduino's built-in USB/Serial to upload it to the Arduino.

That's all. It's so easy... :-) 

Ok, no need to try to insult my intelligence or lack thereof. First, I have been around computers for some 38 years. I have a little, but not a whole lot of programming experience using Basic and a couple of other low level (by todays standard) languages. I was a Project Manager overseeing 3000+ computer systems around the world. I do know a little bit about them. Had I known that the Mega USB was the same as the TX0 and RX0 pins I think I may figured that one out. As I said, I am new at this game, not stupid.  While I appreciate your help, there is no need to belittle me. I guess I should have noticed that the TX/RX lights blinked both during serial and USB transmission.

Your answer however, does not explain why it worked the first time I hooked these two together. After that, when it did not work the second time, I thought perhaps the display had been damaged.

So I do not suppose there is a way to upload to the display through the Arduino serial interface even though there are 3 additional ports? Really, upload by SD card? I can hardly get my fingers in there to insert the card (I have the enclosure with it.)

Anyway thanks for pointing out some information obviously missing in documentation.

It most probably worked the first time "by accident" if there hasn't been any code trying to communicate with the Nextion through the same serial port on the Arduino.

I personally don't like the SD solution, too. That's why I spent 8€ for a Prolific USB-TTL adapter which allows me to connect the Nextion directly to my PC in order to upload the .tft (quicker and more reliable, especially after setting bauds=115200 as a default rate for the Nextion).

I didn't mean to insult you. I rarely work with Arduinos, but googling for "Arduino Mega R3 Serial" (because I had a doubt) gave me as a result in the first place. And there I found the needed information.

Please accept my apologies if my tone was rough, but please understand that often in these forums, people ask questions which they could have answered by themselves with the required and desired systematic and scientific approach, i.e. by thoroughly studying documentation and reference manuals first. And that stresses people like me, who are basically wanting to help everybody who ran into true problems or bugs with the Nextion environment.

I perfectly understand your frustration in dealing with we newbies who don't seem to research prior to asking questions here. I can assure you that while my question seemed to evolve without previous research, it is not so. I researched both at Arduino and Nextion. As someone else expressed in these forums, there is nothing far worse than trying to find information on these sights and having 30 pages open at once only to find yourself going in circles. At 68 years of age, I don't have much time left, so it is precuious. I would like to get my simple, yet to me complex, project completed before I get to feeble and start drooling.  I can't even find a manual for either devices, so yes, I do appreciate your frustration and accept your gracious apology. Wouldn't have been nice if the developer of the Nextion IDE had provided for configuration of the additional serial ports.

I have in fact ordered the FTDI today. Thanks for the advice. Seems such an unnecessary expense.

You can not upload to Nextion via the Mega

Nextion's protocol - in Gallery> Tools, Tips, Tricks and HowTOs

Mega's protocol is the avrdude stk

Both are different and requires

Mega program uploaded to Mega via the Arduino IDE

Nextion compiled HMI project (*.tft file) upload to Nextion via

 - microSD card

 - over serial using USB-to-TTL Serial Adapter (FTDI, Prolific, etc)

Each will have their own COM port.

Here in the forum

 - Look at the Nextion FAQs

 - the Iteadlib Arduino Nextion Library (link in Nextion FAQs)

 - Arduino Nextion Examples (pinned to top of Free Chat)

Serial is preferred by some rather than the manual insert/remove of microSD

Not all microSD cards are great for embedded

 - Kingston Class 10 HC 8GB to 32 GB work well for me reliably.

But also with any serial adapter, Windows sometime Dozes zzzzzzzz.

  - usually removing the adapter from USB and reinserting will restore COMs

This is a Windows issue

Manual for Mega is on the Mega page at   albeit about 430ish pages

and that's just the hardware, Arduino C++ is another story -  no manual

"But also with any serial adapter, Windows sometime Dozes zzzzzzzz.

  - usually removing the adapter from USB and reinserting will restore COMs

This is a Windows issue"

LOL, I always said that Windows was not an ideal environment for developing software, since it's a consumer OS. That's why the Nextion IDE runs actually in a Wine 2.0 container on my MacBook Pro. It was a bit tricky to get the serial communication routed to the Mac's USB ports, but I finally managed it. :-) 


Oh stop your Wine'ing ... lol. ;)

One might argue that Windows even on top of a super solid Linux kernel still has it's inherent flaws. It still infects - just a bit better contained =)

That’s why I was a bit surprised when I saw that the Nextion IDE was developed using .NET which is a proprietary Microsoft thing. Doing it instead in C++ with the gtk library would have allowed to compile it for most current platforms.

Getting a bit off the subject aren't we?

Now that we have established the two can't talk over the usb/serial port, what port does the display want to talk on. I notice in the NexConfig.h file that dbserial is for the Mega and Serial2 for the display:

#define dbSerial Serial

#define nexSerial Serial2

What gives?? And since I can't get the example CompButton  to work, I assume it is port related. I get this error message on the Arduino monitor:

recvRetCommandFinished err

recvRetCommandFinished err

setup done

I also notice that perhaps the examples are written for the iTead Arduino clone Mega. Is that true?

Without sending me off into the nebulous never-never land of cascading documentation that literally leads me into darkness can someone communicate in straight tutoring what the hell is going on and what I need to do? All I really want to do is set up several pages with different buttons that send keyboard keystrokes to my computer via a real Mega2560 to my flight simulator. It should not be this difficult finding working examples.

Login or Signup to post a comment