matlab-create-custom-arduino-library

Create custom Arduino add-on libraries bridging MATLAB with unsupported sensors and peripherals.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-create-custom-arduino-library
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: matlab-create-custom-arduino-library
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/test-and-measurement/matlab-create-custom-arduino-library
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-create-custom-arduino-library

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

MATLAB's Support Package for Arduino Hardware natively supports only a fixed set of peripherals, so reading sensors like DHT22 or driving OLED displays from MATLAB requires building a custom Arduino add-on library that bridges MATLAB and Arduino C++ code.

Core Features & Use Cases

  • Custom Add-On Scaffolding: Generates the +arduinoioaddons package structure, MATLAB class, and C++ header using arduinoio.customLibrary.createLibraryTemplate or manual fallback for older releases.
  • Third-Party Library Integration: Installs and wraps existing Arduino C++ libraries (e.g., DHT22, U8g2) via arduinoio.customLibrary.downloadLibrary with correct LibraryHeaderFiles and DependentLibraries configuration.
  • Hardware Conflict Prevention: Enforces rules for I2C/SPI bus ownership, lazy hardware initialization, and safe sendResponseMsg usage to avoid server handshake failures and ARM board crashes.
  • Use Case: A user asks "How do I read humidity in MATLAB from a DHT22 sensor?" The Skill checks native support, installs the DHT library, scaffolds the add-on, and produces working MATLAB and C++ code verified with listArduinoLibraries.

Quick Start

Ask the agent to create a custom Arduino library in MATLAB for your unsupported sensor, providing the library name, the third-party Arduino library to wrap, and the target output directory.

Frequently Asked Questions about matlab-create-custom-arduino-library

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use an unsupported Arduino sensor from MATLAB?▼

Create a custom Arduino add-on library that wraps the sensor's Arduino C++ library using the LibraryBase class. First run listArduinoLibraries to confirm the peripheral is not natively supported, then scaffold the add-on with arduinoio.customLibrary.createLibraryTemplate.

How do I wrap a third-party Arduino library for MATLAB?▼

Install the library with arduinoio.customLibrary.downloadLibrary, then reference it in the MATLAB class via LibraryHeaderFiles using the format 'LibraryFolder/header.h'. Write a C++ header extending LibraryBase with a commandHandler that calls the library's functions.

Why does my Arduino add-on fail with 'initialization of the server code is incorrect'?▼

This error occurs when setup() calls hardware initialization like .begin() or Wire.begin(), conflicting with the MATLAB server boot sequence. Move hardware initialization into a dedicated INIT command triggered from the MATLAB constructor instead.

Can I use Wire.h or hardware I2C in a MATLAB Arduino add-on?▼

No, your add-on header must never include Wire.h because MATLAB owns the hardware I2C bus. Use software I2C constructors like U8G2 SW_I2C variants, or set DependentLibraries to {'I2C'} so MATLAB manages the bus.

When should I not create a custom Arduino library for MATLAB?▼

Skip custom library creation when the peripheral is already listed by listArduinoLibraries, when a MathWorks-authored File Exchange add-on exists, or when you need standalone Arduino deployment or Simulink workflows instead of a live MATLAB connection.