本文へ移動
cccskills
無料GitHub で公開

matlab-connect-arduino

Discover, configure, and connect to Arduino boards from MATLAB using the Arduino Support Package. Use this skill when the user wants to set up an Arduino board, connect to Arduino hardware, find connected boards, scan serial ports, configure Arduino libraries, or any task that requires an Arduino connection as a prerequisite (e.g., blink LED, read sensor, read digital pin, read analog pin, write pin, plot sensor data, scan I2C, use ultrasonic sensor, control servo, read temperature, read voltage, data logging from hardware). Triggers on: arduino, board setup, COM port, serial port, hardware connection, Arduino Nano, Arduino Uno, Arduino Mega, Arduino Micro, Grove, sensor setup, I2C scan, ultrasonic, servo, readDigitalPin, writeDigitalPin, readVoltage, writePWMVoltage, temperature sensor, air pressure, pin read, pin write, analog input.

インストール方法を見る

含まれるファイル(2)

  • SKILL.md11.2 KB
  • manifest.yaml450 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Set Up Arduino Board in MATLAB

Guides the agent through discovering, configuring, and connecting to Arduino boards via USB, ensuring the user is informed and in control at each step.

When to Use

  • User wants to connect to an Arduino board from MATLAB
  • User asks to discover or list connected Arduino boards
  • User's task requires an Arduino connection as a prerequisite (reading sensors, controlling actuators, scanning I2C, etc.)
  • User mentions Arduino, COM port, serial port, or hardware setup

When NOT to Use

  • Creating custom addon libraries for unsupported peripherals (see matlab-create-custom-arduino-library)
  • Bluetooth or WiFi Arduino connections (not covered here)
  • Arduino IDE or support package installation issues
  • Simulink hardware-in-the-loop workflows
  • Tasks that already have an active arduino object in the workspace

Workflow

Follow these steps in order. Do not skip steps or guess values.

Core principle: Never assume. Always ask the user before proceeding if any information is unclear or ambiguous.

Step 1: Discover boards

Always run both commands — do not skip serialportlist even if arduinolist already found the board. This is a hard requirement:

list = arduinolist
ports = serialportlist("available")

Both calls are mandatory. Never omit serialportlist — arduinolist alone misses boards without support package firmware.

arduinolist returns a table with Port, Board, Status, and Libraries columns. However, it cannot list all connected boards as of R2026a — it may only show one even when multiple are connected. Always also run serialportlist("available") to catch all available ports.

If arduinolist is not available (pre-R2024a), skip it and rely on serialportlist("available") alone.

Present both results to the user.

Step 1b: Handle "no board detected"

If arduinolist returns an empty table AND serialportlist("available") shows no obvious Arduino ports (or all connection attempts fail), do not brute-force all ports. Instead:

  1. Ask immediately: "No Arduino board was detected. Is the board physically connected via USB?"
  2. Guide to OS tools: Present the appropriate guidance to the user based on their operating system:
    • Windows: "Open Device Manager → Ports (COM & LPT). Do you see a device labeled 'Arduino' or 'USB-SERIAL CH340' / 'USB Serial Device'? If not, the board may not be connected or needs a driver."
    • macOS: "Run ls /dev/cu.usb* in a terminal. Arduino boards typically appear as /dev/cu.usbmodem* or /dev/cu.usbserial*."
    • Linux: "Run dmesg | tail -20 after plugging in the board. Look for /dev/ttyACM* or /dev/ttyUSB*."
  3. Suggest common fixes:
    • Try a different USB cable (some are charge-only, no data)
    • Try a different USB port
    • Install the board's USB driver (CH340 for clones, FTDI for others)
    • Ensure no other application (Arduino IDE Serial Monitor, PuTTY) holds the port open
    • If the board was manually disconnected without clearing the arduino object, restart MATLAB and reconnect
    • For detailed troubleshooting, refer the user to: https://www.mathworks.com/help/matlab/supportpkg/arduino-connection-failure.html
  4. STOP and wait. Do not proceed to Step 2 or beyond until the user responds. If the user confirms the board is not connected, continue troubleshooting here. If connected, return to Step 1 and re-run discovery.

Step 2: Help user identify ports

Serial port names alone do not tell the user what device is connected. Guide the user to identify which ports are Arduino boards:

  • Windows: "Check Device Manager (Ports section) to see which COM ports correspond to Arduino boards."
  • macOS: "Look for /dev/cu.usbmodem* or /dev/cu.usbserial* entries — these are typically Arduino boards."
  • Linux: "Check dmesg | grep tty or look for /dev/ttyACM* and /dev/ttyUSB* devices."

