59 Program a button on the
Vložit
- čas přidán 5. 09. 2024
- I have an updated version of this video • 174 Using the #nextio...
Here are some affiliate links you can use to support my channel
7.0" display amzn.to/3C99zVT
I have personally purchased the next link with good results
2.8" display amzn.to/43lfxPl
This video shows how to send commands to the Arduino from the Nextion without using the Nextion.h file. I show setting up the Nextion along with coding the Arduino. If you have any questions, ask in the comments section.
If you enjoy the content, consider donating a cup of coffee at ko-fi.com/chea...
#nextion
#arduino
#display
#tutorials
Thank you for awesome tutorials, i made my 1st real project with your help, God bless you, all the best. The way you share and teach is what i like most. Never had a teacher like you in engineering class.
Wonderful!
This was INCREDIBLY helpful! I was able to get a 12v DC motor working with my L298N motor driver/Arduino because of this video! It’s so cool. THANK YOU 😊
Glad it helped!
God bless you! After a week of fiddling and breaking the head with Nextion simple buttons, I found your video!!
I am glad it helped I have a new version of the video. #174 As I play with the display I keep altering how I use it. Thank you for taking the time to comment.
Your videos have been very helpful. I am a 52 year old noob and I have gotten this display to do everything I want with the IDE thanks to you and other youtubers.
If you ever get bored enough to do a tutorial on the 2x5 header gpio expansion board or the button board you will be my hero.
Thanks
Sorry but I have not worked with the intelligent displays. I did look up the boards you mentioned and it has me thinking about them.
This is where you've helped me get to. Thanks again! Having so much fun with this project. Have become an ecstatic hermit the last few days which is good because its cold outside. czcams.com/video/LT_txsPWYAE/video.html
The GPIO header expansion works with the Enhanced. I haven't messed with the intelligent displays either. I gave up on it for this project. Things like this derail me until I figure it out or shelve it and I wasn't figuring it out. 8 Digital pins, of which 4 are PWM just wasted for the time being.
I wish Nextion would have at least released a demo HMI showing utilization of the pins for different things but I can't find anything like it. Same goes for their button/beeper expansion board.
Thanks again for all your videos. The front end (display) is just about done and the back end(Mega) is under way. A whole lot faster thanks to these videos.
Cheers!
Thank you for this quick and straight forward explanation! I started using my Nextion with their libraries and lost 50% of controller memory to service 3 pages of the display, need to re-write without it to get some space back.
Good luck. Let me know if it works out for you. My methods are not for everyone.
Thanks for making this video. This really helped! It especially made a lot of sense to me as my first job programming was actually as a Audio Visual control system engineer over 20 years ago. I used to control kramer switches and projectors too!
That is interesting. I have left that industry a few months ago and miss that part of it. I originally hoped this channel would be about controlling Audio Video products. I am in the process of transitioning it to more general control and measurement. I know build testers for products that come off assembly lines. Thanks for watching.
Thank you for posting this series! Job well done sir
Thank you for the kind words. I hope you find them all helpful
Thank you! This makes much more sense!
Glad it helped and thanks for the nice comment.
Ty for this great series, God bless you !
Thanks for watching and may god also bless you and all those you happen to meet. I appreciate the continued support.
Excellent! Bravo and thanks. More please !
You are welcome. I try to publish weekly.
easy to follow and understand, thank you
Glad it was helpful!
PRINT is deprecated and appears not to work in latest Nextion editor use prints "ON",2 to send string to aduino. In other words the first argument is the string you want to send the second is its length. Great work by the way really enjoy learning with you.
I am rebuilding the main cheap controls website and will update all my code. I try to provide a link to all the HMI files and the Arduino code in the video. I have chosen to leave the code as is until I get the new site up and running. I will be displaying the code on the new site in a different way and at this time I have decided to focus on the new over the old. When I get the site up and running I will go back through this and other videos with an update. Thank you for watching and I appreciate the compliment. This particular video I may pull down and completely reshoot. It has a majority of my views and as time goes by I think there is a better way to explain some of it.
Son muy buenos sus tutoriales!! Muy bien explicados. Me podría ayudar con una duda por favor, tengo un botón en mi pantalla Nextion, requiero que al presionarlo se ejecute una interrupción en mi arduino DUE, que instrucción puedo usar??. En botones conectados fisicamente se usa la instruccion "attachInterrupt". En este caso cual instruccion debo usar?
Sorry for the late reply. This would depend on the model of Nextion you are using. You can request mor help at www.cheapcontrols.com.
Many thanks for this.
You are Welcome
Thanks for the great tutorials. However, I have difficulties querying the buttons and displaying the temperature of a sensor at the same time, for example. The buttons then no longer work. Is there a solution ?
I am not sure how to help in a comment. If you go to www.cheapcontrols.com, there is a help page. Go there and submit a comment with your email and I will do the best I can.
Thank you very much sir, it is great video
Thank you for your kind comment.
thank you best nexation tutorials i want to five pages slidshow after one seconds what is the coding in nexation editor without arduino
Good job bro
Thank you so much 😀
Hi, many thanks, your videos are simple and effective. I would go not for the library too, because i like not to learn different methods but i prefer to keep things standard. But how would you send a data e.g. a slider val, from the screen to the arduino without lib? Thanks
Subscribed.
czcams.com/video/k9hibCPbQ08/video.html Check out this video. It might help. Thanks for watching
How to add one or two more buttons to a sketch? Please.
I have an updated video to this one czcams.com/video/b9j7fX45qDo/video.html - Let me know if it helps you.
Thanks for this Video ! - as I'm a beginner : is it possible to control an extrernal Relay Board (16 Channel) with the nextion GPIO Pins over the serial I2C Bus or do I have to use an Arduino for this
I have not found a way to do I2C directly with the Nextion. I have controlled relays directly from the GPIO pins but not with any sort of protocol. Thank you for watching
You are the best
You are the best for watching my videos. I will have more this fall.
Hi, great tutorial !!!, Can you please also show, how Arduino can send back to display and that is shown on the touch display ? May be a bit complex interface like you send something from nextion display to arduino and then arduino talks back to show something on nextion display ?
That is a great idea. I will start on it today and hope to have one or two published in the next day or two(My real job is always getting in the way :-). I will do one simply sending data on an interval then do a followup on sending data back upon a request from the Display. Thanks for the recommendation. I should have done these sooner.
@@CheapControls great !!! Will be waiting for your next tutorial, request if you can show this for multi-page scenario, currently I am working for an assignment, will be a great help.
@@pravinpadale8787 I added the video. I hope it is what you need. I plan a third and will try to work in a multi-page feature.
@@CheapControls thank you very for your efforts, yes this is what I was looking for. It's great help. Looking forward for more videos from you in future.
I posted a multipage tutorial. I will expand on the topic on my next video.
i have a problem, every time I press the botom in the serial, appears a "?". which means nothing bcause I printed in a botom -> print "1" for example and the Serial.println("programa 1");
Should it be Serial2.println ?
@@CheapControls no :(
@@CheapControls actually having the set up and the loop empty, I load the program. I press anywhere on the screen and a "?" appears in the serial.
If you want you can email your code for review.
I have small dought iam sending analog values (0-1024);resultion(0-255).the wave coming very very small,and try to adjust to zoom not happening,i tried to adjust all variable of attribute of waveform but no results
watch this video and see if it helps czcams.com/video/9yGZYoCRS7g/video.html
Thanks! Yah.. I'm not a big fan of the Nextion library.
I understand why people use it but I found it to complicated. Thanks for watching
Thanks for these tutorials which help a beginner like me a lot, I wanted to ask you if it is possible to use the "dual state button" without the library.
Thank you.
Thank you for watching - Check out this video czcams.com/video/IsRS8MRLBgQ/video.html
@@CheapControls Thank you very much but I meant the "dual state button" present in the new releases of Nextion Editor, a single button with two states, I would like to understand how to distinguish the two states without the library.
Sorry for my translator's English :-)
The green and red buttons on that video are dual state buttons and I do not use the Nextion Library.
@@CheapControls ahhhh, ok, I didn't watch the video carefully, I have to use subtitles to understand and I'm a super beginner, now I understand better, thank you so much for your patience :-)
You are welcome. I struggle with many things so i try to be patient with others.
Great stuff. Can you help me design a four "Dual-state button" in Nextion display to activate four separate leds or relays on Arduino independent of each other.
Do you mean in a video or would you like to have me write the code for you?
@@CheapControls First of all thanks for your quick and kind attention. I would say make a video so it can help others like me. Thanks again.
Thanks for the donation. I will try to get it up by the end of the week. I am currently editing a video I hope to release tomorrow or Tuesday that shows how to use the built-in input output on the Nextion.
@@CheapControls My pleasure. Thanks a million.
Hello can you share some sample codes for uploading datalog to Nextion lcd and saving to its SD card
I have no examples of this sort of function at this time.
Hello,
I am not able to receive any response from the HMI (usng mega). However when i tried printing text onto the HMI, it is working, button is not. What am i doing wrong?
It is hard to say without seeing the code. Please consider going over to the Cheap Controls Facebook page. You can message me there and attach the HMI file for review.
Is it possible to send "ON" on the press event and "OFF" on the release event. I would like to jog a stepper motor while pressed and stop when released.
Thanks
That is very possible but I would recommend sending a series of on requests while the button is pushed and then not sending when it is not pushed. In the event that the Arduino fails to receive the off it will stop if it does not see the an on request for a set period of time. You can use a timer that runs on the press event and stops on the release event. Or you could use a dual state button if you don't want to hold the button while the stepper is turning. The project sounds interesting. Good Luck and Thanks for watching.
Video is great and easy to follow, so why can't my Nextion and Arduino follow same simple process. (always the way!!)
Loaded nex file to display but cannot get Arduino to talk to it. Loaded Arduino code without blue
nextion pin attached. Serial monitor won't even load hello world in setup. Help if poss would be very grateful. Else I will trial and error even deeper
using Arduino uno and nx4827T043. visual display from TFT file via cd card to Nextion.
You can contact me through Email or contact through www.cheapcontrols.com and send me the files to review. Thanks for watching.
hello there i have a quition please i am using your methode of codin nextion without biblio it's really helpfull its for my last year study project but the problem is i am using meanwhile an SD card to save the data for a long duration they're both on baud 9600 its arduino uno so i have only one serial can you give me an idea of what i can do
thanks
You can add a soft serial port. I have a video on the topic czcams.com/video/O0uDENcBZP8/video.html
nice tutorial...it is possible can use relay channel with arduino mega 2560?
Yes you can
Hi,I wonder if you can give me a hand with this exact code an example.I have problem receiving on the serial monitor two response from Nextion
example:
void sendData(String data){
if(data == "A");{
Serial.println("Relay 1 ON");
}
if(data == "B");{
Serial.println("Relay 1 OFF");
}
response :
A // button 1
Relay 1 ON
Relay 1 OFF
B //button 2
Relay 1 ON
Relay 1 OFF
This happens for one push of a button
I have 7 inch nextion enhanced display with 8 buttons,each one different print command.
On the nextion everything seems to be fine sending but when connected to arduino mega 2560 the response on the serial monitor for each push button gives me On&OFF
Thank you from now on you have another subscriber
I am not sure. You would have to request help over at www.cheapcontrols.com. I will reply with an email address to submit your code.
i have a number in my Nextion which i can change with the integrated Keyboard. I want to send "wait" and the variable of the number when i exit the page. What should i write on the exit button?
print "wait" + waitTime.val doesnt work :/
You have to set up a couple variables as strings and then load them with the data and then concatenate them and finally print the variable. It is not straight forward but once you do it a couple times it comes naturally.
variable va1 and va2 configured as a string
va1.txt="wait"
covx waitTime.val,va2.txt,0,0
va1.txt+=va2.txt
print va1.txt
I have not tested this so there may be a typo but I hope the idea is clear. If not let me know and I will try to find a current video I have made that describes it better. If I don't have a video I will make one. Thank you for watching
@@CheapControls wow, i havent got a notification from CZcams that you answered my comment. Anyways thank you it seems to work now, except i have another combination which i want to send over.
va0.txt="WAIT"
covx waitTime.val,va1.txt,0,0
va0.txt+=va1.txt
print va0.txt
delay=30
va2.txt="DISTANCE"
covx distance.val,va3.txt,0,0
va2.txt+=va3.txt
print va2.txt
the delay is there to "divide both variables" (the delay creates a new line). but the problem is, the second number is limited to 2 digits. I can enter 1 number and it sends 1 number but if i enter more than 2 numbers the other numbers dont get sent to my esp32. The first number is not limited at all.
@@CheapControls i figured it out. It was the "txt_maxl" which was at 10 so i raised it to 20 and now everything is working :)
Glad you got it.
I have the exact same code as you do, but I cannot get it to read the data from the screen. All kinds of question marks and empty boxes show up and that's it
Sorry to hear you are having issues. It might be the baud rate. Do you know how to connect the Arduino or MCU to the debug window. It makes it easer to simulate different strings and settings
@@CheapControls No, I don't know how to do that.
I can send data to the screen without any problems. I just can't read when a button is pushed.
Just wanted to let you know i figured out how to do it with the Library. couldn't ever get your way to work. thank you though!
There are lots of ways to do things. I have nothing against the Nextion library. If it works for you that is great. Please consider watching my videos on specific topics.
Thank you for the very valuable video. I have a question. Communication between Nextion TFT and Arduino Uno3 has succeeded in my project, but data communication does not work on the ESP32 development board and ESP8266 development board. I am new to Arduino and Nextion TFT. If there is a website or video that is easy for beginners to solve these problems, would you please introduce it?
I have wanted to do a video on the ESP series for awhile. I will look into it. I am not sure of any out there. Give me a week and I will try to get something together.
I am working on a basic ESP8266 example. Did you have any aspects of what you are doing that I can add to my basic video that might help you?
@@CheapControls I am very interested in videos that do not require the Nextion library you provided. What I want to do is very simple, but I am new to Arduino and programming. I am programming on an ESP32 Devkit or 8266 series. My stumbling block is to read the numerical data displayed in Nextion, such as n0.val, into the ESP32Devkit or 8266 side. On the Nextion side, I can get text data by doing something like (print "sometextdata") but I don't know how to handle numbers. For a shallow understanding, I refer to the sketches of many senior engineers, but it is difficult to understand because it is complicated. I deeply appreciate your kindness.
I will try to work in an example using both text and numbers. I will also try to show transferring text and numbers both too and from the Nextion. This might end up being a two part video but I will do the best I can.
OH, I learned something this past week. I did not know the ESP had that secondary serial transmit pin. It is funny how you can use something for awhile but completely overlook something. Not really important but I found it interesting.
Hello, I try to design an interface that allow me to have hidden and visible( if I want) keyboard to register any name on textbox easily, but I cant !!!!! could you help me please???
Something like this video? czcams.com/video/XSSVtR4-ceU/video.html
thank you, very gread tutorial, can you upload coad and hmi file
The code and HMI files are available at www.cheapcontrols.com Click on the the Nextion image and then look under the heading Nextion Tutorials.
where can I dowload all command thank
If you want the code you have to go to my website and ask for it in the comment section. I will email it to you.
Many thanks you...im trying to send several values to Arduino to control steper motor i used several values for example if i send A the stepper will move in speed and direction constant and if i send B it will move in different direction and speed its work but when loop finish the motor stop and wait another serial read how to keep same serial read value to keep in loop until i send different value?
I can't be sure without seeing your code. My guess is there is a default that get changed when you go through the loop the second time. If you have the ability, please post your code on the cheap controls Facebook page.
Thank you for replying im waiting the approval to join your group in Facebook i can post the example of my code here:
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 200
String data_from_display;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("HELOO WORLD");
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
if(Serial.available())
delay(30);
data_from_display = Serial.read();{
if(data_from_display == 66){
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(1000);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 1 revolution quickly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000);
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 5 revolutions fast:
for (int i = 0; i < 5 * stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 5 revolutions fast:
for (int i = 0; i < 5 * stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
}
}
}
Did you cut and paste the code. There are some curly brace errors and I am wondering if you typed it in it may be typos but if you cut and paste then I see some errors. I have accepted your facebook request. We can move over there. I am off to run some errands but will check in later.
How did you use the Arduino UNO serial port to send data to/from the Nextion ?
How do you upload Nextion file to the Nextion and yet talk to Nextion with Arduino?
I am not sure I am understanding your first question. If you are asking about multiple serial ports check out this video. czcams.com/video/O0uDENcBZP8/video.html If you are asking about using the built in Serial Port I run the transmit from the Arduino to the Receive of the Nextion and the Transmit of the Nextion to the Receive of the Arduino. When I am in development I have wires running to a USB to Serial device and I switch the wires between the USB device and Arduino as required.
@@CheapControls The UNO has one hardware serial port and you connect the Nextion to that hardware port, even though it has USB serial also "coming in" ? Perhaps because there are series 1k resistors on TX/RX ?
I know that I have to be careful when I program the UNO and have the Nextion using the same single serial port. When I have it connected to my computer and am in the process of uploading new code I disconnect the Nextion and then reconnect after I the code is uploaded the UNO . You can use Software Serial to add a second Serial port to the UNO.
Hi can somebody please help..
I have been using a nextion display NX 8048K070_011... I have just come to switch it on and all I get is the white display! Using a steady 5v , tried re upload of file but nothing works...it was fine last time I was using it. At a total loss..
Please help!
I am sorry but when I have issues with the hardware from Nextion I generally throw it away and get a new one.
@@CheapControls thank you, that is what I intended to do.
It is not an easy thing to do. I wish their tech support was better.
@@CheapControls their tech support is terrible, rude even.
I agree. It is a good thing their products are cheap. I asked if they would help promote my youtube channel and the said no. I feel like I am doing a good job showing their product. But I am not doing it for anything but me so I don't really care.
Do you know how to get the Nextion to work on the Arduino Nano 33 IoT? For some reason the same code that works on a regular Arduino Nano won’t work for an Arduino Nano 33 IoT.
Are you using Serial or Serial1. I don't have once of those so I can't test but I believe there is a second serial port on the device.
Cheap Controls are you referring to Serial in the config file?
In the Arduino Code. Serial1.begin(9600) Pins d0 and d1. I am guessing on the pins but I could look it up if this does not make sense. Serial is on all Arduino devices. The Mega has Serial, Serial1, Serial2 and Serial 3. I believe the Nano 33 ioT has Serial and Serial1. I could be wrong about that. Also does the device run on 3.3 volts or 5. 3.3 volts could be your issue also. I am a little out of my depth not having worked with this device and I want to order one so badly but I have too many current projects to finish up that it will have to wait. I hope this was helpful.
Cheap Controls It uses serial. I’ll try serial1 and hope it works. The device runs on 3.3 Volts, however I soldered the connection that also allows me to attach a 5V device to it. The error I’m getting comes from when I try to compile the code. It compiles perfectly for a regular Nano, however for the IoT Nano I get an exit status 1 error that says it can’t compile for some reason. Also, upon further inspection the error says softwareSerial only supports 20,16, and 8MHz processors. Do you suggest a workaround for this?
@@goldenfang57 If there is a serial1 then you should not use softwareserial
Hello ,
First of all thanks for your videos.
I'm following your method and it works when the two buttons (ON, OFF) are on the same page. But I want to make a screen where on page zero, pressing the ON button starts an output and also changes to page two. On this page there is another OFF button that stops the exit. I get the output to turn on by pressing ON, but if I press the OFF button on page 2 it only stops the output if I press it many times.
I do not have the real screen I am using the PROTEUS simulator.
Any ideas?
I am not familiar with the PROTEUS simulator. But I will be looking it up. Do you have your buttons set to Global scope.
Use Serial.readString() instead of appending
I prefer appending data because it gives me more control if I read one character at a time. I have combined multiple commands sent from the Nextion into a single string ad this method allows me to breakout of the collection based on partial data. I do understand what you are recommending and I understand why you would prefer that way. The nice part of the Arduino is there are many ways to complete a task.
Yes, you're right. The result the one that matters
Where do I start from?
Introduce nextion,
Introduce the ide you are using I don't even know the name
Show connection diagrams and probably libraries
Before going ahead with a lecture on it.
Sorry but that is not what my channel is all about. It is more just ramblings of an insane person that got stuck in a electronics lab and cant find his way out. Seriously, I appreciate you watching and commenting
@@CheapControls I appreciate you more for putting out content here for the community to develop themselves with. Please refer me to your first video on nextion. I am currently building an inverter and I want to make maximum advantage of a touch screen display. Thank you
I think this is my first video on the Nextion. There is no order, I think you can search my channel on CZcams for any topic you are looking for. Sorry, but I don't have a dedicated tutorial. I have been considering making a series. I think this video could use an update.
Do you have a similar tutorial but for Double State Buttons?
Try this one czcams.com/video/IsRS8MRLBgQ/video.html
And thanks for taking time to comment and ask.
Hi Cheap Controls,
I hope you are doing well. I've seen that you answer practiclly all comments, even though it has been a year. So I thought that you would answer to this one too.Pl
My nextion display (2.8 inch enhanced), arrived a week ago. I have been able to import tft files on it using my sd card, however I have NEVER managed to upload the nextion code, from the nextion editor, on my nextion from the nextion editor. While the arduino uno I used is recognised as COM3 (the port), it starts the baud rate thingy normally, but after 9 seconds or so, it writes the following error message: "Connection failed, forced interrupt. I have tried every single combination for the yellow and blue cable to tx and rx of my arduino.. nothing works. I have searched on all the forums the solution, but never came across it.... this I why I am adressing this to you, as you seem to know your stuff about the nextion more than well. I also have an other problem with the nextion editor... I have an arduino mega and nano (clones, but doesn't matter as recognised by arduino ide) and neither of them are recognised in the upload section of the nextion editor. They are not found.
My nextion however seems to work when I connect it to arduino and put code in the ide the standard way. But this only suceeded once, and that was today, uploading a gauges tutorial on it. With your tutorial, I have tried every single combination blue and yellow wire. Even the ones where non of them are connected. Nothing happens. It just keeps my old project going. What is your configuration?? (I have seen previous comments, tried the ones in them but no success. Please come back to me, and if you find the solution, you would literally be a lifesaver. Also note that I am on mac, so I use the ide on my macBookPro, however I am using a virtual machine (Parralels Desktop) to run the nextion editor (setup works fine). I really do not know how this could interfere with my problem, but please investigate🙏🏻🙏🏻🙏🏻.
Many thanks,
Vincent
/*
The following sketch is an example of how to send data to the Nextion display without any library.
The data can be text, numbers, or any other atribute of an object.
You can also send System Variables to change settings on the display like: brightness, serial baud rate, etc.
Connection with Arduino Uno/Nano:
* +5V = 5V
* TX = none
* RX = pin 1 (TX)
* GND = GND
This sketch was made for my 1st video tutorial shown here: czcams.com/video/wIWxSLVAAQE/video.html
Made by InterlinkKnight
Last update: 02/04/2018
*/
int variable1 = 0; // This is a simple variable to keep increasing a number to have something dynamic to show on the display.
void setup() { // Put your setup code here, to run once:
Serial.begin(9600); // Start serial comunication at baud=9600. For Arduino mega you would have to add a
// number (example: "Serial1.begin(9600);").
// If you use an Arduino mega, you have to also edit everything on this sketch that
// says "Serial" and replace it with "Serial1" (or whatever number you are using).
/*
// I am going to change the Serial baud to a faster rate (optional):
delay(500); // This dalay is just in case the nextion display didn't start yet, to be sure it will receive the following command.
Serial.print("baud=38400"); // Set new baud rate of nextion to 38400, but is temporal. Next time nextion is
// power on, it will retore to default baud of 9600.
// To take effect, make sure to reboot the arduino (reseting arduino is not enough).
// If you want to change the default baud, send the command as "bauds=38400", instead of "baud=38400".
// If you change default, everytime the nextion is power on is going to have that baud rate.
Serial.write(0xff); // We always have to send this three lines after each command sent to nextion.
Serial.write(0xff);
Serial.write(0xff);
Serial.end(); // End the serial comunication of baud=9600.
Serial.begin(38400); // Start serial comunication at baud=38400.
*/
} // End of setup
void loop() { // Put your main code here, to run repeatedly:
variable1++; // Increase the value of the variable by 1.
if(variable1 == 201){ // If the variable reach 201...
variable1 = 0; // Set the variable to 0 so it starts over again.
}
// We are going to send the variable value to the object called n0:
// After the name of the object you need to put the dot val because val is the atribute we want to change on that object.
Serial.print("n0.val="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print(variable1); // This is the value you want to send to that object and atribute mention before.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
// We are going to update the progress bar to show the value of the variable.
// The progress bar range goes from 0 to 100, so when the variable is greater than 100, the progress bar will keep showing full (100%).
Serial.print("j0.val="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print(variable1); // This is the value you want to send to that object and atribute mention before.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
// We are going to update the gauge to show the value of the variable.
// But instead of updating the gauge directly, we are going to send the value to a variable called va0 on the nextion display.
// On the nextion display we have a code on the timer (tm0) that compares the variable value and the gauge value, and updates the gauge only when they are different.
// The gauge range goes from 0 (pointing to the left) to 359.
Serial.print("va0.val="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print(variable1); // This is the value you want to send to that object and atribute mention before.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
// We are going to update the text to show "Hot!" when the variable is greater than 99, and show "Normal" when variable is below 100.
if(variable1 > 99){ // If the variable is greater than 99...
Serial.print("t0.txt="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print("\""); // Since we are sending text we need to send double quotes before and after the actual text.
Serial.print("Hot!"); // This is the text we want to send to that object and atribute mention before.
Serial.print("\""); // Since we are sending text we need to send double quotes before and after the actual text.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
}else{ // Since condition was false, do the following:
Serial.print("t0.txt="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print("\""); // Since we are sending text we need to send double quotes before and after the actual text.
Serial.print("Normal"); // This is the text we want to send to that object and atribute mention before.
Serial.print("\""); // Since we are sending text we need to send double quotes before and after the actual text.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
}
// We are going to hide the progress bar if the variable is greater than 119:
if(variable1 > 119){ // If the variable is greater than 119...
Serial.print("vis j0,0"); // This is to hide or show an object. The name of the object comes before the comma, and after the comma goes a 0 to hide or 1 to show.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
}else{ // Since condition was false, do the following:
Serial.print("vis j0,1"); // This is to hide or show an object. The name of the object comes before the comma, and after the comma goes a 0 to hide or 1 to show. Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
}
// We are going to change the color of the progress bar to red if the variable is greater than 49, and change to green if is below 50:
if(variable1 > 49){ // If the variable is greater than 49...
Serial.print("j0.pco=63488"); // Change color of the progress bar to red.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
}else{ // Since condition was false, do the following:
Serial.print("j0.pco=1024"); // Change color of the progress bar to green.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
}
} // End of loop
this is the only code that worked with the arduino. Hope it helps?.
Do you connect the Nextion directly to computer or through Arduino? To program the Nextion with Serial you must disconnect from the Arduino and connect it to pc using a usb to serial device.
@@CheapControls Thank you very much for this quick response! I have found a solution to the problem, by accident haha! I am writing it here to help other fellow nextion enthusiasts. Basically, if you directly upload the arduino code to the nextion, it will NOT work. You first need to upload the tft file, and then upload the code to the arduino with the blue wire plugged out, then reconnect it. I am so happy to have found the solution, and I hope this helps others too!! Yes, I can now upload common sketches with the nextion.
Thank you again!!!:))
@@vincent8368 I am glad you figured out a solution.
My name is indra from indonesia, i use print "ABC" in nextion on button (bo), then i use Serial1 port on arduino mega, when i prees the button more then one time, the result on serial monitor seem like this
ABC
ABC
ABC
AB_
ABC
ABC
⸮JC
AB_
AB⸮
ABC
AB⸮
ABC
ABo
ABC
⸮JC
i need help
thanks
It looks like your strings are getting out of sync. I made a follow up video that goes into more detail czcams.com/video/b9j7fX45qDo/video.html
@@CheapControls i try to connect nextian power to arduino board and then result ok, no problem found..
i think the problem is power source
Maybee I'm stupid but howto connect the Nextion against the Arduino sry I'm a newbie 57years old
It depends on the Arduino. I use the Nano in most of my tutorials, but it would be the same for the Uno. I use a library called software serial and define two pins( usually 2 and 3) as a software serial port. I use those pins to connect to the transmit and receive on the the Nextion. Using an additional serial port allows you to keep the arduino connected to the IDE and use the serial monitor for trouble shooting.
You are only a couple of years older then me. Never to old to learn something new.
Trying to make an LED on pin 9 turn On or Off and I can't get this to work using the method in the video. I can see the serial monitor receiving the PWR ON and PWR OFF messages from the Nextion screen but the LED is not turning on or off when pressing the buttons. I'm using the code from the tutorial and added my LED code to it. I've attached the code below, If anyone knows what I'm doing wrong please let me know. Thanks!
int Blue_led = 9;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("HEllo World");
pinMode(Blue_led, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
String data_from_display="";
delay(30);
while(Serial.available()){
data_from_display = char(Serial.read());
}
Serial.println(data_from_display);
//sendData(data_from_display);
}
}
void sendData(String data_from_display){
if(data_from_display == "ON"){
Serial.println("PWR ON");
digitalWrite(Blue_led,HIGH);
}
if(data_from_display == "OFF"){
Serial.println("PWR OFF");
digitalWrite(Blue_led,LOW);
}
if(data_from_display == "MAIN"){
Serial.println("MAIN COMPUTER");
}
if(data_from_display == "LAP"){
Serial.println("LAPTOP");
}
if(data_from_display == "DOC"){
Serial.write("DOCUMENT CAMERA");
}
}
What type of Arduino are you using, UNO, MEGA, NANO? Make sure you have the serial port pins connected correctly
@@CheapControls I'm using a genuine Arduino UNO
@@CheapControls The serial pins should be connected correctly because I can make it work using the Nextion Library. I would much rather use your method which is a lot simpler and clean :( See the the code below using the Nextion Library and I confirm that this works right now on my desk so the pins should be connected correctly.
----------------------------------------------------------------------------------------------------------------------
#include
//define LED PINS ON ARDUINO
const int Blue_led = 9;
//Declare your Nextion objects , pageid, component id., component name
NexButton b0 = NexButton(0,2,"b0");
NexButton b1 = NexButton(0,3,"b1");
NexText t0 = NexText(0,4,"t0");
//Register a button object to the touch event list
NexTouch *nex_listen_list[] = {
&b0,
&b1,
NULL
};
//Button b0 component popcallback function
// When ON button is Released the LED turns ON and the state text changes
void b0PopCallback(void *ptr){
t0.setText ("State:ON");
digitalWrite(Blue_led,HIGH);
}
//Button b1 component popcallback function
// When OFF button is released the LED turns OFF and the state text changes
void b1PopCallback(void *ptr){
t0.setText ("State:OFF");
digitalWrite(Blue_led,LOW);
}
void setup(void) {
Serial.begin(9600);
nexInit();
//Register the pop event callback function of the components
b0.attachPop(b0PopCallback,&b0);
b1.attachPop(b1PopCallback,&b1);
//TURN OFF BLUE LED WHEN TURNING ON SYSTEM.
pinMode(Blue_led,OUTPUT);
digitalWrite(Blue_led,LOW);
}
void loop() {
nexLoop(nex_listen_list);
}
@@marvg7062 I will look a little closer at your code and replay in a bit.
@@CheapControls thanks very very much!
wich rx and tx do yo use ?
On the Arduino? The Mega I usually use Serial2 on the nano and uno I use Software Serial and define it as Serial2
Hi , can you help me to connect nextion lcd with wifi
This is not a simple question. You would need to add something to the Arduino. The easiest would be to use an ESP8266 but we don't have videos on this yet. They are planned. You could possibly use a Raspberry PI but that would get pretty advanced. If you are not in a hurry we will have ESP8266 videos coming but I can't give you any definite dates. Hope this helps
Cheap Controls thank you i hope your video can help me to do my fyp ?
Hello, can i use the same method with stm32f4 ?
I am not familiar with the stm32f4. Can you provide a link. When I google the item I do not get a Nextion model.
Not familiar with the stm32f4, but I have used the same method with the arduino and with a PIC micro to talk to a nextion display. It gives you a lot of flexibility over what info is sent from the display and can make your final code more compact
May be this has clues, I tried editing nextion.h as mentioned in the below link but no luck,
nextion.ca/portfolio-items/nextion-iteadlib-and-stm32-step-by-step/
can you show the same method on a raspberry pi
Yes, I can, I will try to get one up next week Thanks for the video idea and consider joining the private cheap controls Facebook group. We can have a better conversation there and I can cater the video more toward your needs. I find that if one person is asking for something there are probably others that have the same question. If you don't join, no worries, look for a video on this next week.
I have been looking into this. The pi has more functionality than the Arduino. I need to know how you use the pi. Are you a command line user or a GUI user? I am working up a video on how to tie a Nextion into a Raspberry Pi as a web server to control a simple light connected to the Pi. If you are a GIU user this might not be for you.
@Blondie SL I took a little break from making videos. I will be starting back up after the 4th of July. This OctoPrint might be a stretch but I will look into it.
Who else wasted 2 hours on this not working
Sorry you had troubles. If you go to cheapcontrols.com and submit a comment with your Email address I will reply and you can submit your code for review. Thank you for giving it a try.
@@CheapControls update that may help others, there is a "rare" lost bauds documented in the nextion instructions. My Arduino and ide monitor were set to 9600 as well as the nextion but the nextion insisted on using 115200 baud without telling me which I found by changing serial monitor baud rate until it didn't display gibberish