matlab/matlab-agentic-toolkit / skills-catalog/test-and-measurement/matlab-create-custom-arduino-library
matlab-create-custom-arduino-library
VerifiedUse when the user wants to use Arduino sensors or peripherals from MATLAB that are not directly supported by the MATLAB Support Package for Arduino Hardware. Triggers on requests to create, wrap, or expose a custom Arduino library to MATLAB. Also triggers on indirect questions like "How do I read humidity in MATLAB?" or "How do I display text on an LCD from MATLAB?" where the answer requires a custom Arduino add-on library. Covers: custom addon creation, third-party Arduino library integration, LibraryBase class, C++ header files, DependentLibraries, arduinoioaddons namespace, I2C/SPI/GPIO peripheral wrappers.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 13.3 KB |
| manifest.yaml | config | 476 B |
| references/bus-conflicts.md | markdown | 3.0 KB |
| references/common-errors.md | markdown | 3.3 KB |
| references/cpp-patterns.md | markdown | 4.9 KB |
references/common-errors.md
View on GitHub# Common Errors and Fixes
## "The Arduino source '<header>' cannot be found"
**Cause:** `LibraryHeaderFiles` format is wrong in the MATLAB .m file.
**Fix:** Use `'<LibraryFolderName>/<HeaderFileName.h>'`:
- The folder name must match the folder under `arduinoio.CLIRoot/user/libraries/`
- Use just the header filename — NOT a full path with subdirectories
- The Arduino resolver searches `src/` automatically
```matlab
% GOOD
LibraryHeaderFiles = {'U8g2/U8g2lib.h'}
LibraryHeaderFiles = {'DHT22/DHT22.h'}
LibraryHeaderFiles = {'Adafruit_Motor_Shield_V2_Library/Adafruit_MotorShield.h'}
% BAD — subdirectory path
LibraryHeaderFiles = {'U8g2/src/U8g2lib.h'}
% BAD — just the filename without library folder
LibraryHeaderFiles = {'U8g2lib.h'}
```
## "Failed to add library '<Name>'. The library is dependent on the unavailable library '<X>'"
**Cause:** `DependentLibraries` contains a name that is NOT in `listArduinoLibraries`.
**Fix:** `DependentLibraries` must only contain names from `listArduinoLibraries`.
Common valid values: `'I2C'`, `'SPI'`, `'Serial'`, `'Servo'`.
Common wrong values: `'Wire'`, `'SPI.h'`, `'Adafruit_NeoPixel'`.
```matlab
% GOOD
DependentLibraries = {}
DependentLibraries = {'I2C'}
DependentLibraries = {'Servo', 'I2C'}
% BAD — Arduino library names, not MATLAB addon names
DependentLibraries = {'Wire'}
DependentLibraries = {'SPI.h'}
```
## "Internal error: The initialization of the server code is incorrect"
**Cause:** Hardware initialization (`.begin()`, `Wire.begin()`, `SPI.begin()`) in
`setup()` conflicts with the server boot sequence.
**Fix:** Move hardware init out of `setup()` into a command handler triggered from
the MATLAB constructor. Simple variable assignments in `setup()` are safe.
See `cpp-patterns.md` for the lazy initialization pattern.
## "Unable to receive data from the target hardware"
**Cause:** The command handler or hardware init blocks serial communication.
Most common: `Wire.begin()` / hardware I2C init conflicts with MATLAB server.
**Fix:** Switch to software I2C constructors, or ensure your addon uses
`DependentLibraries = {'I2C'}` and never calls `Wire.begin()` directly.
See `bus-conflicts.md` for which buses are safe.
## Library not appearing in listArduinoLibraries
**Cause:** The parent folder containing `+arduinoioaddons` is not on the MATLAB path.
**Fix:**
```matlab
addpath('<folder containing +arduinoioaddons>');
savepath;
listArduinoLibraries % verify
```
If using `createLibraryTemplate` (R2025a+), the path is added automatically.
## Nested +arduinoioaddons directory after createLibraryTemplate
**Cause:** Running `createLibraryTemplate` when the current directory already contains
`+arduinoioaddons` creates a nested structure.
**Fix:** After running, check the output path. If nested, move the inner
`+<FolderName>` up to the correct level:
```
<targetDir>/+arduinoioaddons/+<FolderName>/<ClassName>.m
<targetDir>/+arduinoioaddons/+<FolderName>/src/<HeaderName>.h
```
## Compilation error: "No such file or directory" for #include
**Cause:** Using quoted relative path in C++ code like `#include "LibraryName/src/header.h"`
**Fix:** Use angle brackets with just the header name: `#include <U8g2lib.h>`.
The Arduino build system resolves the path automatically via the `LibraryHeaderFiles`
property in the MATLAB .m file.
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |