ESP32 and STM32 Microcontrollers
STM32 is a family of microcontrollers based on the ARM Cortex-M processor core. They are produced by STMicroelectronics and are widely used in embedded systems due to their performance, flexibility, and low power consumption.
ESP32 is a series of low-cost, low-power system-on-chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth, produced by Espressif Systems. The ESP32 is popular in IoT applications due to its connectivity features and performance.
ESP32 is a series of low-cost, low-power system-on-chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth, produced by Espressif Systems. The ESP32 is popular in IoT applications due to its connectivity features and performance.
Lab Equipment
Project 1: ESP32
The first project I wanted to work on with the ESP32 was a basic project - to simply prove out the development system ecosystem.
My system included:
Step 1: Install the Arduino IDE and USB to Serial driver on Windows.
Step 2: Plug in the USB-A to the computer and USB-C to the ESP32 device
Step 3: Windows should now recognize the new driver for the USB device - this can be validated via the Windows Device Manager.
My system included:
- Windows 10 Workstation
- Arduino IDE V2.3.4 (https://support.arduino.cc/hc/en-us/articles/360019833020-Download-and-install-Arduino-IDE)
- USB to Serial driver (CP210x_Universal_Windows_Driver.zip) - from www.silabs.com/developer-tools/usb-to-uart-bridge-vcp-drivers?tab=downloads
- USB A to USB-C cable
- ESP32 device (ESP-WROOM-32)
Step 1: Install the Arduino IDE and USB to Serial driver on Windows.
Step 2: Plug in the USB-A to the computer and USB-C to the ESP32 device
Step 3: Windows should now recognize the new driver for the USB device - this can be validated via the Windows Device Manager.
Step 4: Configure the Arduino IDE with the serial port and ESP board that matches the one you are using. Please note this screenshot includes the working program already - to be discussed later.
Step 5: Insert the Sample Code in the IDE:
const int LED_PIN2 = 2;
const int LED_PIN3 = 3;
#define LED_ON HIGH
#define LED_OFF LOW
void setup() {
Serial.begin(115200);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
digitalWrite(LED_PIN2, LED_OFF); // Give the output pins a definite, known state at start up
digitalWrite(LED_PIN3, LED_OFF);
Serial.println("Setup complete");
}
void loop() {
flashEqualOnOffPin2();
flashUnequalOnOffPin3();
}
void flashEqualOnOffPin2() {
uint32_t currentMillis = millis();
static uint32_t lastMillis;
const uint32_t onOffTime = 500; //Duration for LED to be on or off before changing state, in miliseconds
if (currentMillis - lastMillis >= onOffTime) {
lastMillis += onOffTime;
if (digitalRead(LED_PIN2) == LED_ON) {
digitalWrite(LED_PIN2, LED_OFF);
} else {
digitalWrite(LED_PIN2, LED_ON);
}
}
}
void flashUnequalOnOffPin3() {
uint32_t currentMillis = millis();
static uint32_t lastMillis;
const uint32_t onTime = 1750; //Duration for LED to be on, in miliseconds
const uint32_t offTime = 350; //Duration for LED to be off, in miliseconds
if (digitalRead(LED_PIN3) == LED_ON) { // Read the current state of pin 3
if (currentMillis - lastMillis >= onTime) { // Pin 3 is high (LED on), check on time and turn LED off if time has expired
lastMillis += onTime; // Add the value of onTime to lastMillis ready to start the next timing interval
digitalWrite(LED_PIN3, LED_OFF); // Turn LED off
}
} else {
if (currentMillis - lastMillis >= offTime) { // Pin 3 is low (LED off), check off time and turn LED on if time has expired
lastMillis += offTime; // Add the value of offTime to lastMillis ready to start the next timing interval
digitalWrite(LED_PIN3, LED_ON); // Turn LED on
}
}
}
const int LED_PIN2 = 2;
const int LED_PIN3 = 3;
#define LED_ON HIGH
#define LED_OFF LOW
void setup() {
Serial.begin(115200);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
digitalWrite(LED_PIN2, LED_OFF); // Give the output pins a definite, known state at start up
digitalWrite(LED_PIN3, LED_OFF);
Serial.println("Setup complete");
}
void loop() {
flashEqualOnOffPin2();
flashUnequalOnOffPin3();
}
void flashEqualOnOffPin2() {
uint32_t currentMillis = millis();
static uint32_t lastMillis;
const uint32_t onOffTime = 500; //Duration for LED to be on or off before changing state, in miliseconds
if (currentMillis - lastMillis >= onOffTime) {
lastMillis += onOffTime;
if (digitalRead(LED_PIN2) == LED_ON) {
digitalWrite(LED_PIN2, LED_OFF);
} else {
digitalWrite(LED_PIN2, LED_ON);
}
}
}
void flashUnequalOnOffPin3() {
uint32_t currentMillis = millis();
static uint32_t lastMillis;
const uint32_t onTime = 1750; //Duration for LED to be on, in miliseconds
const uint32_t offTime = 350; //Duration for LED to be off, in miliseconds
if (digitalRead(LED_PIN3) == LED_ON) { // Read the current state of pin 3
if (currentMillis - lastMillis >= onTime) { // Pin 3 is high (LED on), check on time and turn LED off if time has expired
lastMillis += onTime; // Add the value of onTime to lastMillis ready to start the next timing interval
digitalWrite(LED_PIN3, LED_OFF); // Turn LED off
}
} else {
if (currentMillis - lastMillis >= offTime) { // Pin 3 is low (LED off), check off time and turn LED on if time has expired
lastMillis += offTime; // Add the value of offTime to lastMillis ready to start the next timing interval
digitalWrite(LED_PIN3, LED_ON); // Turn LED on
}
}
}
Step 6: Upload the code to the ESP device - note you will need to ensure the serial baudrate should correctly (115,200) and you press the boot button for a second or so on the ESP device while the Ardiuno IDE is trying to connect.
Step 7: Monitor the Output as well as the Serial Monitor in the IDE
Sketch uses 296504 bytes (22%) of program storage space. Maximum is 1310720 bytes.
Global variables use 20056 bytes (6%) of dynamic memory, leaving 307624 bytes for local variables. Maximum is 327680 bytes.
esptool.py v4.8.1
Serial port COM3
Connecting..................................
Chip is ESP32-D0WD (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: bc:dd:c2:d0:dc:5c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00007fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00058fff...
Compressed 24976 bytes to 15952...
Writing at 0x00001000... (100 %)
Wrote 24976 bytes (15952 compressed) at 0x00001000 in 0.5 seconds (effective 442.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 177.4 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 506.6 kbit/s)...
Hash of data verified.
Compressed 296608 bytes to 158230...
Writing at 0x00010000... (10 %)
Writing at 0x0001bd71... (20 %)
Writing at 0x00028841... (30 %)
Writing at 0x0002dec3... (40 %)
Writing at 0x00033a07... (50 %)
Writing at 0x00038e83... (60 %)
Writing at 0x0003e477... (70 %)
Writing at 0x00043ba7... (80 %)
Writing at 0x0004b23c... (90 %)
Writing at 0x000547a8... (100 %)
Wrote 296608 bytes (158230 compressed) at 0x00010000 in 3.2 seconds (effective 751.0 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
The simple program is now running - flashing the blue LED once per second.
Step 7: Monitor the Output as well as the Serial Monitor in the IDE
Sketch uses 296504 bytes (22%) of program storage space. Maximum is 1310720 bytes.
Global variables use 20056 bytes (6%) of dynamic memory, leaving 307624 bytes for local variables. Maximum is 327680 bytes.
esptool.py v4.8.1
Serial port COM3
Connecting..................................
Chip is ESP32-D0WD (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: bc:dd:c2:d0:dc:5c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00007fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00058fff...
Compressed 24976 bytes to 15952...
Writing at 0x00001000... (100 %)
Wrote 24976 bytes (15952 compressed) at 0x00001000 in 0.5 seconds (effective 442.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 177.4 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 506.6 kbit/s)...
Hash of data verified.
Compressed 296608 bytes to 158230...
Writing at 0x00010000... (10 %)
Writing at 0x0001bd71... (20 %)
Writing at 0x00028841... (30 %)
Writing at 0x0002dec3... (40 %)
Writing at 0x00033a07... (50 %)
Writing at 0x00038e83... (60 %)
Writing at 0x0003e477... (70 %)
Writing at 0x00043ba7... (80 %)
Writing at 0x0004b23c... (90 %)
Writing at 0x000547a8... (100 %)
Wrote 296608 bytes (158230 compressed) at 0x00010000 in 3.2 seconds (effective 751.0 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
The simple program is now running - flashing the blue LED once per second.

