This week is focused on Embedded Programming. The goal was to study microcontroller architectures by reading a datasheet, compare multiple programming languages and toolchains (Arduino IDE C++ and Thonny MicroPython), and program a microcontroller board to interface with sensors and actuators. I read the datasheet of the Espressif ESP32-C3, programmed a go-kart throttle-and-LED dashboard controller using C++ and Python, and documented my development workflows.
The group assignment was to compare the performance, memory footprint, and development workflows of various microcontroller architectures in our lab. The complete group research can be found on the Fablab Dilijan Group Assignment Page.
| Feature | Arduino Uno (ATmega328P) | Seeed Xiao ESP32-C3 | Raspberry Pi Pico (RP2040) |
|---|---|---|---|
| CPU Core | 8-bit AVR | 32-bit RISC-V (single core) | 32-bit ARM Cortex-M0+ (dual core) |
| Clock Speed | 16 MHz | Up to 160 MHz | Up to 133 MHz |
| SRAM | 2 KB | 400 KB | 264 KB |
| Flash Memory | 32 KB | 4 MB (External) | 2 MB (External) |
| Connectivity | None (Requires shields) | Wi-Fi 2.4GHz & BLE 5.0 | None (RP2040 W adds Wi-Fi) |
| Logic Level | 5.0 V | 3.3 V | 3.3 V |
For my individual board, I am using the ESP32-C3 microcontroller. I read the datasheet to understand its power consumption, pinouts, and register configurations:
130 mA during active RF transmission, 5 mA in light sleep, and just 13 μA in deep sleep. This is crucial for optimizing battery life on the Go-Kart dashboard.I programmed my development board using two separate environments and languages: Arduino C++ (compiled toolchain) and MicroPython (interpreted execution). The logic performs a Go-Kart throttle threshold alarm: it reads an analog throttle pedal input, checks if it exceeds 80%, and triggers a warning LED indicator.
The Arduino IDE compiles the C++ code into a binary file that is flashed directly to the ESP32-C3 memory. This provides maximum speed and low overhead.
// Arduino C++ Code - Throttle Status Indicator
const int THROTTLE_PIN = 2; // Analog input pin connected to throttle potentiometer
const int LED_PIN = 3; // Digital output pin connected to LED
const int THRESHOLD = 3276; // 80% of 12-bit ADC (4095 * 0.8)
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
analogReadResolution(12); // Configure ADC to 12-bit resolution
}
void loop() {
int throttleValue = analogRead(THROTTLE_PIN);
float percentage = (throttleValue / 4095.0) * 100.0;
Serial.print("Throttle: ");
Serial.print(percentage);
Serial.println("%");
if (throttleValue > THRESHOLD) {
digitalWrite(LED_PIN, HIGH); // Alarm LED ON
} else {
digitalWrite(LED_PIN, LOW); // Alarm LED OFF
}
delay(100);
}
Using Thonny IDE, I flashed the MicroPython interpreter firmware onto the board. I then wrote an equivalent control script in Python, which is interpreted line-by-line by the MCU.
# MicroPython Code - Throttle Status Indicator
from machine import Pin, ADC
import time
# Configure ADC on Pin 2 with 11dB attenuation (0 - 3.6V range)
throttle_pin = ADC(Pin(2))
throttle_pin.atten(ADC.ATTN_11DB)
# Configure output LED on Pin 3
led_pin = Pin(3, Pin.OUT)
THRESHOLD = 52428 # 80% of 16-bit range (65535 * 0.8)
while True:
raw_val = throttle_pin.read_u16() # Reads a 16-bit value (0-65535)
percentage = (raw_val / 65535.0) * 100
print("Throttle Input: {:.1f}%".format(percentage))
if raw_val > THRESHOLD:
led_pin.value(1) # Turn LED On
else:
led_pin.value(0) # Turn LED Off
time.sleep(0.1)
Download the source code files created for the embedded programming workflows this week:
| File Name | Format | Description | Download Link |
|---|---|---|---|
| throttle_alarm.ino | Arduino Source (.ino) | Arduino C++ script to read throttle ADC and trigger alert LED. | 📥 Download INO |
| main.py | Python Script (.py) | MicroPython script to read throttle ADC and print to shell. | 📥 Download PY |
This week helped me establish the MCU firmware code pipeline. Here is a summary of the outcomes:
Studied the Espressif ESP32-C3 datasheet to map memory structures, power modes, and ADC pins.
Wrote and debugged C++ scripts in Arduino IDE to establish low-level interrupt-driven threshold logic.
Flashed MicroPython firmware and ran scripts directly from Thonny's REPL shell to test ADC scaling.
Designed a threshold-based indicator system representing speed safety alarms for the final kart dashboard.