Top Open‑Source MCU Libraries and Projects for Embedded Development
This article curates a collection of popular open‑source microcontroller projects, covering practical software modules such as MultiButton, QueueForMcu, and StateMachine, complete hardware projects like TinyGameEngine and HomeAutomation, IoT platforms, creative gadgets, and debugging tools, each with repository links, feature highlights, usage examples, and code snippets.
Practical Software Modules
MultiButton – Multi‑key handling library
Project URL: https://github.com/0x1abin/MultiButton
Key Features :
// Supports multiple key events
Press event types:
├── Click: PRESS_DOWN, PRESS_UP
├── Long press: LONG_PRESS_START, LONG_PRESS_HOLD
├── Repeat: PRESS_REPEAT (continuous press)
├── Combination: detection of multiple keys pressed together
└── State: duration of key pressUsage Example :
#include "multi_button.h"
struct Button btn1, btn2;
// Callback for key events
void btn1_callback(void *btn) {
struct Button *handle = (struct Button *)btn;
switch (handle->event) {
case PRESS_DOWN:
printf("Button1 press down
");
break;
case PRESS_UP:
printf("Button1 press up
");
break;
case LONG_PRESS_START:
printf("Button1 long press start
");
break;
case LONG_PRESS_HOLD:
printf("Button1 long press hold
");
break;
}
}
void setup() {
button_init(&btn1, read_button1_GPIO, 0);
button_attach(&btn1, PRESS_DOWN, btn1_callback);
button_attach(&btn1, PRESS_UP, btn1_callback);
button_attach(&btn1, LONG_PRESS_START, btn1_callback);
button_start(&btn1);
}
void main_loop() {
// Call every 5 ms
button_ticks();
}QueueForMcu – MCU queue library
Project URL: https://github.com/xiaoxinpro/QueueForMcu
Highlights :
// Designed for microcontrollers
Core features:
├── Platform compatible: 8/16/32‑bit MCUs
├── Memory efficient: minimal RAM/ROM usage
├── Simple API: enqueue, dequeue, query
├── Thread‑safe: usable in interrupt context
└── State monitoring: full/empty detectionCode Example :
#include "queue.h"
#define QUEUE_SIZE 32
uint8_t queue_buffer[QUEUE_SIZE];
Queue_t my_queue;
void setup() {
// Initialise queue
Queue_Init(&my_queue, queue_buffer, QUEUE_SIZE);
}
void uart_rx_handler(uint8_t data) {
// Safe enqueue from ISR
if (!Queue_IsFull(&my_queue)) {
Queue_Put(&my_queue, data);
}
}
void main_loop() {
uint8_t data;
// Process queued data
while (!Queue_IsEmpty(&my_queue)) {
if (Queue_Get(&my_queue, &data)) {
process_received_data(data);
}
}
}Typical Application Scenarios :
Serial data buffer : store variable‑length packets.
Key‑event queue : cache button events.
Sensor data : queue multiple sensor readings.
Communication protocol : buffer and parse CAN/UART frames.
StateMachine – UML‑compliant state‑machine framework
Project URL: https://github.com/kiishor/UML-State-Machine-in-C
Core Features :
// UML standard state‑machine implementation
Features:
├── Standard compliance: follows UML state‑chart rules
├── Hierarchical states: nested state structures
├── Event‑driven: transitions triggered by events
├── Safe & reliable: atomic state changes
└── Debug‑friendly: logs transitionsExample – Smart Door Lock :
// Enumerations for states and events
typedef enum {
STATE_LOCKED,
STATE_UNLOCKING,
STATE_UNLOCKED,
STATE_LOCKING,
STATE_ALARM
} door_state_t;
typedef enum {
EVENT_PASSWORD_CORRECT,
EVENT_PASSWORD_WRONG,
EVENT_TIMEOUT,
EVENT_MANUAL_LOCK,
EVENT_INTRUSION_DETECTED
} door_event_t;
// Transition table (partial)
const state_transition_t door_transitions[] = {
{STATE_LOCKED, EVENT_PASSWORD_CORRECT, STATE_UNLOCKING},
{STATE_LOCKED, EVENT_PASSWORD_WRONG, STATE_ALARM},
{STATE_UNLOCKING, EVENT_TIMEOUT, STATE_UNLOCKED},
{STATE_UNLOCKED, EVENT_MANUAL_LOCK, STATE_LOCKING},
{STATE_UNLOCKED, EVENT_TIMEOUT, STATE_LOCKING},
// ... more rules
};Complete Projects
TinyGameEngine – STM32 game development framework
Project URL: https://github.com/juj/fbcp-ili9341
Features :
// STM32‑based game engine
Engine capabilities:
├── Pixel‑level graphics rendering
├── PWM audio output
├── Input handling: buttons, joystick
├── 2D collision detection
├── Scene management: state switching
└── Save system: EEPROM data storageClassic games implemented :
Snake – classic puzzle game.
Tetris – block‑clearing game.
Breakout – ball‑bounce arcade.
Space Shooter – side‑scrolling shooter.
HomeAutomation – Smart home system
Project URL: https://github.com/home-assistant/core
System Architecture :
// Distributed smart‑home architecture
Components:
├── Central controller: ESP32 main board
├── Sensor network: temperature, humidity, light, smoke
├── Actuators: relays, servos, LEDs
├── Communication: Wi‑Fi, Bluetooth, Zigbee
├── Web UI: real‑time monitoring & control
└── Data logging: sensor data storageCore device abstraction (excerpt):
typedef struct {
uint8_t device_id;
device_type_t type;
device_status_t status;
int (*init)(void *device);
int (*read)(void *device, void *data);
int (*write)(void *device, void *data);
int (*control)(void *device, uint8_t cmd, void *param);
} smart_device_t;CanBus‑Triple – CAN‑bus analyzer
Project URL: https://github.com/CANBus-Triple/CANBus-Triple
Features :
// Professional CAN‑bus tool
Core functions:
├── Data listening: real‑time CAN frame capture
├── Data transmission: custom CAN frame send
├── Protocol analysis: common CAN protocols parsing
├── Data logging: record and replay CAN traffic
├── Remote control: Wi‑Fi based operation
└── Filtering: ID filter and data selectionApplication domains :
Automotive diagnostics – OBD‑II analysis.
Industrial control – CANopen network debugging.
Device development – testing CAN peripherals.
Reverse engineering – unknown CAN protocol analysis.
IoT Projects
ESP32‑IoT‑Platform – Full‑stack IoT solution
Project URL: https://github.com/espressif/esp-idf
Platform Features :
// Complete IoT stack
Technology stack:
├── Hardware: ESP32 / ESP8266
├── Connectivity: Wi‑Fi, Bluetooth, LoRa
├── Cloud services: MQTT, HTTP, CoAP
├── Mobile apps: Android / iOS
├── Web management UI
└── Data analytics: real‑time visualizationTypical application – environmental monitoring station :
typedef struct {
float temperature;
float humidity;
uint16_t pm25;
uint16_t co2;
uint8_t light_level;
uint32_t timestamp;
} env_data_t;
void sensor_task(void *pvParameters) {
env_data_t data;
while (1) {
data.temperature = read_temperature();
data.humidity = read_humidity();
data.pm25 = read_pm25();
data.co2 = read_co2();
data.light_level = read_light();
data.timestamp = get_timestamp();
mqtt_publish("sensor/env", &data, sizeof(data));
vTaskDelay(pdMS_TO_TICKS(60000)); // 1‑minute interval
}
}PowerManagement – Low‑power management for ESP32
Project URL: https://github.com/espressif/esp-idf/tree/master/examples/system/deep_sleep
Power‑saving techniques :
// Smart power‑management system
Strategies:
├── Deep sleep: lowest power mode
├── Timed wake‑up: RTC timer
├── Event wake‑up: external interrupt
├── Dynamic frequency scaling
├── Peripheral control: on‑demand enable
└── Power monitoring: real‑time measurementExample – entering deep‑sleep mode :
#include "esp_sleep.h"
#include "esp_wifi.h"
void enter_power_save_mode(uint32_t sleep_time_ms) {
// Stop Wi‑Fi and unused peripherals
esp_wifi_stop();
disable_unused_peripherals();
// Configure wake‑up sources
esp_sleep_enable_timer_wakeup(sleep_time_ms * 1000);
esp_sleep_enable_ext1_wakeup(GPIO_SEL_0, ESP_EXT1_WAKEUP_ANY_HIGH);
// Enter deep sleep
esp_deep_sleep_start();
}
void handle_wakeup() {
esp_sleep_wakeup_cause_t reason = esp_sleep_get_wakeup_cause();
switch (reason) {
case ESP_SLEEP_WAKEUP_TIMER:
printf("Timer wake‑up, collect sensor data
");
collect_sensor_data();
break;
case ESP_SLEEP_WAKEUP_EXT1:
printf("External interrupt wake‑up, handle user input
");
handle_user_input();
break;
}
}Creative Projects
MusicBox – MCU‑based music player
Project URL: https://github.com/TheRemote/PicoMusicBox
Features :
// Music playback on a microcontroller
Features:
├── PWM audio output
├── SD‑card file system for music files
├── Volume & pitch control
├── OLED display for song info
├── Button‑based user interaction
└── DAC high‑quality audio outputSmartClock – Multifunctional smart clock
Project URL: https://github.com/witnessmenow/ESP32-Trinity
Core Functions :
// Feature‑rich smart clock
Modules:
├── Time display with NTP sync
├── Environment monitoring (temp/humidity)
├── Calendar reminders
├── Weather forecast via online API
├── Music alarm with custom tones
├── RGB ambience lighting
└── Remote control via mobile appDebugging Tools
SerialPlotter – Serial waveform visualizer
Project URL: https://github.com/devinaconley/arduino-plotter
Tool Highlights :
// Real‑time data visualization
Display features:
├── Multi‑channel waveform view
├── Numeric readout
├── Color coding per channel
├── Time‑axis zoom
├── Data export
└── Trigger‑based captureSupported data format (example):
void send_plot_data() {
static uint32_t timestamp = 0;
// Format: timestamp:ch1:ch2:ch3
printf("%lu:%.2f:%.2f:%.2f
", timestamp++,
read_adc_channel(0) * 3.3f / 4095.0f,
read_adc_channel(1) * 3.3f / 4095.0f,
read_temperature());
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
