arduino
Connection to the Arduino and Arduino-compatible ESP32 hardware
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
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 the
supported connection type for each board, 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 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
port
— Hardware port
character vector | string array
Hardware port that your Arduino or ESP32 is connected to, specified as a character vector or string array. The port can be a USB serial port. To identify the USB serial port number, see Find Arduino Port on Windows, Mac, and Linux. This argument can be specified on its own if connected via USB serial port, or with a board name.
Example: a = arduino('COM5')
board
— Name of Arduino enabled board
character vector | string array
Name of the Arduino enabled board, specified as a character vector or string array. This argument must be specified with a valid serial port, IP address, Bluetooth address, or Bluetooth name. See Supported Boards for all supported boards.
Example: a = arduino('COM5','Uno')
creates a connection to an
Arduino Uno board using port 5.
btaddress
— Bluetooth address of the Nano 33 BLE
, Nano 33 BLE Sense
, Nano 33 IoT
, MKR1010
,
HC-05
, HC-06
, ESP32-DevKitV1
or ESP32-DevKitC
character vector | string array
For Nano 33 BLE
, Nano 33 BLE Sense
,
Nano 33 IoT
, MKR1010
,
ESP32-DevKitV1
or ESP32-DevKitC
the
Bluetooth
4.0
address is the peripheral device's MAC address for Windows. For
macOS, it is a random operating system assigned address.
For HC-05
or HC-06
devices, the Bluetooth Classic address is specified as a character vector or string array of
the form btspp://
followed by the 12-digit hexadecimal value of the
address. To identify the Bluetooth device address, see Pair a Bluetooth Device and Retrieve the Bluetooth Device Address.
Example: a = arduino('btspp://98d331fb3b77')
creates a
Bluetooth connection to a board using HC-05
or
HC-06
.
Example: a = arduino('5A8769A09DA6')
creates a Bluetooth
4.0
connection between a Windows OS and Arduino
Nano 33 BLE
, Nano 33 BLE Sense
, Nano 33
IoT
, MKR1010
, ESP32-DevKitV1
or
ESP32-DevKitC
boards.
Example: a = arduino('121B0BAC-0DE7-4FB1-909A-EEA6877DBC5C')
creates a Bluetooth
4.0
connection to between a macOS and a Arduino
Nano 33 BLE
, Nano 33 BLE Sense
, Nano 33
IoT
, MKR1010
, ESP32-DevKitV1
or
ESP32-DevKitC
boards.
btname
— Bluetooth name of the device
character vector | string array
Bluetooth name of the device, specified as a character vector or string array.
Example: a = arduino('HC-05')
creates a wireless Bluetooth connection to an Arduino Uno board that uses an HC-05 Bluetooth device.
Example: a = arduino('IMUBLE')
creates a wireless Bluetooth connection to an Arduino
Nano 33 BLE
,Nano 33 BLE Sense
, Nano 33
IoT
, MKR1010
, ESP32-DevKitV1
or
ESP32-DevKitC
boards that uses a Bluetooth
4.0
device.
ipaddress
— IP address of Arduino board with WiFi support or ESP32 board
character vector | string array
IP address of the Arduino board with WiFi support, specified as a character vector or string array.
Example: a = arduino('192.168.1.15','MKR1000')
creates a WiFi
connection to an Arduino MKR1000 board that uses the IP address
192.168.1.15
.
tcpipport
— TCP/IP port on Arduino or ESP32 board
9500 (default) | numeric
TCP/IP port on the Arduino or ESP32 board, specified as a number.
Example: a = arduino('192.168.1.15','MKR1000',9500)
creates a
WiFi connection to an Arduino MKR1000 board that uses the TCP/IP port at 9500.
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Note
If you are connecting an Arduino board using Bluetooth or WiFi, you cannot specify Name,Value
arguments.
Example:
a = arduino('COM3','Uno','Libraries','I2C')
Libraries
— Name of Arduino library
{'I2C' 'Servo' 'SPI'}
(default) | APDS9960
| Adafruit/MotorShieldV2
| CAN
| MotorCarrier
| RotaryEncoder
| Serial
| ShiftRegister
| Ultrasonic
| character vector | cell array of character vectors
Name of the Arduino library, specified as the comma-separated pair consisting of
'Libraries'
and a character vector or a cell array of character
vectors. Libraries installed by default extend the Arduino environment.
Note
When you first connect to your Arduino hardware, your Arduino connection is created with these default libraries {'I2C'
'Servo' 'SPI'}
. However, if you create an Arduino connection with libraries other than the defaults, your
Arduino connection will have only the libraries that you specified, even
after you disconnect and reconnect your Arduino hardware.
Note
The libraries CAN
,
Servo
, and RotaryEncoder
are not supported for ESP32 board.
Example: a = arduino('COM9','Uno','Libraries','spi')
limits
the environment to the SPI library.
Example: a =
arduino('COM9','Uno','Libraries','Adafruit/MotorShieldV2')
limits the
environment to the Adafruit Motor Shields V2 library and its dependent
libraries.
Example: a = arduino('COM9','Uno','Libraries','ShiftRegister')
limits the environment to shift register library.
AnalogReferenceMode
— Type of reference voltage
default depends on AnalogReference
| internal
| external
| character vector
Type of reference voltage, specified as internal
or
external
. In the external
mode, an external
voltage is applied at the AREF pin. In the internal
mode, the
internal voltage supported by the Arduino boards is used.
The actual default value depends on AnalogReference
.
If
AnalogReference
is used as a Name-Value arguments, the default value is set toexternal
.If
AnalogReference
is not used as a Name-Value arguments, the default value is set tointernal
.
See Supported Boards for supported internal voltages of the Arduino boards.
Note
In the external
mode, you must specify the external voltage
applied at the AREF pin using AnalogReference
. In the
internal
mode, you can specify the internal voltage supported
on the boards. If you do not specify a voltage in the internal
mode, the default internal reference voltage of the Arduino boards is used.
Example: a =
arduino('COM9','Uno','AnalogReferenceMode','external','AnalogReference',1.1)
sets the reference voltage externally to 1.1V.
AnalogReference
— Analog reference voltage
double
Reference voltage of the analog input, specified as a double.
Before using an external reference voltage on the AREF pin, ensure the following for safety:
Connect the external voltage to the AREF pin through a 5K resistor to prevent damaging the board. If
AnalogReferenceMode
isinternal
and a reference voltage is still connected externally at the AREF pin, you will short the internal reference voltage and the AREF pin, thus damaging the board.Do not use a voltage less than 0V or more than the maximum voltage supported by the boards.
Note
When you change the analog reference voltage, the output of
readVoltage
may not be accurate. Run
readVoltage
until you see the expected value. For Arduino Uno and Mega boards, see Incorrect readVoltage results.
Example: a = arduino('COM9','Uno','AnalogReferenceMode','external',
'AnalogReference',1.1)
sets the reference voltage externally to
1.1V.
ForceBuildOn
— Reprogramming of the Arduino board
false
(default) | true
If 'ForceBuildOn'
is not set as true
,
MATLAB does not reprogram the Arduino board and uses the existing Arduino server if the libraries that you specify match with libraries that are
already on the existing Arduino server. Use this setting to update the Arduino server with different source code when you work with custom
Arduino libraries.
Example: a =
arduino('COM9','Uno','Libraries','CustomLibrary','ForceBuildOn',true)
reprograms the Arduino board using your latest C++ source code for
CustomLibrary
.
Note
MATLAB does not reprogram the Arduino board and uses the existing Arduino server if the libraries that you specify match with libraries that are already on the existing Arduino server.
TraceOn
— Program log and Arduino commands log
false
(default) | true
Program log and Arduino commands log, specified as the comma-separated pair consisting of
'TraceOn'
and either false
or
true
. If you fail to connect to your Arduino board, set 'TraceOn'
to true
to
print compilation and upload errors of Arduino IDE at the MATLAB command window. You can also set 'TraceOn'
to
true
to print the Arduino commands executed on the Arduino board for each MATLAB command.
Example: a =
arduino('COM9','Uno','TraceOn',true)
BaudRate
— Bit transmission rate
The rate at which information is transferred in the communication channel. For
Arduino Pro Mini, and Digital Sandbox use the BaudRate
value of
57600. For all the other boards listed in Find Board Name use the BaudRate
value of 115200.
Note
For streaming data from sensors at higher rates, set the
BaudRate
to a higher value. For other applications use the
default BaudRate
of the Arduino board.
Example: a =
arduino('COM9','Uno','BaudRate',115200);
Dependencies
For streaming data from multiple sensors with Navigation Toolbox™ or Sensor Fusion and Tracking Toolbox™, set the BaudRate
to 921600. This change on
Arduino enables MATLAB to acquire real-time data from the GPS receivers and
IMU sensors. For other applications use the default BaudRate
of
the Arduino board.
Properties
Port
— Hardware port
'COM4'
| 'COM5'
| character vector | ...
This property is read-only.
Hardware port that your Arduino or ESP32 is connected to, specified as a character vector or string array.
The port can be a USB serial port. Specify the port when you create the
arduino
object.
Example:
>> a.Port ans = 'COM4'
Data Types: char
Connected
— Arduino device connection status over Bluetooth
true
or 1
| false
or 0
This property is read-only.
Arduino device connection status over Bluetooth, returned as numeric or logical
1
(true
) or 0
(false
). Property is available for only Nano 33
BLE
, Nano 33 BLE Sense
, Nano 33 IoT
,
MKR1010
, ESP32-DevKitV1
, and
ESP32-DevKitC
boards.
Data Types: logical
Board
— Name of Arduino enabled board
'Uno'
| 'Due'
| 'Mega2560'
| character vector | ...
This property is read-only.
Name of the Arduino enabled board, specified as a character vector or string array. It is the
type of Arduino hardware connected to your system. Specify the board type when you create
the arduino
object. See Supported Boards for all supported
boards.
Example:
>> a.Board ans = 'Uno'
Data Types: char
AvailablePins
— Pins available on Arduino device
{'D2-D13', 'A0-A5'}
| cell array of character vectors | ...
This property is read-only.
Pins available on Arduino device connected to your system, specified as cell array of character vectors.
Example:
a.AvailablePins ans = 1×18 cell array Columns 1 through 12 {'D2'} {'D3'} {'D4'} {'D5'} {'D6'} {'D7'} {'D8'} {'D9'} {'D10'} {'D11'} {'D12'} {'D13'} Columns 13 through 18 {'A0'} {'A1'} {'A2'} {'A3'} {'A4'} {'A5'}
Data Types: cell
AvailableDigitalPins
— Digital pins available on Arduino device
{'D2-D13', 'A0-A5'}
(default) | cell array of character vectors
This property is read-only.
Digital pins available on Arduino device connected to your system, specified as cell array of character vectors.
Example:
a.AvailableDigitalPins ans = Columns 1 through 12 {'D2'} {'D3'} {'D4'} {'D5'} {'D6'} {'D7'} {'D8'} {'D9'} {'D10'} {'D11'} {'D12'} {'D13'} Columns 13 through 18 {'A0'} {'A1'} {'A2'} {'A3'} {'A4'} {'A5'}
Data Types: cell
AvailablePWMPins
— PWM pins available on Arduino device
{'D3', 'D5-D6', 'D9-D11'}
(default) | cell array of character vectors
This property is read-only.
PWM pins available on Arduino device connected to your system, specified as cell array of character vectors.
Example:
a.AvailablePWMPins ans = {'D3'} {'D5'} {'D6'} {'D9'} {'D10'} {'D11'}
Data Types: cell
AvailableAnalogPins
— Analog pins available on Arduino device
{'A0-A5'}
(default) | cell array of character vectors
This property is read-only.
Analog pins available on Arduino device connected to your system, specified as cell array of character vectors.
Example:
a.AvailableAnalogPins ans = 1×6 cell array {'A0'} {'A1'} {'A2'} {'A3'} {'A4'} {'A5'}
Data Types: cell
AvailableI2CBusIDs
— I2C bus IDs available on Arduino device
0
(default) | numeric
This property is read-only.
The ID of I2C bus available on Arduino device connected to your system.
Example:
a.AvailableI2CBusIDs ans = [0]
Data Types: double
AvailableSerialPortIDs
— Serial ports available on Arduino device
numeric
The serial bus ID available on Arduino device connected to your system.
Note
The Arduino Due, Mega2560, and MegaADK boards have three serial ports available while the Arduino Leonardo, Micro, MKR1000, MKR1010, Nano33IoT, Nano33BLE, and ESP32 have only one serial port available.
Example:
a.AvailableSerialPortIDs ans = 1
Dependencies
This property is valid only when the serial library is used to create a connection to the Arduino hardware.
Data Types: double
Libraries
— Installed Arduino add-on libraries
{'I2C', 'Servo', 'SPI'}
(default) | 'Adafruit/MotorShieldV2'
| 'ShiftRegister'
| character vector | cell array of character vectors
This property is read-only.
Installed Arduino add-on libraries downloaded to your hardware, specified as a character
vector or cell array of character vectors. Check the available libraries with listArduinoLibraries
to specify the add-on library you want to use.
Example:
a.Libraries ans = 1×3 cell array {'I2C'} {'Servo'} {'SPI'}
Data Types: cell
| char
AnalogReferenceMode
— Type of reference voltage
default depends on AnalogReference
| internal
| external
| character vector
This property is read-only.
Type of reference voltage, specified as internal
or
external
. In the external
mode, an external
voltage is applied at the AREF pin. In the internal
mode, the
internal voltage supported by the Arduino boards is used.
The actual default value depends on AnalogReference
.
If
AnalogReference
is used as a Name-Value arguments, the default value is set toexternal
.If
AnalogReference
is not used as a Name-Value arguments, the default value is set tointernal
.
In the external
mode, you must specify the external voltage
applied at the AREF pin using AnalogReference
. In the
internal
mode, you can specify the internal voltage supported on
the boards. If you do not specify a voltage in the internal
mode, the
default internal reference voltage of the Arduino boards is used.
Example:
a.AnalogReferenceMode ans = 'internal'
AnalogReference
— Analog reference voltage
double
This property is read-only.
Reference voltage of the analog input, specified as a double.
Before using an external reference voltage on the AREF pin, ensure the following for safety:
Connect the external voltage to the AREF pin through a 5K resistor to prevent damaging the board. If
AnalogReferenceMode
isinternal
and a reference voltage is still connected externally at the AREF pin, you will short the internal reference voltage and the AREF pin thus damaging the board.Do not use a voltage less than 0V or more than the maximum voltage supported by the boards.
See Supported Boards for supported internal voltages of the Arduino boards.
When you change the analog reference voltage, the output of
readVoltage
may not be accurate. Run readVoltage
until you see the expected value. For Arduino Uno and Mega boards, see Incorrect readVoltage results.
Example:
a.AnalogReference ans = 5.0
Supported Boards
The board
input argument currently support these boards:
Arduino Board | Input Argument | WiFi Support | Bluetooth Support | Supported Internal Voltage (V) |
---|---|---|---|---|
Arduino Uno | 'Uno' | No | Yes | 5.0 (default), 1.1 |
Arduino Uno R4 WiFi | 'UnoR4WiFi' | Yes | No | 1.5 (default) |
Arduino Uno R4 Minima | 'UnoR4Minima' | No | No | 1.5 (default) |
Arduino Due | 'Due' | No | Yes | 3.3 (default) |
Arduino Mega 2560 | 'Mega2560' | No | Yes | 5.0 (default), 1.1 ,
2.56 |
Arduino Leonardo | 'Leonardo' | No | Yes | 5.0 (default), 2.56 |
Arduino Mega ADK | 'MegaADK' | No | No | 5.0 (default), 1.1 ,
2.56 |
Arduino Micro | 'Micro' | No | Yes | 5.0 (default), 2.56 |
Arduino MKR1000 | 'MKR1000' | Yes | No | 3.3 (default), 1.0 ,
1.65 , 2.23 |
Arduino MKR WiFi1010 | 'MKR1010' | Yes | Yes | 3.3 (default), 1.0 ,
1.65 , 2.23 |
Arduino MKR Zero | 'MKRZero' | No | No | 3.3 (default), 1.0 ,
1.65 , 2.23 |
Arduino Nano 3.1 | 'Nano3' | No | Yes | 5.0 (default), 1.1 |
Arduino Nano 33 IoT | 'Nano 33IoT' | Yes | Yes | 3.3 (default), 1.0 ,
1.65 , 2.23 |
Arduino Pro Mini |
| No | No |
|
Sparkfun Digital Sandbox | DigitalSandbox | No | No | 3.3 (default), 1.1 |
Arduino Nano 33 BLE | 'Nano33BLE' | No | Yes | 3.3 (default) |
Arduino Nano 33 BLE SENSE | 'Nano33BLE' | No | Yes | 3.3 (default) |
ESP32-DevKitV1 | 'ESP32-WROOM-DevKitV1' | Yes | Yes | 3.3 (default) |
ESP32-DevKitC | 'ESP32-WROOM-DevKitC' | Yes | Yes | 3.3 (default) |
For a list of other Arduino-compatible boards that have been tested and their corresponding input arguments, see Find Board Name.
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
Connect to Arduino Hardware
Autodetect an Arduino Nano33IoT.
a = arduino()
arduinoObj = arduino with properties: Port: 'COM11' Board: 'Nano33IoT' AvailablePins: {'D0-D13', 'A0-A7'} AvailableDigitalPins: {'D0-D13', 'A0-A7'} AvailablePWMPins: {'D2-D6', 'D9-D12', 'A2-A3', 'A5'} AvailableAnalogPins: {'A0-A3','A6-A7'} AvailableI2CBusIDs: [0] AvailableSerialPortIDs: [1] Libraries: {'SPI'} Show all properties
Note
If an Arduino object was created previously, the new Arduino object created on the computer will have the same configuration as the earlier object.
Specify Port Number and Arduino Board Type
Connect to an Arduino Uno on port 9. The port and board names depend on your configuration.
a = arduino('COM9','Uno')
Updating server code on board Uno (COM9). This may take a few minutes.
a = arduino with properties: Port: 'COM9' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'SPI'} Show all properties
Specify Port Number and ESP32 Board Type
Connect to an ESP32-DevKitC on com port 4. The port and board names depend on your configuration.
a = arduino('COM4','ESP32-WROOM-DevKitC')
a = arduino with properties: Port: 'COM4' Board: 'ESP32-WROOM-DevKitC' AvailablePins: {'D0-D5', 'D12-D19', 'D21-D23', 'D25-D27', 'D32-D39'} AvailableDigitalPins: {'D0-D5', 'D12-D19', 'D21-D23', 'D25-D27', 'D32-D39'} AvailablePWMPins: {'D1-D5', 'D12-D19', 'D21-D23', 'D25-D27', 'D32-D33'} AvailableAnalogPins: {'D2', 'D4', 'D12-D15', 'D25-D27', 'D32-D36', 'D39'} AvailableI2CBusIDs: [0] AvailableSerialPortIDs: [2] Libraries: {'I2C', 'SPI', 'Serial'} Show all properties
Specify Bluetooth Address
Connect an HC-05
with a Arduino
Uno
using Bluetooth.
a = arduino('btspp://98D331FB3B77')
a = arduino with properties: DeviceAddress: 'btspp://98D331FB3B77' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'I2C', 'Servo', 'SPI'} Show all properties
Specify Bluetooth Address
Connect Nano 33 BLE
, Nano 33 BLE
Sense
, Nano 33 IoT
, MKR1010
,
ESP32-DevKitV1
or ESP32-DevKitC
boards over
Bluetooth
4.0
address which is the peripheral device's MAC address for
Windows.
a = arduino('CA89D02FDC71')
a = arduino with properties: Name: 'IMUBLE' Address: 'CA89D02FDC71' Connected: 1 Board: 'Nano33BLE' AvailablePins: {'D0-D13', 'A0-A7'} AvailableDigitalPins: {'D0-D13', 'A0-A7'} AvailablePWMPins: {'D2-D6', 'D9-D12'} AvailableAnalogPins: {'A0-A3', 'A6-A7'} AvailableI2CBusIDs: [0,1] AvailableSerialPortIDs: [1] Libraries: {'I2C'} Show all properties
In Windows, you can also specify the address in the format
CA:89:D0:2F:DC:71
.
Specify Bluetooth Device Name
Connect an HC-06
with a Arduino
Uno
using Bluetooth.
a = arduino('HC-06')
a = arduino with properties: DeviceAddress: 'HC-06' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'I2C', 'Servo', 'SPI'} Show all properties
Specify Bluetooth Formatted Address
Connect to an Arduino
Nano 33 BLE
using Bluetooth. The address format is of two types.
a = arduino('CA:89:D0:2F:DC:71')
a = arduino with properties: Name: 'IMUBLE' Address: 'CA89D02FDC71' Connected: 1 Board: 'Nano33BLE' AvailablePins: {'D0-D13', 'A0-A7'} AvailableDigitalPins: {'D0-D13', 'A0-A7'} AvailablePWMPins: {'D2-D6', 'D9-D12'} AvailableAnalogPins: {'A0-A3', 'A6-A7'} AvailableI2CBusIDs: [0,1] AvailableSerialPortIDs: [1] Libraries: {'I2C'}
Specify IP Address to Connect to Arduino MKR1000 Board
Connect to an Arduino MKR1000 board using WiFi.
a = arduino('10.10.10.55','MKR1000')
a = arduino with properties: DeviceAddress: '10.10.10.55' Port: 9500 Board: 'MKR1000' AvailablePins: {'D0-D14', 'A0-A6'} AvailableDigitalPins: {'D0-D14', 'A0-A6'} AvailablePWMPins: {'D0-D8', 'D10', 'A3-A4'} AvailableAnalogPins: {'A0-A6'} AvailableI2CBusIDs: [0] AvailableSerialPortIDs: [1] Libraries: {'I2C', 'SPI', 'Serial', 'Servo'}
Specify IP Address and TCP/IP Port to Connect to an Arduino MKR1000 Board
a = arduino('10.10.10.55','MKR1000',9500)
a = arduino with properties: DeviceAddress: '10.10.10.55' Port: 9500 Board: 'MKR1000' AvailablePins: {'D0-D14', 'A0-A6'} AvailableDigitalPins: {'D0-D14', 'A0-A6'} AvailablePWMPins: {'D0-D8', 'D10', 'A3-A4'} AvailableAnalogPins: {'A0-A6'} AvailableI2CBusIDs: [0] AvailableSerialPortIDs: [1] Libraries: {'I2C', 'SPI', 'Serial', 'Servo'}
Connect to an Arduino Board on a Mac
Connect to an Arduino
Uno
on port /dev/tty.usbmodem1421
.
a = arduino('/dev/tty.usbmodem1421','Uno')
a = arduino with properties: Port: '/dev/tty.usbmodem1421' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'Adafruit/MotorShieldV2', 'I2C', 'SPI', 'Servo'} Show all properties
Connect to an Arduino
Nano 33 BLE
, Nano 33 BLE Sense
, Nano 33
IoT
, or a MKR1010
board over Bluetooth using a random
128
bit device address assigned by the macOS.
a = arduino('121B0BAC-0DE7-4FB1-909A-EEA6877DBC5C')
a = arduino with properties: Name: 'IMUBLE' Address: '121B0BAC-0DE7-4FB1-909A-EEA6877DBC5C' Connected: 1 Board: 'Nano33BLE' AvailablePins: {'D0-D13', 'A0-A7'} AvailableDigitalPins: {'D0-D13', 'A0-A7'} AvailablePWMPins: {'D2-D6', 'D9-D12'} AvailableAnalogPins: {'A0-A3', 'A6-A7'} AvailableI2CBusIDs: [0,1] AvailableSerialPortIDs: [1] Libraries: {'I2C'} Show all properties
Specify an Arduino Library
Limit the Arduino environment to use only an I2C library.
a = arduino('COM9','Uno','Libraries','I2C')
Updating server code on board Uno (COM9). This may take a few minutes.
a = arduino with properties: Port: 'COM9' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'I2C'} Show all properties
Limit the Arduino Environment to Use Only Two Libraries
Limit the Arduino environment to use only the servo and shift register libraries.
a = arduino('COM9','Uno',"Libraries",{"Servo","ShiftRegister"},'ForceBuildOn',true)
Updating server code on board Uno (COM9). This may take a few minutes.
a = arduino with properties: Port: 'COM9' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'Servo', 'ShiftRegister'} Show all properties
Specify Analog Reference Voltage
Set AnalogReference
internally to 1.1 V
a = arduino('COM9','Uno','AnalogReferenceMode','internal','AnalogReference',1.1)
Updating server code on board Uno (COM9). This may take a few minutes.
a = arduino with properties: Port: 'COM9' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'Adafruit/BNO055', 'I2C'} Show all properties
More About
Code Generation Using MATLAB Function Block
Use
arduino
in a MATLAB Function block with the Simulink® Support Package for Arduino Hardware to generate code that can be deployed on Arduino Hardware.Specifying arguments to create the
arduino
object is not supported in code generation. For more information see Deploy Arduino Functions to Arduino Hardware Using MATLAB Function Block.
Version History
Introduced in R2014b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)