arduino-code-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Arduino Code Generator

Arduino 代码生成器

Generate production-quality Arduino code snippets for sensors, actuators, communication, and embedded patterns.
生成适用于传感器、执行器、通信及嵌入式设计模式的生产级Arduino代码片段。

Quick Start

快速开始

Browse example sketches:
bash
undefined
浏览示例草图:
bash
undefined

See 9 production-ready examples in examples/ folder

查看examples/目录下的9个可直接用于生产环境的示例

ls examples/
ls examples/

config-example.ino, filtering-example.ino, buttons-example.ino,

config-example.ino, filtering-example.ino, buttons-example.ino,

i2c-example.ino, csv-example.ino, scheduler-example.ino,

i2c-example.ino, csv-example.ino, scheduler-example.ino,

state-machine-example.ino, hardware-detection-example.ino,

state-machine-example.ino, hardware-detection-example.ino,

data-logging-example.ino

data-logging-example.ino


**List available patterns:**
```bash
uv run --no-project scripts/generate_snippet.py --list
Generate code for specific pattern and board:
bash
uv run --no-project scripts/generate_snippet.py --pattern i2c --board esp32
uv run --no-project scripts/generate_snippet.py --pattern buttons --board uno --output button.ino
Interactive mode:
bash
uv run --no-project scripts/generate_snippet.py --interactive

**列出可用设计模式:**
```bash
uv run --no-project scripts/generate_snippet.py --list
为特定设计模式和开发板生成代码:
bash
uv run --no-project scripts/generate_snippet.py --pattern i2c --board esp32
uv run --no-project scripts/generate_snippet.py --pattern buttons --board uno --output button.ino
交互模式:
bash
uv run --no-project scripts/generate_snippet.py --interactive

Resources

资源

  • examples/ - 9 production-ready example sketches (one per pattern category)
  • examples/README.md - Detailed documentation for each example with wiring diagrams
  • scripts/generate_snippet.py - CLI tool for code generation with 9 pattern templates
  • scripts/verify_patterns.ps1 - Compile examples for UNO/ESP32/RP2040 (PowerShell)
  • scripts/verify_patterns.sh - Compile examples for UNO/ESP32/RP2040 (bash)
  • assets/workflow.mmd - Mermaid diagram of code generation workflow
  • examples/ - 9个可直接用于生产环境的示例草图(每个设计模式类别对应一个)
  • examples/README.md - 每个示例的详细文档,包含接线图
  • scripts/generate_snippet.py - 用于代码生成的CLI工具,包含9种设计模式模板
  • scripts/verify_patterns.ps1 - 为UNO/ESP32/RP2040编译示例(PowerShell脚本)
  • scripts/verify_patterns.sh - 为UNO/ESP32/RP2040编译示例(bash脚本)
  • assets/workflow.mmd - 代码生成工作流的Mermaid图

Supported Patterns

支持的设计模式

Hardware Abstraction

硬件抽象

  • Multi-board config.h with conditional compilation
  • Pin definitions for UNO/ESP32/RP2040
  • Memory budget tracking
See patterns-config.md | Example: config-example.ino
  • 支持多开发板的config.h,带条件编译
  • UNO/ESP32/RP2040的引脚定义
  • 内存预算跟踪
查看 patterns-config.md | 示例:config-example.ino

Sensor Reading & Filtering

传感器读取与过滤

  • ADC noise reduction (moving average, median, Kalman)
  • DHT22, BME280, analog sensors
  • Data validation and calibration
See patterns-filtering.md | Example: filtering-example.ino
  • ADC降噪(移动平均、中位数、卡尔曼滤波)
  • DHT22、BME280、模拟传感器
  • 数据验证与校准
查看 patterns-filtering.md | 示例:filtering-example.ino

Input Handling

输入处理

  • Software button debouncing
  • Edge detection (PRESSED/RELEASED/LONG_PRESS)
  • Multi-button management
See patterns-buttons.md | Example: buttons-example.ino
  • 软件按键消抖
  • 边缘检测(按下/释放/长按)
  • 多按键管理
查看 patterns-buttons.md | 示例:buttons-example.ino

Communication

通信

  • I2C device scanning and diagnostics
  • SPI configuration
  • UART/Serial protocols
  • CSV data output