Step 3: Ask the user to select board

Present the discovered boards/ports and ask the user which to connect to. Never auto-select a board.

Ask for:

  1. Port (required) — which COM port / device path
  2. Board type (optional) — if the user doesn't know, use arduino('<port>') which auto-detects the board type

For multi-board scenarios, ask the user to identify each board by port and its intended role.

Step 4: Determine libraries

The default libraries are {'I2C', 'SPI', 'Servo'} — MATLAB loads these automatically if no Libraries argument is specified.

Library strategy:

  1. Start with the defaults: {'I2C', 'SPI', 'Servo'}
  2. Infer additional libraries from the user's prompt using this mapping:
User mentionsAdd library
ultrasonic, distance sensor, HC-SR04'Ultrasonic'
shift register, 74HC595'ShiftRegister'
rotary encoder, quadrature'RotaryEncoder'
motor shield, Adafruit motor'Adafruit/MotorShieldV2'
motor carrier, MKR motor'MotorCarrier'
CAN bus'CAN'
serial device, UART'Serial'
APDS9960, gesture, color sensor'APDS9960'

Only infer from the table above when the match is explicit and unambiguous. If uncertain, ask the user rather than guessing libraries.

  1. Tell the user which libraries you are including and why
  2. Ask the user if any additional libraries are needed
  3. If the user asks what's available, run listArduinoLibraries and show the full list

Step 5: Connect

Build the arduino() call based on what you gathered:

% TEMPLATE — not executable
% With board type known + custom libraries:
a = arduino('<port>', '<board>', 'Libraries', {'I2C', 'SPI', 'Servo', ...});

% With board type known, default libraries only:
a = arduino('<port>', '<board>');

% Auto-detect board type (uses libraries already flashed on board):
a = arduino('<port>');

Important: You cannot specify 'Libraries' without also specifying the board type. If the user doesn't know their board type but needs extra libraries, run arduino('<port>') first to auto-detect, then read a.Board and reconnect with the board type and libraries specified.

If the connection fails:

  1. Stop immediately — do not retry automatically
  2. Report the exact error message to the user
  3. Provide 1–2 targeted fixes based on the error
  4. Do not retry with different ports or board types unless the user explicitly instructs

Common issues:

  • Port is busy (another application has it open)
  • "Device in use" — an arduino object already exists in the workspace; the user must clear it before reconnecting
  • Wrong board type specified
  • Board needs a firmware reset (double-tap reset button)

Step 6: Confirm and hand off

After successful connection:

  1. Confirm to the user: "Connection established to [Board] on [Port] with libraries: [list]."
  2. If the user's prompt includes a task beyond just connecting (e.g., "blink LED", "read ultrasonic sensor"), announce: "Now proceeding with [task]..." and continue with the downstream workflow.

Key Functions

FunctionPurposeAvailable From
arduinolistDiscover connected Arduino boards (table output)R2024a
serialportlist("available")List all available serial portsR2019b
arduino(port)Connect with auto-detected board type, default librariesR2014b
arduino(port, board)Connect with specified board, default librariesR2014b
arduino(port, board, 'Libraries', libs)Connect with specified board and custom librariesR2014b
listArduinoLibrariesList all available add-on librariesR2014b

Patterns

Single board connection

% TEMPLATE — not executable
% Step 1: Discover
list = arduinolist;
ports = serialportlist("available");

% Step 3-5: Connect (after user selects port and board is known)
a = arduino('COM8', 'Nano33BLE', 'Libraries', {'I2C', 'SPI', 'Servo', 'Ultrasonic'});

Multi-board connection

% TEMPLATE — not executable
% Connect to each board with its own variable and libraries
a1 = arduino('COM8', 'Nano33BLE', 'Libraries', {'I2C', 'SPI', 'Servo'});
a2 = arduino('COM52', 'Uno', 'Libraries', {'I2C', 'SPI', 'Servo', 'Ultrasonic'});

Common Mistakes

