Institute of Technology of Department of Electrical and
Cambodia Energy Engineering
Embedded Electronics Lab
Lab 1: ESP32-C6 Basics
Group: I5-GEE-EA(Gr2)
Lecturer by:
M. LIM Phing
Student’s Name ID
SETH RATHANAK e20200160
Academic Year 5
Semester I
2024-2025
Learning Objectives
• Handle digital inputs and outputs on ESP-32-C6
• Understand simple push button debounce algorithm
• Create ESP-IDF component
• Program, debug and monitor the application via builtin USB-JTAG
I. Introduction
The ESP32-C6 is a powerful microcontroller developed by Espressif Systems. It belongs to
the ESP32 series, widely known for offering robust wireless communication capabilities
combined with efficient processing power. The ESP32-C6 is particularly notable for
introducing Wi-Fi 6 and Bluetooth 5 (LE) capabilities, which make it ideal for next-
generation IoT applications.
Figure 1: ESP32-C6
II. Tasks
1. Hello World in Embedded Programming aka “Blinky LED”
We will write a program to blink the builtin LED on GPIO11 at the rate of 400 ms. We will
create a project called “Lab-1-blinky-led” (refer to the tutorial on project creation section).
Once created, we can get the Intellisense working. Write the following code, then run Build,
Flash and Monitor.
After, flash this code into the hardware board saw that the LED on board GPIO11 of ESP32
is turn ON and the serial monitor is Blink LED state ON as show in the Figure 2: that Blink is
from TAG and LED state is from the line ESP_LOGI.
Figure 2: LED on at Serial monitor
2. Blink LED with 400ms
We will write code to toggle the LED on board at GPIO2 with 400ms.
In the while loop is set to true forever (while (1) or while (true)) to run as loop. And then, just
set LED_state = ! LED_state to blink state and using ESP_LOGI to print char in the serial
monitor.
Figure 3: LED ON, OFF in serial monitor
Figure 4: Toggle LED
After successfully run the application and observe the results on serial monitor, answer the
following questions:
a) What is TAG used for?
Answer: TAG is a string constant used to identify log messages in the program.
b) Why was the initial GPIO configuration not working?
Answer: The initial GPIO configuration not working because it not clears of the first state.
c) Why is 1ULL (unsigned long or 64-bit) used in pin bit mask setting?
Answer: 1ULL (unsigned long or 64-bit) ensures the pin bit mask is 64 bits wide, which is
needed because the ESP32 can have up to 64 GPIO pins.
d) What is vTaskDelay and why does the number 40 mean 400ms? It is possible to get the
program to delay for 405ms? Explain.
Answer: vTaskDelay(40) delays the task for 40 ticks, and the ticks duration depends on the
system tick rate. To delay for 405ms, you can use vTaskDelay(405 / portTICK_PERIOD_MS),
assuming your tick rate supports that level of precision.
3. Push Button Debounce the Hard Way
Figure below shows the visualization of Ping Pong algorithm and its debounce state at each
sample time.
Figure 5: visualization of Ping Pong algorithm
Before we get started, connect a push button to GPIO15 on your breadboard; then, create a new
project and call it “lab-1-button-debounce”.
Figure 6: Connection of button to GPIO12 and GPIO15
After connect we get with the following code.
To visualize the bouncing effect of the button, first we need to create the circuit which is
including some components.
We need 2 buttons by connecting a pull-up resistor to VCC and the button to GND, we also
add the 2 LEDs to verify that button was pressed or released.
Figure 7: ESP32 with 2 buttons
4. Creating an ESP-IDF Component
First create a new project and call it “lab-1-adc”. After it’s created, open the project folder and
press F1. Type in “idf create component”, then select ESP-IDF: Create new ESP-IDF
Component. Finally, name the new component “adc” and press Enter.
After this step, you will see components folder in your project explorer. A folder named “adc”
is already create. You will find there a source file named adc.c and a header file adc.h in the
include folder as shown below.
First add the decoded code to your adc.h
Then add the following code to your adc.c
Modify the file as shown:
In main.c, add the following code to test the functionality of ADC.
1. Experiment with Potentiometers:
By following the given code and ADC library from Lab-1, we can use it to experiment with
potentiometer by connect A0 or A1 Pin from Potentiometer to ESP32.
Experiment results: As a result, we can do assumption like that:
• Rotating the potentiometer changes the resistance, which divides the input voltage.
• The ESP32 ADC reads these voltage changes and converts them into digital values that
are then displayed as raw ADC values and calibrated voltage (mV).
Figure 8: Results in Serial Monitor
Figure 9: Hardware of potentiometer with ESP32
III. Conclusion
This lab provided practical experience with the ESP32 and its digital input/output capabilities.
We gained knowledge on configuring the ESP-IDF and VS Code, streamlining the
development process. Additionally, we implemented a push button debounce mechanism to
ensure stable signal readings. Through coding, debugging, and monitoring outputs via USB
JTAG, we honed essential skills for creating robust embedded systems. This lab enhanced our
understanding of embedded electronics and IoT development, bridging theoretical concepts
with hands-on application.