See patterns-i2c.md and patterns-csv.md | Examples: i2c-example.ino, csv-example.ino
  • I2C设备扫描与诊断
  • SPI配置
  • UART/Serial协议
  • CSV数据输出
查看 patterns-i2c.mdpatterns-csv.md | 示例:i2c-example.ino, csv-example.ino

Timing & Concurrency

时序与并发

  • Non-blocking millis() patterns
  • Task scheduling without delay()
  • Priority-based schedulers
  • State machines
See patterns-scheduler.md and patterns-state-machine.md | Examples: scheduler-example.ino, state-machine-example.ino
  • 非阻塞millis()模式
  • 无需delay()的任务调度
  • 基于优先级的调度器
  • 状态机
查看 patterns-scheduler.mdpatterns-state-machine.md | 示例:scheduler-example.ino, state-machine-example.ino

Hardware Detection

硬件检测

  • Auto-detect boards (UNO/ESP32/RP2040)
  • SRAM usage monitoring
  • Sensor fallback strategies
  • Adaptive configuration
See patterns-hardware-detection.md | Example: hardware-detection-example.ino
  • 自动检测开发板(UNO/ESP32/RP2040)
  • SRAM使用监控
  • 传感器 fallback 策略
  • 自适应配置
查看 patterns-hardware-detection.md | 示例:hardware-detection-example.ino

Data Persistence

数据持久化

  • EEPROM with CRC validation
  • SD card FAT32 logging
  • Wear leveling for EEPROM
  • Buffered writes
See patterns-data-logging.md | Example: data-logging-example.ino
  • 带CRC校验的EEPROM
  • SD卡FAT32日志记录
  • EEPROM损耗均衡
  • 缓冲写入
查看 patterns-data-logging.md | 示例:data-logging-example.ino

Code Generation Workflow

代码生成工作流

  • Identify Pattern Type - Analyze user request to determine core pattern category
  • Read Reference Documentation - Consult pattern-specific reference files for implementation details
  • Generate Code - Create production-ready code following quality standards
  • Provide Instructions - Include wiring diagrams and usage guidance
  • Mention Integration - Suggest combinations with other patterns when relevant
  • 识别设计模式类型 - 分析用户需求,确定核心设计模式类别
  • 查阅参考文档 - 参考特定设计模式的文档获取实现细节
  • 生成代码 - 遵循质量标准生成可用于生产环境的代码
  • 提供使用说明 - 包含接线图和使用指南
  • 提及集成方案 - 相关时建议与其他设计模式的组合方式

Quality Standards & Rules

质量标准与规则

  • Quality Standards - Compilation, timing, memory safety, and error handling requirements
  • Board Optimization - UNO, ESP32, and RP2040 specific optimizations and features
  • Common Pitfalls - Critical mistakes to avoid in Arduino development
  • 质量标准 - 编译、时序、内存安全及错误处理要求
  • 开发板优化 - 针对UNO、ESP32和RP2040的特定优化与特性
  • 常见陷阱 - Arduino开发中需避免的关键错误

Code Output Template

代码输出模板

  • Code Template - Standardized structure for generated Arduino sketches
  • 代码模板 - 标准化的Arduino草图结构

Resources

资源

  • examples/ - 9 production-ready example sketches (one per pattern category)
  • examples/README.md - Detailed documentation for each example with wiring diagrams
  • scripts/generate_snippet.py - CLI tool for code generation with 9 pattern templates
  • assets/workflow.mmd - Mermaid diagram of code generation workflow
  • workflow/ - Step-by-step code generation process
  • rules/ - Quality standards and board-specific optimizations
  • templates/ - Code output templates and structure guidelines
  • references/ - Detailed pattern documentation and API references
  • references/README.md - Reference structure and formatting guide
  • examples/ - 9个可直接用于生产环境的示例草图(每个设计模式类别对应一个)
  • examples/README.md - 每个示例的详细文档,包含接线图
  • scripts/generate_snippet.py - 用于代码生成的CLI工具,包含9种设计模式模板
  • assets/workflow.mmd - 代码生成工作流的Mermaid图
  • workflow/ - 代码生成的分步流程文档
  • rules/ - 质量标准与开发板特定优化规则
  • templates/ - 代码输出模板与结构指南
  • references/ - 详细的设计模式文档与API参考
  • references/README.md - 参考文档的结构与格式指南