Skip to main content

On This Page

Building a Modular Starter Kit for M5StickC-Plus2: From Messy Code to Clean Architecture

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Why Another M5Stack Project?

A developer sought to streamline M5StickC-Plus2 project setup, frustrated by the extensive boilerplate code required for basic functionality. The resulting starter kit prioritizes ownership of all code, avoiding the limitations of pre-built libraries and offering full customization options.

This project addresses the gap between ideal software development – modularity, control, and clarity – and the reality of quickly accumulating messy, hard-to-maintain code in embedded systems. Failure to address architectural concerns early can lead to significant rework and increased development time, especially as projects grow in complexity.

Key Insights

  • PlatformIO vs Arduino IDE, 2024: Switching to PlatformIO with VSCode improves IntelliSense, project structure, and C++ support.
  • Page System via Lifecycle Management: Implementing a PageBase class with setup(), loop(), and cleanup() methods provides structured page management.
  • Menu Stack with LIFO: Utilizing a stack data structure simplifies the implementation of nested menus and back navigation.

Working Example

// ✅ New way (C++)
struct MenuItem {
std::function<void()> callback; // Can capture anything!
};

// Example usage
mainMenu->addItem("Settings", [this]() {
openSettingsSubmenu(); // 'this' captured, works perfectly
});

Practical Applications

  • IoT Sensor Node: A customized starter kit could quickly be adapted for a remote sensor, managing data display and communication.
  • Pitfall: Over-reliance on pre-built libraries can lead to vendor lock-in and difficulty in debugging or extending functionality.

References:

Continue reading

Next article

AWS RDS: A Fully Managed Database Service for Scalable Applications

Related Content