Arduino Coding Practices
Application skill for Arduino library + sketch guides (archived awesome-guidelines capsules). For portable C++ outside Arduino core, load cpp-coding-practices. Professional embedded without Arduino APIs: follow project RTOS/SDK docs.
Core Principle
Arduino quality is beginner-first APIs and compile-ready packaging, camelCase high-level methods, hardware init in begin() not constructors, guarded .h/.cpp pairs, examples that build.
When to Use / NOT
- Arduino libraries (
*.h/*.cpp), sketch .ino, library.properties, Library Manager prep.
- Reviewing public API names, Stream serial ports, Morse-style class layout.
NOT when:
- Generic C++ desktop/server code,
cpp-coding-practices.
- Bare-metal non-Arduino SDK firmware with no Arduino core.
- Python MicroPython/CircuitPython, stack-specific docs.
Workflow
- API, naming, read/write/begin, Stream, no pointer traps (
arduino-style-library-api.md).
- Structure, guards, ctor vs begin,
_private fields (arduino-style-library-structure.md).
- Sketches, setup/loop, camelCase, braces, AVR loop discipline (
arduino-style-sketch-code.md).
- Packaging, keywords, examples, properties, compile (
arduino-style-packaging-verify.md).
- Verify,
arduino-cli compile on example; hardware smoke if available.
Red Flags
pinMode or bus init inside constructor
- snake_case public library methods
- Public API requiring pointer args (
&x, char*) from sketches
- Boolean parameters instead of two named methods
- Hard-coded
Serial only (no Stream&)
- Missing
#include "Arduino.h" or include guard in library header
- Wrong file extensions (
.cpp.txt, library .ino source)
- Missing
begin() when hardware setup required
- No
examples/ sketch or example fails compile
- ALL_CAPS constant walls hurting readability
- Heavy
String allocation in tight loop() on AVR
- Unbraced single-line
if in maintained sketch code
- Publish without
library.properties when targeting Library Manager
Verification
arduino-cli compile on primary example with project FQBN
- Header review: guards,
Arduino.h, public camelCase, private _fields
- Constructor vs
begin() split check
keywords.txt tab-separated spot check
- Optional: compare API to Adafruit high-level wrapper pattern (one call → one user value)
References
awesome-guidelines/references/arduino-style-learning-note.md
awesome-guidelines/references/arduino-style-library-api.md
awesome-guidelines/references/arduino-style-library-structure.md
awesome-guidelines/references/arduino-style-sketch-code.md
awesome-guidelines/references/arduino-style-packaging-verify.md
Related skills
cpp-coding-practices, portable C++ layout and ownership
c-coding-practices, low-level C safety when mixing C drivers
1---2name: arduino-coding-practices3description: Use when authoring or reviewing Arduino libraries/sketches, camelCase read/write/begin API,.h/.cpp structure, setup/loop lifecycle, Stream-aware serial, keywords/examples, and arduino-cli compile verify.4---56# Arduino Coding Practices78Application skill for Arduino library + sketch guides (archived `awesome-guidelines` capsules). For portable C++ outside Arduino core, load `cpp-coding-practices`. Professional embedded without Arduino APIs: follow project RTOS/SDK docs.910## Core Principle1112Arduino quality is **beginner-first APIs and compile-ready packaging**, camelCase high-level methods, hardware init in `begin()` not constructors, guarded `.h`/`.cpp` pairs, examples that build.1314## When to Use / NOT1516- Arduino libraries (`*.h`/`*.cpp`), sketch `.ino`, `library.properties`, Library Manager prep.17- Reviewing public API names, Stream serial ports, Morse-style class layout.1819**NOT when:**2021- Generic C++ desktop/server code, `cpp-coding-practices`.22- Bare-metal non-Arduino SDK firmware with no Arduino core.23- Python MicroPython/CircuitPython, stack-specific docs.2425## Workflow26271. **API**, naming, read/write/begin, Stream, no pointer traps (`arduino-style-library-api.md`).282. **Structure**, guards, ctor vs begin, `_private` fields (`arduino-style-library-structure.md`).293. **Sketches**, setup/loop, camelCase, braces, AVR loop discipline (`arduino-style-sketch-code.md`).304. **Packaging**, keywords, examples, properties, compile (`arduino-style-packaging-verify.md`).315. **Verify**, `arduino-cli compile` on example; hardware smoke if available.3233## Red Flags3435- `pinMode` or bus init inside constructor36- snake_case public library methods37- Public API requiring pointer args (`&x`, `char*`) from sketches38- Boolean parameters instead of two named methods39- Hard-coded `Serial` only (no `Stream&`)40- Missing `#include "Arduino.h"` or include guard in library header41- Wrong file extensions (`.cpp.txt`, library `.ino` source)42- Missing `begin()` when hardware setup required43- No `examples/` sketch or example fails compile44- ALL_CAPS constant walls hurting readability45- Heavy `String` allocation in tight `loop()` on AVR46- Unbraced single-line `if` in maintained sketch code47- Publish without `library.properties` when targeting Library Manager4849## Verification5051- `arduino-cli compile` on primary example with project FQBN52- Header review: guards, `Arduino.h`, public camelCase, private `_fields`53- Constructor vs `begin()` split check54- `keywords.txt` tab-separated spot check55- Optional: compare API to Adafruit high-level wrapper pattern (one call → one user value)565758## References5960- `awesome-guidelines/references/arduino-style-learning-note.md`61- `awesome-guidelines/references/arduino-style-library-api.md`62- `awesome-guidelines/references/arduino-style-library-structure.md`63- `awesome-guidelines/references/arduino-style-sketch-code.md`64- `awesome-guidelines/references/arduino-style-packaging-verify.md`6566## Related skills6768- `cpp-coding-practices`, portable C++ layout and ownership69- `c-coding-practices`, low-level C safety when mixing C drivers