Nextion - drawing lines, circles from Arduino

I'm using the Nextion display with a Mega2560. Whilst the documentation and examples are a little weak I have managed to make them work. However...

I would like to send some data from the Arduino to the Nextion so the Nextion can pick up that data and draw lines and circles that match the data.

I'm a bit stuck now as it seems I need to be able to do two (at least) things to be able to make this work and I cannot work out how to do either (I blame the virus of course...).

First thing is to send some data and have it stored in a variable or even better into an array.

Second thing is to invoke a function on the Nextion that uses that data and draws the lines.

Any hints or advise will be gratefully received.

Cheers
Alan

Hi Alan,

I suggest you start by looking at the GUI Designing Commands in the The Nextion Instruction Set. Try them out by using the debugging tool in the Nextion editor. Type them in and see what happens.

When you are comfortable with that send the same commands to the serial port and you should see they draw on the Nextion.

You can put predefined code on the Nextion in the configuration to do the drawing for you, but one step at a time.

PerryBebbington:
Hi Alan,

I suggest you start by looking at the GUI Designing Commands in the The Nextion Instruction Set. Try them out by using the debugging tool in the Nextion editor. Type them in and see what happens.

When you are comfortable with that send the same commands to the serial port and you should see they draw on the Nextion.

You can put predefined code on the Nextion in the configuration to do the drawing for you, but one step at a time.

I can draw a line with code in the Nextion editor. I cannot see (find in the documentation) how to write some code on the Arduino that draws a line on the Nextion display. I can see setting text on buttons, changing colours, sending data to the wafeform etc but nothing to control the GUI commands.

Are you saying I could simply send the string

line 20,30,170,200,BLUE

to the Nextion?

Cheers
Alan

Well, well, well....

Just send it as a s tring to Nextion (along with 0xFF 0xFF 0xFF) and it parses it does the job! Need to keep an eye which page you're on as it draws on the current one.

I now down vote the Nextion documentation. If it's there its too hard to find. If it isn't it should be.

Basically anything in the Nextion instruction set if you send to the Nextion over the serial port followed by 0xFF 0xFF 0xFF then it will do that thing.

Have you tried my tutorial 'using Nextion displays with Arduino'?

PerryBebbington:
Basically anything in the Nextion instruction set if you send to the Nextion over the serial port followed by 0xFF 0xFF 0xFF then it will do that thing.

Have you tried my tutorial 'using Nextion displays with Arduino'?

No I haven't

acboother:
No I haven't

Home work :slight_smile:

Note that my methods don't use Nextion (or any other) libraries. There is no one on this site currently providing support for the official Nextion libraries (unless you want to be that person...).

Enjoy :slight_smile:

1 Like

Sorry, I am new to Nextion, and try to follow the comments but I didn´t get results.

I want to draw a line from the Arduino into the Nextion > line 20,30,270.300,BLUE

I tried a lot of alternatives, but never works, the most simple is:

Serial.print(F("""));
Serial.print("line 20,37,270,300,BLUE");
Serial.print(F("""));
Serial.write(0xff);

Can anyone help me and be more specific?

Thanks

Hello nibcorrea,
Welcome.

Please can you read How to get the most out of this forum before you make another post.

Try

void setup() {
  Serial.begin(115200);
  Serial1.begin(9600);
  Serial.println(__FILE__);
  delay(2000);
  Serial1.print("line 20,37,270,300,BLUE");
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial.print("Done");
}

void loop() {
}

This is for the Nextion on serial port 1, please modify to suit the port you are using.

Thank you Perry, it worked!

Sorry, I didn´t send more information because I tried to go direct to the point. Next time I will follow your instructions.

nibcorrea:
Thank you Perry, it worked!

You're welcome :slight_smile:

I’m very happy to see this topic.
Before I learned, I used the Nextion MASSIVE libraries.
Not only do they suck up much needed memory, but their syntaxes are so convoluted.

I’m not sure if I"m allowed to mention a YouTube channel, so I won’t right now, but I found a channel that focuses on Nextion without libraries!

Yes, NO LIBRARIES NEEDED!
Which I believe Perry is getting at.

I mostly use Nanos for most projects and as can be expected, with Nextion libraries, you have so little memory left to write code in.
Keeping in mind too that the Nanos (probably other boards too) complain about things may not work right after you get over 55% or 60%. And in fact, things DO stop working.

So by using just serial you don’t waste memory and you can do pretty much anything without the Libs as you can with.
That also includes Nextion SENDING data back to Arduino.

For the Nanos, I do use the following (not for Mega):
#include <SoftwareSerial.h>
SoftwareSerial Serial2(6,7); // RX, TX These can be any digital pins, but I use 6 and 7

Then to save “Serial.print” statements, that can really suck up memory, I set up a single string:

String endChar = String(char(0xff)) + String(char(0xff)) + String(char(0xff));

In setup, I do this:

Serial2.begin(115200);

delay(100);

I do add the delay (which you need to do at every “SEND” because the Nextion takes a bit of time to process the request.
If you don’t use a delay, which can be as low as 2, or 5 or 10, then often things don’t work right.

On a first startup, I like to assure that the Nextion is on page 0.
So I send:

Serial2.print("page "+(String)currentPageName[0]+ endChar);

delay(50);

This can just be:
Serial2.print(“page 0”+ endChar);
delay(50);
But I use an array for retaining my page names (instead of numbers).

To send static text, all you have to do is:

Serial2.print(“t0Temp.txt=“SAVE”” + endChar); (use whatever your object name is)

delay(50);

If you have a number object, I send like this:
Serial2.print((String)currentPageName[0]+".j0Level.val=" + String(yourVariableHere) + endChar);
delay(10);
I actually put things like that in functions and call as needed, using parameters to display what I need.

There’s so much more, but to keep it short, that’s all I do here. :slight_smile:

But yeah, now due to no longer using libaraires, my entire code takes up so much less memory, that I can now do larger projects than ever before.

I highly recommend others to search YouTube for Nextion without Libraries.

If I am allowed to post a link and someone confirms that, I’ll happily share the link.

The guy who does these videos is an excellent teacher and very patient. He’s also very responsive if you have a question.
I haven’t even counted how many videos he has on Nextion without Libraries, but it’s a lot.
You will learn everything you need to know.

I hope this helps others.

What can I say. I love Nextions. I have a bunch of these displays, from 2.8" Basics (for building projects and for projects that don’t need Enhanced displays).
I have several 3.2" Enhanced displays, 1, 7" Basci and 2, 7" Enhanced.
Yes, I love these things that much. LOL