loading

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.

<p>Love the simplicity of your code. Well done.</p><p>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?</p>
<p>Hi,</p><p>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.</p><p>Regards,</p><p>Gideon</p>
<p>Hi Gideon,</p><p>I think I found out how. - Make simple project with two pages.</p><p>On each page put a number box. I have Page0 with n0 and Page1 with n1. Make both number boxes GLOBAL.</p><p>Run debug. - whilst on page0 type instruction 'page1.n1,val=100' - I get error.</p><p>BUT....... make both pages GLOBAL and type the instruction again and it works. Brilliant.</p><p>You can even change other parameters like colours, pictures etc.</p><p> Bob</p>
<p>Hi Bob,</p><p>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.</p><p>Regards,</p><p>Gideon</p>
Hi Gideon,<br>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).<br>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.<br><br>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.<br>Any help will be appreciated.<br>Thanks,<br>Bob
<p>I like your work very much. Thank you so much.</p><p>You sent a variable here, but how is TXT sent?</p><p><br>for example; </p><p>When you have a 5v input, you see the &quot;active&quot; TXT on the screen</p><p>i try this;</p><p>String sendThis = &quot;&quot;; </p><p> Delay (50); </p><p> SendThis = &quot;t1.txt =&quot;; </p><p> SendThis.concat (&quot;active&quot;);</p><p><br> WriteString (sendThis);<br></p><div>But he did not work.</div>
Hello. I am not at home to test it now, but try everything the same except change the one line to:<br>SendThis.concat(&quot;&quot;active&quot;&quot;);<br><br>The difference being using double inverted commas. <br><br>Regards, <br>Gideon
<p>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.</p><p>Thank you so much.</p><p>Sincerely</p>
<p>Thanks for the Instructable. I'm having fun playing with my new Nextion.<br> I can't wait to try out your Arduino code as it seems very straight <br>forward......Except for the part where you're driving a device that <br>consumes 90ma from a port (7) that only supplies 40ma max. Maybe a <br>transistor should be used to supply the required current. I hope nobody<br> fries their Nextion.</p>
Hi,<br><br>I hope the code works well. You are absolutely right about the power thing. I will change that soon.<br><br>Regards,<br>Gideon<br><br>
<p>I got this to work, thank you.</p><p>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? </p><p>Or an analog input, can it change colors that way also?</p><p>Thanks again </p>
<p>Hi,</p><p>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.</p><p>Nextion has a dual state button however. It has a property &quot;val&quot; 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 &quot;val&quot; property with the Arduino to get different colours.</p><p>Regards,</p><p>Gideon</p>
<p>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. </p>
Hi,<br><br>That looks cool. I am glad you could expand it for your own purpose.<br><br>Regards,<br>Gideon

About This Instructable

4,944views

10favorites

License:

More by Gideon Rossouwv:Writing From Arduino Uno to Nextion  Getting Started With Arduino and Nextion (pt 3) Peltier Fermentation Chamber for Beer 
Add instructable to: