Goal of this experiment
Use the module ESP32-C3 SuperMini with PlatformIO Core with the example code Blink. The “Blink” sketch is a small program that does nothing else than blink the built-in LED.
All the steps are described here, so that even a beginner can follow.
There is a similar description at the PlatformIO documentation website, which we adapt slightly to be more Arduino compatible. This means that with the project set up as described here, you can either run PlatformIO to build, flash and monitor the software, or you can double-click on the .ino
file, which opens the Arduino IDE, and work from there.
Install PlatformIO
Follow the description at PlatformIO Core Installation.
The code
I modified the program for the ESP32-C3 SuperMini:
/*
Blink
Flashes a LED every second, repeatedly.
The ESP32-C3 SuperMini has an on-board LED you can control.
It is attached to digital pin 8.
LED_BUILTIN is set to the correct LED pin.
This example code is in the public domain.
Adapted from:
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/
// the LED is at pin GPIO8
#define LED_BUILTIN 8
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED on (LOW is the voltage level)
delay(50); // wait 50 ms
digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage HIGH
delay(950); // wait 950 ms
}
The source code folder structure
We need to create an empty folder to store all the files for this project. I chose the folder /home/michiel/development/myproject/
.
michiel@Delphinus:~> cd development/
michiel@Delphinus:~/development> mkdir myproject
michiel@Delphinus:~/development> cd myproject/
michiel@Delphinus:~/development/myproject> mkdir blink
The Arduino IDE requires the .ino
file to be in a folder with the same name as the .ino
file.
Save the above code in a file with the name blink.ino
in a folder named blink
.
We will use the blink
folder instead of the src
folder from a normal PlatformIO project.
The platformio.ini file
Create a new file in the project folder with the name platformio.ini
and the following content:
[platformio]
src_dir = blink
[env:esp32c3_supermini]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
The project folder structure
So, now we have the following files and folders:
michiel@Delphinus:~/development/myproject> tree
.
├── blink
│ └── blink.ino
└── platformio.ini
1 directory, 2 files
michiel@Delphinus:~/development/myproject>
Get PlatformIO
As described in the PlatformIO installation description, we now activate the virtual environment for our project for PlatformIO:
michiel@Delphinus:~/development/myproject> get_pio
(penv) michiel@Delphinus:~/development/myproject>
Compile the code
Platformio installs the necessary libraries and compiles the code with pio run
:
(penv) michiel@Delphinus:~/development/myproject> pio run
Processing esp32c3_supermini (platform: espressif32; board: esp32-c3-devkitm-1; framework: arduino)
-------------------------------------------------------------------------------------------------------
Tool Manager: Installing espressif/toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: toolchain-riscv32-esp@8.4.0+2021r2-patch5 has been installed!
Tool Manager: Installing https://github.com/tasmota/esptool/releases/download/v4.7.0/esptool-4.7.0.zip
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: tool-esptoolpy@1.40700.0 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-c3-devkitm-1.html
PLATFORM: Espressif 32 (2024.1.1) > Espressif ESP32-C3-DevKitM-1
HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flash
...
... <-- I left out many more lines here ...
...
RAM: [ ] 2.0% (used 6536 bytes from 327680 bytes)
Flash: [= ] 8.8% (used 114862 bytes from 1310720 bytes)
Building .pio/build/esp32c3_supermini/firmware.bin
esptool.py v4.7.0
Creating esp32c3 image...
Merged 2 ELF sections
Successfully created esp32c3 image.
=========================== [SUCCESS] Took 41.83 seconds ===========================
(penv) michiel@Delphinus:~/development/myproject>
If there are any serious problems here, you will not see the SUCCESS notification at the end. Fix these problems first.
In fact, since everything went well, we could have skipped the pio run
, and start the upload immediately, as described in the next step.
Connect the ESP32-C3-SuperMini board and program it
Connect the board with a USB cable to your PC and type pio run -t upload
:
(penv) michiel@Delphinus:~/development/myproject> pio run -t upload
Processing esp32c3_supermini (platform: espressif32; board: esp32-c3-devkitm-1; framework: arduino)
...
... <-- I left out many more lines here ...
...
Auto-detected: /dev/ttyACM0
Uploading .pio/build/esp32c3_supermini/firmware.bin
esptool.py v4.7.0
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-C3 (QFN32) (revision v0.4)
Features: WiFi, BLE, Embedded Flash 4MB (XMC)
Crystal is 40MHz
MAC: 64:e8:33:84:1e:dc
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x00002fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00031fff...
Compressed 11360 bytes to 8611...
Writing at 0x00000000... (100 %)
Wrote 11360 bytes (8611 compressed) at 0x00000000 in 0.2 seconds (effective 478.0 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 499.2 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 632.1 kbit/s)...
Hash of data verified.
Compressed 138784 bytes to 79438...
Writing at 0x00010000... (20 %)
Writing at 0x000166ea... (40 %)
Writing at 0x00021954... (60 %)
Writing at 0x000275e4... (80 %)
Writing at 0x0002d1da... (100 %)
Wrote 138784 bytes (79438 compressed) at 0x00010000 in 1.3 seconds (effective 877.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
=========================== [SUCCESS] Took 10.63 seconds ===========================
(penv) michiel@Delphinus:~/development/myproject>
The LED is blinking!
The Blue LED is blinking.