Communication test failure when setting up MATLAB Support Package for Arduino Hardware

14 views (last 30 days)
I am trying to connect MATLAB to an Arduino uno and turn on the LED. The communication test during setup of the MATLAB Support Package for Arduino Hardware fails and I am stuck. I ignore it and complete the setup, but when I run the following command, an error occurs:
>> a = arduino('/dev/cu.usbmodem101','Uno')
Error using: arduino
Too many input arguments.
>> a = arduino('/dev/cu.usbmodem101')
java.lang.NullPointerException thrown while loading gnu.io.RXTXCommDriver
java.lang.NullPointerException thrown while loading gnu.io.RXTXCommDriver
java.lang.NullPointerException thrown while loading gnu.io.RXTXCommDriver
Can't open: Port: /dev/cu.usbmodem101 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Error using: arduino (line 83)
Could not open port: /dev/cu.usbmodem101
Writing from ArduinoIDE is possible, and the LED in the sample sketch can be lit. The port name specified in ArduinoIDE and the port name written in the above command match. The operating environment is as follows.
MacOS Sequoia ver15.3
Arduino Uno R3
I would appreciate any advice on how to solve this problem.
  1 Comment
Shota Okawa
Shota Okawa on 10 Apr 2025
I solved it myself.I reinstalled Matlab 2020a and added in Legacy MATLAB and Simulink Support for Arduino.I did not use the MATLAB Support Package for Arduino Hardware.As a result, I am now able to light up the LED in response to commands.

Sign in to comment.

Answers (1)

MathWorks MATLAB Hardware Team
Hi ,
  • MATLAB Support Package for Arduino Hardware should be fully compatible with MATLAB R2020a, and it is the recommended solution over the legacy support package.
  • Installing the legacy support package is generally not necessary and may lead to compatibility issues .
Based on your description, the error messages indicate that MATLAB is unable to access the serial port (/dev/cu.usbmodem101) used by your Arduino. Here are some steps you can follow to resolve this:
1. Verify the Serial Port
  • Make sure your Arduino is connected and visible to your Mac.
  • You can check available serial ports in MATLAB using serialportlist:
serialportlist
  • Ensure that /dev/cu.usbmodem101 appears in the output. If not, try reconnecting your Arduino or using a different USB cable/port.
2. Test Serial Communication
  • Before using the Arduino support package, test if MATLAB can open the port using serialport:
s = serialport('/dev/cu.usbmodem101', 9600)
  • If this fails, another application (such as the Arduino IDE) may be using the port. Close any such applications and try again.
3. Reinstall the Official Support Package
  • Uninstall any legacy Arduino support packages.
  • Reinstall the official MATLAB Support Package for Arduino Hardware via: Home > Add-Ons > Get Hardware Support Packages
  • Follow the guided setup to completion.
4. Retry the Connection
  • Try connecting with:matlabCopy codea = arduino('/dev/cu.usbmodem101', 'Uno')
5. Further Assistance
Recommendation:
For best results and future compatibility, always use the official MATLAB Support Package for Arduino Hardware rather than the legacy support package.
Best regards,
MATLAB Hardware Team
MathWorks

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!