ESP32 LED Blinking Tutorial with ESP-IDF: Menuconfig and Code Implementation Explained

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Ashi Sunny from innovate yourself your channel for exploring exciting projects and Innovations in the world of technology in today's video you will be diving into the fascinating world of microcontrollers and learning how to Blink an LED using esp32 and ESP IDF now that is not it for today because apart from this we will also see that how you can completely configure your esp32 board according to your project requirements so in short we'll set up the complete configuration I'll show you everything in detail so that you can at least apply this with your project that you may be working on in your future so let's get started to begin with a project we will need a few components firstly we will require an esp32 development board which is powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities additionally we will need an LED resistor breadboard and jumpers but just because in our today's video I'm not gonna add up uh the external hardware stuff so that's the reason we'll use the built-in LED of esp32 microcontroller so I'll use that and I'll demonstrate that how to do the blinking of your LED using esp32 and ESP IDF so that is all that I'm gonna show you in our today's video now let's not waste much time and let's straight forward start with the coding stuff and let's understand that how do we do that with ESP IDF so let's get started all right so now you can see on your screen that this is a project that we have covered in the last video where I demonstrated that how do you simply print the hello world using the ESP IDF so that was all about that but now we are not gonna use that same project we're gonna start everything from scratch so that I can explain you everything like how to start working with ESP IDF because you may have seen in my previous video that I have started working with Arduino and other softwares but we haven't worked with ESP IDF so we have to learn everything like how to work with this right so let's see that and for that let me do one thing let me open up a new folder right because it's like we have to create a new project and as you can see in here we don't have any option for creating a new project so I'll show you how to do that so for that I'm on desktop right now here I'll simply create up a new project and let me give it a name as blinking LED right so this is the name that I have given to my project so I'll simply create this and this is the folder that I'll be selecting right now just click on open and I'll Trust this okay so you guys can see that this is a completely new project for me where I don't have anything right now and this is the like project in which we don't have any file or anything right so this is all about this now we have to start working with this right and start working with this firstly what I need to do is I need to create my project right and for creating my project I will be using my ESP IDF or let's say I'll use the idf.py which I have already shown you in my last video so that I can simply do all the configuration and everything required for esp32 and ESP IDF right so I'll do everything now I'll simply go to terminal and I'll simply click on new terminal just click on that and over here you can see that a terminal is opened and right now you can see if I will type IDF Dot py and I'll press enter I'm not gonna get any output in fact you can see that I am getting an error right so to configure that or to set up that thing we know like how to do that and let me do that because I have already shown you that in my previous video as well right so I'll simply do this save workspace you can check my previous video as well so we'll do it in that way so let me do that quickly and let me add up the configuration for this so that uh we will be able to uh get that thing done right so let me do that all right so you can see I've simply add up the things like I've simply add up the default profile for your OS like what it will be opening whenever I'll simply open it up and accordingly I'll also set up like uh what it should do right because currently what I have to do is I simply have to open ESP IDF by default so that's the reason this is the path I have specified because my ESP IDF is installed on this directory or let's say on this location so that's why I have simply added this up right and this is uh for my win uh like MacBook system right on my system I'm using Mac that's the reason I'm getting this way and I am setting up this zsh uh this way right but if you are using Windows for that we have a separate configuration and for that you need to set up it like uh it will be like cmd.exe so in that way you will be having it right and in case you are facing any difficulties don't worry I'll uh add up a link in the description so you can check that and accordingly see like what configuration or let's say what uh setting parameters that you have to set over here so that uh it will open up on your Windows system as well right so I'll add it in the description you can check it from there right so this is the way how I have done it now I'll Simply Save it and I'll simply close the terminal and now I will open it again now can you see when I open the terminal this time it is first of all loading this IDF dot py now this is loaded successfully so that means now I'll be able to uh start working with this uh like configuration or let's say IDF dot py to start creating my project and to further do all the possibilities right so we'll do that so this is the first step that we have achieved and this is the way like how I have done it so now whenever I'll open up a new terminal every time it's gonna do the same way right so you can see I open one new terminal again the same thing is happening right so this is how I have done it now our first step is that we are inside this directory and inside this directory I have to start creating my project so for creating a project we have a command or let's say we have an instruction and that instruction is simply type this command IDF Dot py foreign to my project let's say LED blink right so this is the name that I have given and I have set the path uh to my current directory only so that it will create everything all it's all the required files on the current directory only right so I'll click that I'll press enter now you can see uh okay it is saying something like that this directory is not empty that is the reason that I am getting this issue right so I can do one thing I'll simply take this outside outside over here right or let me do one more thing let me create a directory on this present directory and I will create my project inside that so that it will not create such problem so let me do that I'll create this I'll move inside and now I'll write the same command again now you can see the project was created in this so this is the path for that now this is that project now inside this you can see I didn't created anything I didn't added anything but these all uh this folder is not empty anymore because we have created the project and we have got the by default uh like uh files which should be present over there right so you can see that we have uh like this main folder inside is Led underscore blink and inside that we have one more file that is cmakelist.txt I'll open it up and inside this you can see that this is the name of your project which you have over here right now let's say this is the name that I've given right here right so this is my project name and this is the cmake file right and accordingly inside this main folder you will see we have another cmake list just like here I'll open this up now here what we are defining we are simply registering that what components we are using or in other words you can say that this is the name of the C file in which you will simply write up your code so in case you have to add additional uh like a code for your project you have to mention it here or let's say you have to register it here so this is what uh or this is how it's gonna work so currently we are going to work with this led underscore link.c which is this one so inside this I'll write up the code and those codes are linked up just because we have registered filter right so this is how we have done it now these are the functionalities for your cmake list.txt one which is inside Main and one which is outside main right now I'll open this led underscore blink.c inside which I have to write up the code right so you can see this is the by default code which I have right here inside uh which you can see that that is one included uh header file which is stdio.h and we have the main function or you can say this is the main function where you have to write up everything whether you are writing directly or you're writing uh by using the functions right so this is how we have to do it now this is uh something which is uh which is where we have to write up the code and everything now our functionality for today's uh session is that we have to blink our LED so to Blink the LED we need to define or let's say we need to Simply set up like what pins we are going to use how we want to use that whether as an input or whether as an output and accordingly afterwards will also set up that what it should do whether it should turn on whether it should turn off so this is all the things that we have to mention in here so that is what I'm gonna Define in here and for defining that up I will simply write the wallets I'll simply include the header files and the header file which I'll need here is driver slash gpio.h right so this is how I have simply defined this or let's say this is how I have simply included this right and uh now accordingly I'll simply start writing up like how do I initialize it or let's say I'll set up that which pin I am going to use and how I want to use it and just because I have already mentioned in the beginning that I'm gonna use my built-in LED and on esp32 we have the built-in LED connected to pin number two so I have to Define that and for that we have gpio set set Direction right so this is uh how I'm going to do it and inside this you need to pass up two parameters one parameter is that what pen you're going to use second parameter is and how you are going to use it right so I'm gonna use the pin number uh two and to Define that uh over here in ESP IDF the way for doing that is gpio underscore num underscore the pin number that you want to work with I'm going to work with pin number two because that is connected to the built-in LED on my esp32 and now I also have to Define that how I'm going to use it and as I know that I'm gonna use it as an output so I'll simply Define it this way gpio underscore mode just like in Arduino you must have already seen that we have a mode that how do we set it up right so we use it like gpio mode underscore output right okay so in this way I have simply set up or I have simply said that this is the PIN which I am going to use so that I can simply control it or let's say simply I can blink my LED right so this is what I have done now accordingly I'll press enter now I have simply defined that what pin I'm going to use and how I'm going to use it now the next process is that I have to Blink the LED and to Blink the LED uh the process is repetitive process which means turning on the LED for some time turning off the LED for some time and that process is going to repeat which is called as blinking of LED so this is what I have to Define and for that I need to start a loop so that I can simply say that I am gonna blink it and I'm gonna blink it in finite time so that's why I'll start an infinite Loop now over here I'll simply write up my code and the code for that is like over here I am setting up that uh what is the direction for that or let's say what mode I want to use for this pin here I have to set up the level for this so I'll simply type it like set level now inside this just like uh here what pin I'm going to use I'm going to use pin number two what value I want to set it for either high or low you can set it that way but I'll set it like high or low which is 1 and 0 right and just because I want to start it like I want to run it or let's say I want to turn it on but for how long I want to turn it off on for some time and that sometime is let's say one second I want to put right and for that we have a command that is V task delay just open the bracket and here we have to Simply set up the timing for that I'll set up the timing as 100 right so this is the way how I will get it and similarly this will simply turn it on for one second right so you can see there is a variation in that right so that's why we are having this value so this will turn it on for one second and now I have to turn it off as well so I'll turn it off for uh one second again so it's like turning on turning off turning on turning off and this is gonna repeat multiple times right and one more thing is this uh or let's say one more thing is here and that is that this V task delay is not available in the header files which I have already included so for this I have to include two more header files one is this similarly one more task dot h so in this way I have done it and now our code is almost done or you can say our code is done right so in this way I have already done it and now our code is successfully written so that it will simply repeat the process repeat the process of turning on the LED and turning off reality right so this is how I can do that now this is the way to do it now one more thing you can see over here is that I am getting uh the errors over here or you can say I'm getting these underline which is red underline that means this is not included by default right so for doing that you can see when I clicked here I'm getting this bulb right so just click on that now here to resolve this I have to click on this first option which is edit include path just click on that and now just scroll down and here we have to Simply uh setup like over here you can see one include path per line so here we have to set up the path so that it will automatically be able to find out that where are these header files which I have mentioned in here right and to mention that I have a path and that path is which is okay so you can see I have simply added the path that this is the path where I have all the libraries and header files which are present inside this right and I've simply put start so that it will automatically uh figure out like where exactly we have the header files over there right so that's why uh we have it that way right okay so this is how we have done it and now it is done now I'll go back to the code okay I'll put it here only I'll simply put star star here and let's see it now okay now you can see uh previously I think there was some spelling mistake only that's why I was not able to get it but now uh it's fine okay now it's giving error in here storage [Music] okay anyways so this is the correct ly to do it right so sometime it shows you this error also so I can simply put it this way and this error will also be gone right so you can simply put it this way right now uh yeah this is done now the next thing is that we have to Simply upload the code so for uploading the code that process we have already seen in our last video but apart from that I also want to show you one more thing and that is to uh do the configuration of your esp32 right because uh currently we have two parameters basically which we have to change uh in the configuration or let's say in the menu configuration so over there we need to change two things one is the clock speed and second one is the flash memory right so we have to Simply change that because by default those values are different and in our case the values are different so I'll simply change that because those create some problem sometimes when you start uploading the code right so I'll simply show you how to do that just go to the terminal like over here you can see just simply go to IDF dot py space menu config just type this and press enter now you can see we have the configuration uh menu opened now over here you can see we have the multiple option which I can access using the arrow keys like up down I can access that and accordingly I can go inside and back side using the left and right keys and also there are some options where we need to select the option as a check buttons or something you can say so those can be selected using the space bar as well right so as I said that we have to set up two things one is the clock speed and one is the flash memory right so let me first of all go in here serial flash config and over here you can see there is an option with the name flash size so by default The Flash size is set to 2 MB and in our case we are using esp32 which is having a flash memory of 4 MB so I'll simply go in here and I'll simply press spacebar so that I can select it and you can see the size is changed right so flash size is 4 MB now and I can use it and esp32 comes with a different variant so you can check your variant and accordingly you can adjust the flash size uh whatever it is right so you can select that and accordingly select it now I'll go back and for going back you can press the S button ESC so just press that and it will take you backward and now second thing is we have to set up the clock speed and for that go to component config just go inside and now scroll down or let's say just use the arrows to go down and over here we have to go to ESP system settings let's go inside now you can see the first option CPU frequency I'll go inside again now the CPU frequency is 160 megahertz but in our case it's 240 megahertz so just simply select that and you can see it's changed so now these were the two values which I have to set up and currently just because these two were the only requirement for us so that's why I'm changing them but in case you want to make further changes according to the Wi-Fi according to the ble according to the Bluetooth or any other requirement if you have for your project you can come in here and you can select the options accordingly so this is the way to do that now after all like when you are done with everything once you have set up everything like whatever you want to change now on this screen just simply press ESC now it will ask you to save the configuration if you want to save it just press y if you don't want to save it just press n in my case I want to save it so I'll simply click on y so you can see when I clicked on guess the configurations are changed and they are saved and here you can see we have two SDK config files one is the old one and one is the new one so this SDK config is the new configuration after the changes that you have done right so I can show you that either just open it up and I'll simply search for uh 240 240 yeah basically you can see config ESP default uh CPU frequency megahertz is 240 this is what I said right now right same thing if I will check in the old one just find it out sorry about this okay now you can see previously it was this and this is 160 megahertz right so we have changed that right so this is the way like how we can do that and now once we are done with this once we have make the configuration changes now the final thing for us is that we have to Simply upload the code and for uploading the code I simply have to first of all connect my system uh or let's say I have to Simply connect my esp32 to the system so that I can accordingly uh do the modifications and I can simply upload the code right and for doing this uh I have to write up the command right and I'll write up the command here IDF dot py because first of all we have to build it right so for doing this first of all you have to build it so that your project will be uh created successfully and it will be created in such a way that uh the bootloader can be uploaded or you can say flash to your esp32 so this is what we have to do so while simply first of all Build It Up just press enter and wait for it to finish because we have make the changes in the con menu config so it may take some time because it's gonna build everything from scratch so you can see this right once it is done after that we have to start uh flashing the code to the esp32 right so just wait for it to finish uh okay uh in my case you can see I got an error because uh in my case I put the value for Value as true but the true is not acceptable it's written in uh small T right in case uh you don't want to see the errors or something we can do it this way also I can write one as well but yeah two is also uh correct but I'll put it one for now right so let me do it again okay so now you can see this time it's done successfully so to flash uh you can see it is giving you the options for that as well right and now it means it is successfully done now we have to Simply flash it and for flashing it I'll simply write it like es IDF Dot py and slash so it is simply giving you that this is the option like how to do this uh when you want to do it this way right but I also want to specify that what port I am using in my case just because I'm using Mac OS so my port will be something different right but in case you're using Windows system up in that you will be having the port something like this let's say com 3 com 1 com 7 something like that right so in your case your port number will be like this but just because I am using MacBook or you can say if you if you are a Linux user in your case also it will be the same right so let me do it let me put it foreign okay so this is the port uh which I have on my system so this is the way to uh put it right and on Ubuntu users or on the Linux users right you also have to put it in the similar way because you will also get the port number like this only right so this is for that and along with that I can also set up the bot rate uh I'm I'm setting it as 115 to double zero because I want to communicate uh like my esp32 with my system as well so that I can read like what's happening because uh currently uh you can see like uh I am simply putting it like turning it on turning it off something like this but in case you want to also put up a message over here that message you should be able to display there right so that is what we can do as well right so this is the way to do it and after that I'll also put up one more thing monitor so that I can simply uh see like what's happening uh with the esp32 right so currently I haven't written any uh message for that but it's okay I'll simply put it now and now it will simply flash it and along with flashing it will simply show you or open up the serial monitor so that you can see like what's happening right so I'll simply run it now so everyone uh one one more thing you can see over here SPI flashlight this is what we said right so this is what we have and also you can verify the clock speed as well right uh you may be able to see it here only right okay you can find it here only right that's not a problem if you are able to see it then it's good otherwise no problem so now you can see on your screen that this is the way like how we have done it and also you can see how the LED is blinking so this is the way like how we can simply blink our LED or let's say the built-in LED uh with the esp32 and ESP idea so this is all about this so that's all for today and also one more thing one last thing which I can show you for this is in case you want to stop it because if you will see if I will press like Ctrl C uh this uh menu or let's say this monitor screen will not go right so you can see this it's not going right I'm trying to do the things but it's not happening so if I want to stop it I have to Simply press control your closing square brackets just simply press that and it will be simply stopped automatically otherwise if you don't know about that you simply have to like uh terminate your terminal and then you have to start it so that's all for my site for today I hope you guys have understood like how we can simply work with esp32 and ESP IDF and just like in our today's video we have seen like how to Blink the LED and also how to set up the configurations uh of your esp32 so this is all about for this and if still have understanding any of the topic or if you still facing any difficulties in uh blinking your LED just feel free to leave a comment below in the comment section and also just wait for our next tutorial so that I can demonstrate something new to you you are using the ESP IDF so that's all for my site for today I hope you are able to understand this but still if you guys are facing any difficulties just feel free to leave a comment below in the comment section so that I can help you as soon as possible and also if you guys have liked this video do click on the like button and if you're new to our Channel and if you haven't subscribed to our Channel yet do click on the Subscribe button so that you do not miss any videos from our Channel and also you can share this video with everyone so that they can also get the benefits uh like in learning all these process right so that's all from my side see you in the next video till then bye bye and take care
Info
Channel: Innovate Yourself
Views: 1,639
Rating: undefined out of 5
Keywords: ESP32, ESP-IDF, LED blinking, microcontroller, embedded systems, DIY, maker, Internet of Things, IoT, technology, innovation, coding, menuconfig, GPIO, open-source, Wi-Fi, Bluetooth, software tools, firmware development, Internet connectivity, smart devices, sensor integration, project-based learning, interactive demonstrations, debugging, troubleshooting, community support, open-source hardware, creative projects, innovative technology, technology enthusiasts, programming enthusiasts
Id: ByEsL11hgzE
Channel Id: undefined
Length: 28min 12sec (1692 seconds)
Published: Mon Jul 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.