Introduction: Writing From Arduino Uno to Nextion

Hi all,

In previous instructables (1, 2, 3) we looked at how to send data from the Nextion to your Arduino Uno. We did this without using the libraries. Now I'd like to show you how you can send commands from the Arduino to a Nextion screen without the libraries. You can write almost any command that we find in the instruction set to the Nextion from the Arduino.

Step 1: Make Your Interface

For this instructable you can just download the interface. There is no code anywhere in the interface. It is much simpler than the previous instructables.

Step 2: Connect Your Components

Refer to the picture and connect your Nextion to the Arduino. You should also connect the circuit.

The idea of this circuit is just to have 2 resistors with different values connected in series. In series resistors are voltage dividers. We can measure the different voltages over the resistors and output that reading to the screen. You can also measure ground and +5V to see if they are indeed read as 0 and 1023 by the Arduino.

EDIT: In the past I connected the Nextion to a digital pin for power, but this is not recommended. If possible rather power your Nextion from the 5V pin on the Arduino or an external 5V power supply.

Step 3: Upload the Arduino Sketch

Download the sketch and upload it to your board. I tried to add enough comments to the sketch to make it understandable.

Step 4: Test

Play around with your A0 pin's jumper and read different voltages across the circuit. The value on the screen should change accordingly.

Comments

author
BJ43 (author)2017-06-17

Love the simplicity of your code. Well done.

I assume 'n0' is on the first page. Is it possible to send value on another Nextion page and if so what is the code?

author
Gideon Rossouwv (author)BJ432017-06-19

Hi,

Can you maybe describe the case in what you want to use it? This will help me to give you the best answer as I have a couple of scenarios running through my head, but I am not sure which one will suit your needs.

Regards,

Gideon

author
BJ43 (author)Gideon Rossouwv2017-06-19

Hi Gideon,
I have up to 6 WEMOS D1 mini clients sending temperature readings at 5 minute intervals to esp8266 server. I want to display: Sensor no., Date, Time, and Temperature on 3.5 inch Nextion (which I am awaiting delivery).
On second Nextion page I want to add these readings to Waveform plots. I can do this with Nextion editor debug instruction 'add 1,0,25' - where 1 is the waveform id, 0 is the channel and 25 is the temperature. (This will then show temperature history for many hours). But it only works if the plot is on first page.

It would be good to know how to push value/text of text, numbers and waveforms from Arduino/esp8266 using your simplified method to other pages.
Any help will be appreciated.
Thanks,
Bob

author
Mr_contractor (author)BJ432017-08-01

Hi again,

I sent a request from a different account (nukte) asking about your wemos clients sending to an ESP8266 server.

At my work, I would like to send temperatures from several wemos minis to a wemos host, and, while you see all sorts of ideas, most use the internet to upload to a service and then back to the host.

Because my application requires privacy I may not upload to cloud (etc.) but have to use the network inside of the building. So information may flow from wemos to router to host, but not out of the building. Any help is surely appreciated.

author
nukte (author)BJ432017-07-30

Hi;

I'm working on a project like yours, and wondered if you would allow me to read your code?

Thank you

author
BJ43 (author)nukte2017-07-31

Hi Nukte

My temperature project is quite big. It has RTC, SD card, oled as well as connection to Nextion and WiFi to remote sensors. You're welcome to what I have but its not for real beginner. Suggest you send me your PM with what you are seeking.

Will help in any way I can

Bob

author
BJ43 (author)Gideon Rossouwv2017-06-20

Hi Gideon,

I think I found out how. - Make simple project with two pages.

On each page put a number box. I have Page0 with n0 and Page1 with n1. Make both number boxes GLOBAL.

Run debug. - whilst on page0 type instruction 'page1.n1,val=100' - I get error.

BUT....... make both pages GLOBAL and type the instruction again and it works. Brilliant.

You can even change other parameters like colours, pictures etc.

Bob

author
Gideon Rossouwv (author)BJ432017-06-20

Hi Bob,

That's great! Sorry I couldn't be of more help. Running through some scenarios and ran into the problem that Nextion doesn't have global variables. Luckily I was wrong and as you've pointed out one can change an object from local to global by changing the 'vscope' attribute. Thanks for teaching me something.

Regards,

Gideon

author
uludirik (author)2017-03-17

I like your work very much. Thank you so much.

You sent a variable here, but how is TXT sent?


for example;

When you have a 5v input, you see the "active" TXT on the screen

i try this;

String sendThis = "";

Delay (50);

SendThis = "t1.txt =";

SendThis.concat ("active");


WriteString (sendThis);

But he did not work.
author
Gideon Rossouwv (author)uludirik2017-03-17

Hello. I am not at home to test it now, but try everything the same except change the one line to:
SendThis.concat(""active"");

The difference being using double inverted commas.

Regards,
Gideon

author
NguyenthanhC (author)2017-03-04

Thanks for the Instructable.It's verygood and so helpfull for any newone to play with Nextion.I spend days to find out this simply but good way to mke Arduino and Nextion work together.

Thank you so much.

Sincerely

author
BillS37 (author)2017-01-05

Thanks for the Instructable. I'm having fun playing with my new Nextion.
I can't wait to try out your Arduino code as it seems very straight
forward......Except for the part where you're driving a device that
consumes 90ma from a port (7) that only supplies 40ma max. Maybe a
transistor should be used to supply the required current. I hope nobody
fries their Nextion.

author
Gideon Rossouwv (author)BillS372017-01-06

Hi,

I hope the code works well. You are absolutely right about the power thing. I will change that soon.

Regards,
Gideon

author
sdtag (author)2016-09-14

I got this to work, thank you.

Instead of writing numbers in a box can you tell me if I can change a button's background color based on if a certain digital input is hi or low in the Arduino?

Or an analog input, can it change colors that way also?

Thanks again

author
Gideon Rossouwv (author)sdtag2016-09-15

Hi,

When in the Nextion editor, look at your button's properties. Properties in bold and green are the only properties you can set from the Arduino. The bco (colour) property of the button is green but not bold, so I suspect that you cannot change its colour.

Nextion has a dual state button however. It has a property "val" that indicates the button state and is editable via the Arduino. In short it is possible, but you'll need to use a dual state button of which you'll change the "val" property with the Arduino to get different colours.

Regards,

Gideon

author
sdtag made it! (author)2016-09-14

I added some buttons at the bottom of the screen so I can dim or brighten the screen. I have a 3d printer and made a wall plate for it so I can mount it in my wall. It will just barely fit into a single gang box.

instructable 4.jpg
author
Gideon Rossouwv (author)sdtag2016-09-15

Hi,

That looks cool. I am glad you could expand it for your own purpose.

Regards,
Gideon