arduino
Connection to the Arduino and Arduino-compatible ESP32 hardware
Description
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
An arduino object represents a connection to Arduino® or Arduino-compatible ESP32 hardware. Use the arduino
function to connect Arduino or Arduino-compatible ESP32 hardware to MATLAB®. After you create the object, you can program your hardware and use custom
add-on libraries directly from MATLAB using the Object Functions.
Use the arduino object to connect to an Arduino board over USB, WiFi, or
Bluetooth, by specifying the different arguments based on the connection type. For more
information, see Supported Boards.
| Connection Type | Type of Valid Arguments | Option for Additional Name-Value Arguments |
|---|---|---|
| USB |
| Yes Specify one or more Name-Value Arguments from these options:
|
| Bluetooth |
| No |
| WiFi |
| No |
Creation
Syntax
Description
USB
recreates the last successful
connection to the Arduino or Arduino-compatible ESP32 hardware. If there is no last successful
connection or that connection failed, it creates a connection to an official Arduino hardware connected to your host computer via USB.a = arduino
creates a connection to Arduino or Arduino-compatible ESP32 hardware on the specified serial port. The
serial port can be a USB serial port.a = arduino(port)
creates a connection with additional options specified by one or more
a = arduino(___,Name,Value)Name,Value pair arguments.
Bluetooth
uses the Bluetooth® address of the supported Arduino or Arduino-compatible ESP32 hardware. For the list of Bluetooth connection
type supported hardware, see Supported Boards.a = arduino(btaddress)
uses the name of the of the supported Arduino or Arduino-compatible ESP32 hardware Bluetooth device to create a connection to the Arduino hardware. For the list of Bluetooth connection type supported hardware,
see Supported Boards.a = arduino(btname)
Input Arguments
Name-Value Arguments
Properties
Object Functions
The object functions device, shiftRegister, rotaryEncoder, servo, addon, and ultrasonic are used to create
objects for each of their respective peripheral devices. Other functions are used to interact
with the pins on your Arduino hardware.
device | Connection to device on I2C bus on Arduino or ESP32 hardware |
device | Connection to device on SPI bus on Arduino or ESP32 hardware |
device | Connection to serial device on Arduino or ESP32 hardware |
shiftRegister | Connection to shift register on Arduino hardware |
rotaryEncoder | Connection to quadrature encoder on Arduino or ESP32 hardware |
servo | Connection to servo motor on Arduino or ESP32 hardware |
servo | Connection to servo motor on Arduino MKR Motor Carrier or Nano Motor Carrier |
addon | Connection to add-on device for Arduino hardware |
ultrasonic | Connection to ultrasonic sensor on Arduino hardware |
motorCarrier | Connection to Arduino MKR Motor Carrier or Nano Motor Carrier |
apds9960 | Connect to APDS9960 sensor on Arduino hardware using I2C bus |
canChannel | Connection to CAN channel connected to a specified device |
configurePin | Set Arduino pin mode |
readDigitalPin | Read data from a specified pin on Arduino hardware |
writeDigitalPin | Write data to a specified pin on Arduino hardware |
writePWMVoltage | Generate PWM signal with specified voltage on digital pin |
writePWMDutyCycle | Generate PWM signal with specified duty cycle on digital pin |
playTone | Play tone on piezo speaker using digital pin |
readVoltage | Read voltage from analog pin on Arduino hardware |
scanI2CBus | Scan I2C bus on Arduino hardware for device address |
motorCarrier | Connection to Arduino MKR Motor Carrier or Nano Motor Carrier |
canChannel | Connection to CAN channel connected to a specified device |
Examples
More About
Supported Boards
The board input argument currently support these boards:
Classic Boards
| Arduino Uno R4 Minima | Arduino Uno R4 WiFi | Arduino Uno | Arduino Mega 2560 |
| Arduino Mega ADK | Arduino Due | Arduino Leonardo | Arduino Micro |
| Arduino Pro Mini |
Nano Boards
MKR Boards
Arduino Compatible Boards
| ESP32-S3-DevKitM-1 | ESP32-DevKitV1 | ESP32-DevKitC | Raspberry Pi Pico |
| Raspberry Pi Pico W | Sparkfun Digital Sandbox |
Arduino Uno R4 Minima
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'UnoR4Minima' | No | No | Yes | 1.5 (default) | No | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
Arduino Uno R4 WiFi
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'UnoR4WiFi' | Yes | Yes | Yes | 1.5 (default) | No | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
Arduino Uno
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Uno' | No | Yes | Yes | 5.0(default), 1.1 | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
Arduino Mega 2560
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Mega2560' | No | Yes | Yes | 5.0 (default), 1.1,
2.56 | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino Mega ADK
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'MegaADK' | No | No | Yes | 5.0 (default), 1.1,
2.56 | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino Due
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Due' | No | Yes | Yes | 3.3 (default) | No | No | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino Leonardo
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Leonardo' | No | Yes | Yes | 5.0 (default), 2.56 | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino Micro
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Micro' | No | Yes | Yes | 5.0 (default), 2.56 | Yes | Yes | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino Pro Mini
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
| No | No | Yes |
| Yes | Yes | Yes | No | Yes | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
Arduino Nano ESP32
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
| 'NanoESP32' | Yes | Yes | Yes | 3.3 (default) | No | No | Yes | No | No | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
Arduino Nano 33 BLE SENSE
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Nano33BLE' | No | Yes | Yes | 3.3 (default) | No | No | Yes | No | Yes | Yes | No | No | Yes | Yes | Yes | Yes | Yes |
Arduino Nano 33 BLE
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Nano33BLE' | No | Yes | Yes | 3.3 (default) | No | No | Yes | No | Yes | Yes | No | No | Yes | Yes | Yes | Yes | Yes |
Arduino Nano 33 IoT
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Nano33IoT' | Yes | Yes | Yes | 3.3 (default), 1.0,
1.65, 2.23 | Yes | No | Yes | No | Yes | Yes | Yes (Nano Motor carrier) | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino Nano 3.1
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'Nano3' | No | Yes | Yes | 5.0 (default), 1.1 | Yes | Yes | Yes | No | Yes | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
Arduino MKR WiFi1010
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'MKR1010' | Yes | Yes | Yes | 3.3 (default), 1.0,
1.65, 2.23 | Yes | No | Yes | No | Yes | Yes | Yes (MKR Motor carrier) | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino MKR1000
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'MKR1000' | Yes | No | Yes | 3.3 (default), 1.0,
1.65, 2.23 | Yes | No | Yes | No | Yes | Yes | Yes (MKR Motor carrier) | Yes | Yes | Yes | Yes | Yes | Yes |
Arduino MKR Zero
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'MKRZero' | No | No | Yes | 3.3 (default), 1.0,
1.65, 2.23 | Yes | No | Yes | No | Yes | Yes | Yes (MKR Motor carrier) | Yes | Yes | Yes | Yes | No | Yes |
ESP32-S3-DevKitM-1
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
| 'ESP32-S3-DevKitM' | Yes | Yes | Yes | 3.3 (default) | No | No | Yes | No | No | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
ESP32-DevKitV1
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'ESP32-WROOM-DevKitV1' | Yes | Yes | Yes | 3.3 (default) | No | No | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
ESP32-DevKitC
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'ESP32-WROOM-DevKitC' | Yes | Yes | Yes | 3.3 (default) | No | No | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Raspberry Pi Pico
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'RaspberryPiPico' | No | No | Yes | 3.3 (default) | No | Yes | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Raspberry Pi Pico W
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'RaspberryPiPicoW' | Yes | No | Yes | 3.3 (default) | No | Yes | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
Sparkfun Digital Sandbox
| Input Argument | WiFi Support | Bluetooth Support | AnalogReferenceMode | playTone Function Support | Supported Libraries | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Internal AREF | Supported Internal Voltage (V) | External AREF | APDS9960 | Adafruit/MotorShieldV2 | CAN | I2C | Motor Carrier | Rotary Encoder | Servo | SPI | Serial | Shift Register | Ultrasonic | ||||
'DigitalSandbox' | No | No | Yes | 3.3 (default), 1.1 | No | Yes | Yes | No | Yes | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
For a list of other Arduino-compatible boards that have been tested and their corresponding input arguments, see Find Board Name.
Version History
Introduced in R2014b