Main Content

Arduino USB, Bluetooth, and WiFi Connection Failure

Arduino USB Connection Failure

Arduino Object Creation Error

When you try to create an arduino object as shown here,

a = arduino() 
you see the following error message,
Cannot detect Arduino hardware. Make sure original Arduino hardware is properly plugged in. Otherwise, please specify both port and board type.

Steps to Resolve the Error

Specify Board Type and Port.  If you see the error Cannot detect Arduino hardware. Make sure original Arduino hardware is properly plugged in. Otherwise, please specify both port and board type, specify the board and type as shown here,

a = arduino('COM4','Uno')

Specify Board Type and Port Correctly.  If you see the error Cannot program board Uno (COM4). Please make sure the board is supported and the port and board type are correct with both board type and port specified:

  1. Make sure that you specify the correct board type.

  2. Make sure the board type is supported. See the full list.

  3. Make sure you are using an FTDI converter to connect the board to computer, if you are using the old ATmega328p board.

  4. Make sure that you specify the correct port. See the Find Arduino Port on Windows, Mac, and Linux for more information.

  5. Open Arduino® IDE (any version supports the board). Make sure you can program the same board under the same port successfully.

If you are using official Arduino boards such as Uno, Mega, Due, Micro and Leonardo, MATLAB® can autodetect the port connected to the hardware on Windows®. However, some Arduino devices are not automatically recognized, especially those that require external FTDI adaptors. In those cases, specify both the port and board type to create a connection.

Remove Bluetooth Device.  If you want the Arduino hardware to communicate with the host computer via a USB cable, remove any Bluetooth® devices connected to your Arduino hardware, and then call the arduino function with appropriate parameters to create your Arduino object.

Install Device Driver.  If you cannot connect to official Arduino hardware, you may be missing the device driver. See Install Hardware Driver to update the hardware driver.

Manual Disconnect.  If you manually disconnect the board before clearing the arduino object from the MATLAB workspace, MATLAB will not recognize the Arduino serial port if you reconnect. Restart MATLAB, and try reconnecting the board.

Turn On the Trace Log.  If you have checked for Manual Disconnect and the issue still persists, turn on the trace log by executing the following command in MATLAB.

a = arduino('COM4','Uno','Trace',true);

The trace log gives a much more detailed output of the compilation and upload results. There are some common possible causes of the error. Depending on what you see in your trace log, try the one that applies.

  • If you see either of these errors in the log, try the appropriate action for your release. For R2015a update the support package to the latest version, or uninstall WINAVR. For R2014a and R2014b, follow these workarounds.

    • C:/MATLAB/SupportPackages/R2015a/arduino-1.5.6-r2/hardware/arduino/sam/cores/arduino/WInterrupts.c:19: 
      fatal error: avr/pgmspace.h: No such file or directory 
      compilation terminated. 
      cs-make: *** [C:/Users/maciej/AppData/Local/Temp/ArduinoServer/WInterrupts.c.o] Error 1
    • C:/MATLAB/SupportPackages/R2014b/arduino-1.5.6-r2/hardware/arduino/avr/cores/arduino/WInterrupts.c -o 
      In file included from C:/MATLAB/SupportPackages/R2014b/arduino-1.5.6-r2/hardware/arduino/avr/cores/arduino/wiring_private.h:33, 
      from C:/MATLAB/SupportPackages/R2014b/arduino-1.5.6-r2/hardware/arduino/avr/cores/arduino/WInterrupts.c:33: 
      C:/MATLAB/SupportPackages/R2014b/arduino-1.5.6-r2/hardware/arduino/avr/cores/arduino/Arduino.h:245:26: error: pins_arduino.h: 
      No such file or directory 
      make: *** [C:/Users/ecsadmin/AppData/Local/Temp/ArduinoServer/WInterrupts.c.o] Error 1"
  • If you see the following error in the log, reinstall the support package. If error still exists, report the bug to MathWorks® technical support.

    In file included from C:/Users/Tom/AppData/Local/Temp/ArduinoServer/Dynamic.cpp:1, 
    from C:/MATLAB/SupportPackages/R2015a/arduinoio/toolbox/matlab/hardware/supportpackages/arduinoio/src/MWArduino.cpp:488: 
    error: Adafruit_PWMServoDriver.h: No such file or directory 
    make: *** [C:/Users/Tom/AppData/Local/Temp/ArduinoServer/MWArduino.cpp.o] Error 1
  • If you see the following error in the log, remove or rename the user-installed Firmata folder that is conflicting with the shipping Firmata library the support package downloads,

    In file included from 
    C:\Users\Max\Documents\Arduino\libraries\Firmata\utility\SerialFirmata.h:30:28: fatal error: 
    SoftwareSerial.h: No such file or directory 
    compliation terminated.

    Look for the location of the Firmata folder to change in the error log. For example, this error above indicates that the Firmata folder to change is "C:\Users\Max\Documents\Arduino\libraries\Firmata". Remove or rename this Firmata folder. Then call arduino in MATLAB again.

    If you still have the same issues, after trying these steps, contact MathWorks Technical Support.

Arduino Bluetooth Connection Failure

To connect to your Arduino hardware using an HC-05 or HC-06 Bluetooth module, make sure you have Instrument Control Toolbox installed.

Test Connection Fails

If the Test connection fails while you are setting up Arduino hardware to use Bluetooth connection in the arduinosetup interface, try the following steps:

  • To ensure that testing connection did not fail intermittently, try to click the Test connection again.

  • If Test connection fails consistently, check that the Bluetooth device appears on the host computer and that it is paired correctly. If not, follow the instructions on Pair a Bluetooth Device and Retrieve the Bluetooth Device Address to pair your device.

  • If you are using HC-05 or HC-06, type instrhwinfo('Bluetooth') in the MATLAB Command Window, and check that the Bluetooth device address appears on the RemoteIDs properties of the object.

Arduino WiFi Connection Failure

If you have configured your Arduino WiFi connection using arduinosetup interface, and if Test connection fails, try the following steps:

  • Select the Retrieve last configuration from Arduino board in the arduinosetup interface, and obtain configuration information from the board.

    • If you are unable to retrieve the IP address from the board, check whether your WiFi network is up and running. Restart and reconfigure the connection using the arduinosetup user interface in MATLAB Command Window. Check that the WiFi connection settings that you specify in the arduinosetup are accurate.

  • Ping the IP address and check whether the address is reachable. To ping the IP address, open a shell window on Windows or a terminal on Linux®/Mac and type, ping followed by the IP address of the device.

    • If the ping test fails, check whether your WiFi network is up and running. Restart and reconfigure the connection using arduinosetup in the MATLAB Command Window. Check that the WiFi connection settings that you specify in arduinosetup are accurate.

    • If you are using static IP address and if the ping test fails, make sure that the specified IP address is available and your network settings allow communication with that IP address.

If you are still experiencing Arduino hardware connection issues, contact MathWorks Technical Support.

Related Topics