Attest9.2
ESP32 FreeRTOS LED Blinking Example
This project demonstrates how to create two FreeRTOS tasks to control two LEDs connected to the ESP32 microcontroller.
Features:
- Task 1 toggles LED connected to GPIO2 every 500ms.
- Task 2 toggles LED connected to GPIO4 every 1000ms.
Prerequisites
Before you begin, make sure you have the following installed:
-
ESP32 Toolchain
- Install the official ESP32 toolchain.
-
ESP-IDF (Espressif IoT Development Framework)
- Follow the official guide to set up ESP-IDF on your system. This includes:
- Cloning the ESP-IDF repository.
- Setting up the required Python packages.
- Setting up the environment for ESP32 development.
- Follow the official guide to set up ESP-IDF on your system. This includes:
-
Python (for ESP-IDF setup)
- Python version 3.6 or higher is required.
Setup Instructions
-
Clone the repository
-
Clone this repository to your local machine:
git clone https://github.com/your-repository/esp32-led-blink.gitcd esp32-led-blink
-
-
Set up ESP-IDF environment
-
Initialize the ESP-IDF environment:
. $HOME/esp/esp-idf/export.sh
-
-
Install required Python dependencies
pip install -r requirements.txt -
Configure the project
-
Run the configuration tool to set up your ESP32 device settings:
idf.py menuconfig -
In this menu, you can configure parameters like your target ESP32 board, flash size, and other settings. For basic flashing, the default options should be sufficient.
-
Compiling the Code
- Compile the project
-
To compile the code for your ESP32 device, run:
idf.py build -
This command will compile the source code and generate the necessary binary files.
-
Flashing the Firmware to ESP32
-
Connect your ESP32 device to your computer
- Use a USB-to-serial adapter if necessary.
-
Flash the firmware
-
Once your ESP32 is connected, run the following command to flash the compiled firmware:
idf.py -p (YOUR_PORT) flashReplace
with the correct serial port for your ESP32 device (e.g.,(YOUR_PORT)
on Linux or/dev/ttyUSB0
on Windows).COMx
-
-
Monitor the ESP32 output
-
After flashing, you can monitor the output of your ESP32 via the serial terminal:
idf.py -p (YOUR_PORT) monitor -
You should see the LEDs blinking based on the defined timings (500ms for LED1 and 1000ms for LED2).
-
Code Explanation
: This task controls the LED connected to GPIO2 and toggles it every 500ms.task1
: This task controls the LED connected to GPIO4 and toggles it every 1000ms.task2
: This function initializes the GPIO pins for LED control and creates the two tasks using FreeRTOS.app_main
Troubleshooting
- If the serial monitor shows no output, check that the ESP32 is properly connected to the correct port.
- If you encounter any build errors, ensure that you have correctly set up the ESP-IDF environment and dependencies.
License
This project is licensed under the MIT License - see the LICENSE file for details.