MistakeWhy It's WrongCorrect Approach
Using arduino() with no argumentsConnects to arbitrary board without user consentAlways discover first, let user choose
Guessing COM port or board typeWastes time on wrong ports, reflashes wrong boardsAsk the user, or use auto-detect with port only
Loading only the needed libraryReconnecting later with more libraries takes 30+ secLoad defaults {'I2C','SPI','Servo'} plus any inferred extras
Using arduino(port, 'Libraries', libs) without boardError: must specify both port and board before name-value pairsUse arduino(port, board, 'Libraries', libs) or arduino(port) for auto-detect with defaults
Skipping serialportlist when arduinolist succeedsMisses boards without support package firmware or pre-R2024a boardsAlways run both — serialportlist is mandatory even when arduinolist returns results
Killing processes to free a portDestructive action without user consentReport the port conflict, ask user to close the other application

Conventions

  • MUST run both arduinolist AND serialportlist("available") in every discovery step — even if arduinolist already found the board. serialportlist catches boards that arduinolist does not recognize.
  • Always present discovered information to the user before acting
  • Board type is optional — let MATLAB auto-detect when user doesn't know
  • Default libraries {'I2C', 'SPI', 'Servo'} are always included
  • Never take destructive actions (killing processes, clearing workspaces) without asking
  • Clearly separate the connection step from downstream task execution
  • Arduino hardware is not shareable — only one MATLAB session can hold a connection to a given board at a time. Do not run multiple parallel agents that each try to connect to Arduino hardware. Run Arduino workflows sequentially.

Copyright 2026 The MathWorks, Inc.


レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Guide for accessing financial and economic data in MATLAB using the Datafeed Toolbox. Covers Bloomberg (market data via bloomberg/blp/bloombergHypermedia), FRED (Federal Reserve economic data via fredrs), Haver Analytics (economic data via haver/haverdirect/haverview), and LSEG Datastream (historical data via datastreamws). Use when connecting to any of these data providers from MATLAB.

日本語の概要は準備中です。原文の説明を表示しています。

matlab/matlab-agentic-toolkit1,1562026年10月9日 更新

Read BEFORE writing any code that adds Additive White Gaussian Noise (AWGN) to signals and converts between SNR, Eb/No, Es/No, and per-subcarrier SNR for communications simulations, using awgn(), convertSNR(), berawgn(). The default MATLAB patterns for AWGN (e.g., 'measured' option, manual SNR formulas) produce subtly incorrect results. This skill specifies the correct calling conventions, required function usage, and critical anti-patterns that must be avoided.

日本語の概要は準備中です。原文の説明を表示しています。

matlab/matlab-agentic-toolkit1,1562026年10月9日 更新

Analyze AMS waveform data using Mixed-Signal Blockset utilities: phase noise measurement, clock jitter, anti-aliased resampling, timing measurements, lock time, INL/DNL, ADC/DAC calibration, HSpice import. Use when analyzing time-domain voltage from PLL/VCO/clock simulations, measuring phase noise from variable-step solver output, computing jitter, or resampling non-uniform data.

日本語の概要は準備中です。原文の説明を表示しています。

matlab/matlab-agentic-toolkit1,1562026年10月9日 更新

Design and analyze electrically large antenna structures using MATLAB Antenna Toolbox. Covers reflector antennas (parabolic, Cassegrain, Gregorian, offset, corner, cylindrical, spherical, custom STL), reflectarrays and reconfigurable intelligent surfaces (RIS), antennas installed on platforms (vehicles, aircraft, ships, satellites), and radar cross section (RCS) analysis. Includes solver selection (MoM-PO, PO, MoM, FMM), mesh control, and GPU acceleration. Use when the user wants to design a dish/reflector antenna, reflectarray, analyze an antenna on a platform, or compute RCS.

日本語の概要は準備中です。原文の説明を表示しています。

matlab/matlab-agentic-toolkit1,1562026年10月9日 更新

Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, row filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.

日本語の概要は準備中です。原文の説明を表示しています。

matlab/matlab-agentic-toolkit1,1562026年10月9日 更新

S-parameters, insertion loss, fields, currents, mesh control, and solver selection for RF PCB performance validation. TRIGGER: user asks to compute S-parameters, analyze insertion/return loss, extract fields or currents, compare MoM vs FEM, or control mesh for any RF PCB component. Invoke BEFORE writing sparameters() or solver code — API is non-obvious. SKIP: designing or creating components (use the specific matlab-design-pcb-* skill), material/stackup setup only (use matlab-manage-pcb-material), optimization sweeps (use matlab-optimize-pcb-design), PDN/IR-drop analysis (use matlab-analyze-pcb-pdn).

日本語の概要は準備中です。原文の説明を表示しています。

matlab/matlab-agentic-toolkit1,1562026年10月9日 更新

matlab のスキルをすべて見る

このスキルの問題を報告する