In this lesson, you will start the practical exploration of the features of the ESP32 dev kit. Observing “tradition,” the first sketch and circuit I invite you to experiment with will make a red LED blink. By doing so, you will learn how to control the state of a GPIO on the ESP32.
You can watch the video, or if you are the “reading” type, you can read the text below.
The wiringThis little example contains a single LED connected in series to a 230 Ω resistor. You can use any resistor value between 230 Ω and 500 Ω, and the LED will be bright.
Careful, though, don’t go lower than 230 Ω because then the LED will be drawing too much current from the ESP32, and this can cause damage.
Connect the anode of the LED to one of the GPIOs on the ESP32, and the cathode to the blue rail, which is connected to one of the GND pins of the ESP32 dev kit.
You can see the schematic below.
I have connected my LED to GPIO32, though I could have used any of the other pins (with some exceptions that I’m going to discuss later).
PinsThis small experiment is part of a comprehensive course on the ESP32. Throughout this course, I’ll be using this pin map that I’ve put together.
Feel free to download it, perhaps print it, and keep it handy to help you with the assembly of your ESP32 circuits (you can find the hi-res copy here):
In this pin map, you can see the most frequently used functions of each pin.
As you can see, GPIOs 34, 35, 36, 39 can only be used as inputs. Therefore, we can’t use any of them to drive the LED. They can be used for other things, though.
Notice the little “~” marks? A pin that is marked with a “~” can be used for PWM (Pulse Width Modulation) output. I show you how to generate PWM signals in the video course.
Working with the breadboardFor small circuits, you can plug your ESP32 dev kit to a mini breadboard, as I do in the photo below:
Attach the dev kit to the breadboard so that two rows of pins, starting at column 1, are available for jumper wires. In the majority of the experiments that I demonstrate in the course, I use the pins on the right side of the dev kit, so this arrangement works well.
By placing the top-left pin of the dev kit on column 1 of the breadboard, it is easier to count pins and plug-in jumper wires as you can look at the column numbers on the breadboard.
The sketchLet’s have a look at the sketch now.
Instead of loading a pre-written sketch, you will load the blink LED example and then modify it slightly to get it to work with the ESP32.
Load the example sketch by clicking on File, Examples, Basics, Blink.
And this is the classic Arduino blink example. It should look like this:
This sketch will almost work out of the box.
There is a reference to the LED_BUILDIN constant, which does not work with the ESP32, and you must address it.
Create a new single-byte constant, and name it “led_gpio.” The LED is connected to GPIO32, so store the value “32” in “led_gpio.”
Then, replace all occurrences of the LED_BUILDIN reference with “led_gpio.”
The sketch should now look like this:
That’s all the modifications necessary. You can go ahead and upload this sketch to your board to see it working.
Upload to the boardConnect your ESP32 board to your computer.
Make sure the board model is selected (look at the status line of the Arduino IDE for the text “ESP32 Dev Module”). If the ESP32 module is not the current target, select it from the Tools menu, Board, “ESP32 Dev Module.”
Then, check that the USB port for the ESP32 module is selected. Again, look at the status line for confirmation, and if the com/serial port does not look correct, select the correct one from the Tools menu, Port.
When the board model and port selections checkout (i.e., they are correct), it’s time to upload the sketch.
Click on the Upload button. If your board is like mine, and can’t automatically go into upload mode, press and hold the “BOOT” button immediately after you click on the Upload button. Then, observe the Arduino IDE output pane for upload progress information. When the upload starts, you can release the BOOT button.
The upload will complete when progress reaches 100%.
When the upload is complete, the board will automatically reset, and the newly uploaded sketch will start running. The LED will blink at a rate of 1Hz.
This wasn’t too hard, right?
Let’s take this one step further in the next lesson. You will use the same circuit to make the LED fade on and off, using the ESP32 PWM capability.
Check out our comprehensive resources on the ESP32This guide is part of our comprehensive set of free resources and video courses on the ESP32.
With these resources, you will learn how to use the ESP32 through a series of experiments. We'll start with the basics, like how to use the ESP32 to blink an LED and work our way to more elaborate topics, like using its built-in sensors and communications capabilities.
Comments