Start a new topic

Sending commands from Arduino to nextion does not work

I am trying to send serial data from an arduino mega to a nextion via serial1. Receiving data works fine. My source code looks like this:

  Serial1.print("page 1");





  while (Serial1.available() > 0) {


    Serial.print(" ");


The nextion doesn't react at all and I get the command I am sending as a result. Tried different nextion libraries, same result. Does anybody have an idea?

1 person has this problem

Well, I am in quite a mood today.  It must be an OCD thang when my pain levels are too high or somethin.

When your Arduino code doesn't work ... that's not a Nextion Bug.

Absolute failure to look for answers on your part, certainly doesn't even begin to encourage me to try to assist you when in the Free Chat section - (which is where this should have been posted) had THREE topics dealing with Arduino visible in the Top Five most recent.

Now I am going to go out on a limb here, thinking along the lines, that these other people that have posted about Arduino in the Free Chat - just might be able to assist you and shed some light, had you asked them in their thread.  Or in the Gallery section where Joe P has an example of how to sync time (I am sure the sending and receiving of characters must be occurring within his code that he has graciously posted an HMI and an ino file).  But my best idea is using the SEARCH at the top of the page.

Nextion FAQ: "Nextion is not open source, we do not provide schematic, PCB layout, IDE source code or design data involved. We offer Level 2 support to customers, please understand that we can not debug your code, we can only ensure the hardware itself works as expected"

Five Sections - there are only FIVE sections:

Announcements: I guess that is Itead to have a spot where their stuff can be found

Feature Request: People asking for things that have yet to be implemented

Bug Report: Errors in Firmware, freak cases - a BUG

Nextion Gallery: An area for staff AND people to showcase something that worked

Free Chat: an OPEN section, as long as Nextion related, "FREE-CHAT"

Here is a trick:  When you post in a thread, everyone that has posted within that thread prior to your posting, gets an email with your new post.  So the key is to find threads dealing with the area you are looking for help in.  But read the thread through, the answer may already be stated, and they aren't going to come out of retirement to re-answer what they have already answered.  So read it through thoroughly.

When some one posts an HMI or .ino file, it usually indicates there is some level of success to show as an example for others to gain insight from.  BUT read the thread for the context surrounding why the HMI was posted.  (They may have been posting it in response to a request from another to see how far along the other side was).

IF I were you, I would ask the people whose libraries you were using.  If you have tried several, it seems like you are not using Nextions Library with the .  Mixing code is like mixing drugs and alcohol - expect something bad to crop up.  Itead's Nextion's Library is the one with the "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE".  Nextion's Library was item #1 in the Nextion FAQs under Announcements, which tells me you haven't even bothered to try.  First folder in their library is docs, the second folder in their library is examples.  So if you aren't trying for yourself, why should anyone else try?

But mostly I worry about the logic:  Of only FIVE choices, KNOWING that Itead Staff doesn't debug code because you have read the FAQs, and spec sheets, manuals and whatever documentation is available for a device you are trying to implement, you couldn't see that Free Chat was the logical choice and that Report A Bug would not be a logical choice, I strongly question you odds of success, as programming relies heavily on logic, binary true/false 1/0 to get those electrons to do what you need done.

If you are not using Itead's Nextion Arduino Library, you should be asking the programmers of the library you are using to gain insight into what they were thinking and the flow of logic they were envisioning.  And as far as Arduino goes for the ATMega - the manufacturer has so much info posted on their site, in their forums, and the other ATMega users have so many blogs, it is hard to do a Google search without them showing up in the results.

159 /*

160 * Send command to Nextion.

161 *

162 * @param cmd - the string of command.

163 */

164 void sendCommand(const char* cmd)

165 {

166 while (nexSerial.available())

167 {


169 }


171 nexSerial.print(cmd);

172 nexSerial.write(0xFF);

173 nexSerial.write(0xFF);

174 nexSerial.write(0xFF);

175 }


That is the guts of the Nextion sendCommand with the order of things


32 bool NexText::setText(const char *buffer)

33 {

34 String cmd;

35 cmd += getObjName();

36 cmd += ".txt=\"";

37 cmd += buffer;

38 cmd += "\"";

39 sendCommand(cmd.c_str());

40 return recvRetCommandFinished();

41 }


This is the implementation of a Text component using sendCommand

So logical deduction is that you are reporting a bug to iTead for someone else's Library - Gutzy!

Funny things about libraries is that what seems like simple code in a single function is actually an adherence to a fixed standard and cooperation in functions to ensure all tasks are being completed for the health of the whole library.  The sendCommand is making sure it is working with the bytes being received before stepping all over its toes and flushing needed data out BEFORE it steps up to the plate to send out its measly few bytes to request that page 1 be displayed on the Nextion.

So as you butcher the libraries scrambling in a dog-eat-dog fashion to push your way to the front to get your command to go through, you have managed to kill off the whole team of functions that have been trying to work together to keep things rolling.

If I were trying to write a command to change pages, I would follow the format of the NexText.cpp and NexText.h and create my NexMyFunc.h and NexMyFunc.cpp that wouldn't search out an object but just push the text I desired through and then have a function available just for that purpose.

I just found out there is a Documentation For Arduino users PAGE.  No shit. 

Note: the default configuration is for MEGA2560.

For Itead's ITEADLIB_Arduino_Nextion which was 1.1 in the FAQs here

Modules, Classes, Members, Hierarchy, Files and Examples

The programming has mostly been all done for you - except for reading your thoughts.

Logically, I've pointed to everything you need for a solution, and my morphine has finally kicked in.

Hi Thorsten. I had a same problem. You must use serial other serial ports. For example 10 (mega board) for Nextion tx and 11 (mega board) for Nextion rx because" Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)" I hope that my explamation resolved the problem. If not, tell me and copy my code (work fine with mega 2560). Regards

Question Jose,

That is with the Itead Arduino Nextion library?  It appears Thorsten may also need advice along the lines of which libs as his code certainly isn't flowing as if using the Itead lib, so which lib should he be using and point him to where is that located.  He has been trying several.

Hi Patrick, sorry for ruining your day and choosing the wrong forum. Beleive me, I read all the information on your pages and tried all the examples (which didn't work). I posted just a simple and short code so people don't need to read too much. Sorry, my fault.
Hi Jose, thanks for the support. I am not using the softserial, but serial1. It turned out, that sending code to nextion doesn't work, when connected to an external power supply. After connecting it to the Arduino +5V and GND my code worked fine (Flush command has changed and Waits for the transmission of outgoing serial data to complete). Funny, that receiving data works fine, but this problem only occures when trying to send data.

No, I am sorry Thorsten, I am feeling a bit better.

So you are saying that you are using Itead's Arduino lib?  and that none of it works?

Well, Itead's Arduino lib works fine, when nextion is powered by the arduino (which I tried only now), but sending does not work, if powered by an external power supply (probably you can connect both grounds and it will work fine as well). I was trying to find the error by using very simply and easy to understand code and monitoring the serial conversation. I was just so confused that receiving worked fine, that I had not thought of a powering problem. It's probably writen somewhere on your support pages, but I just didn't run ower it. I am glad it is working now. Nextion is really an incredibly good device. 

I am glad you have found your solution.  I am a programmer first, hardware second, and not an electrical engineer.  But I have been learning that ground on one device and ground on another can be very different indeed.  The 5V is a difference between value at ground and 5V from that value - but both devices could be far enough apart in their values of ground to cause real damage.  In networking cables, a card plugged into one socket connecting over distance via Ethernet cable to another card plugged into another socket might not be sharing the same ground, so these cables would include a shielding so that both ends could then share a common ground.  Which is pretty much the same principle you discovered and implemented.   Glad there was no damage - there are posts on here, not so lucky.

Perfect, Thorsten, even so, just in case that other users need help, I am using the lib nextion-master ( from bborncr. For me is more confortable that Itead´s.
In its examples you can a program that tested the comunication.
In my program, I send and received by 10 and 11 respectively
Previously, I had a lot of problem because all explanations were about Arduino Uno.


(235 Bytes)