Why am I unable to connect to Arduino in External Mode?

39 views (last 30 days)
When I try to run my model in external mode with Arduino Mega connected, I receive the following error:
### Starting build procedure for model: model1_test 
Code Generation 1 
Elapsed: 1:04 min 
AVR Memory Usage 
Device: atmega2560 
Program: 24764 bytes (9.4% Full) 
(.text + .data + .bootloader) 
Data: 1769 bytes (21.6% Full) 
(.data + .bss + .noinit) 
### Successful completion of build procedure for model: model1_test 
Build process completed successfully 
Attempting to establish connection with hostname '' through port 17725. 
action: EXT_CONNECT 
Component:Simulink | Category:Model 
Error occurred while executing External Mode MEX-file 'ext_comm': 
Failed to connect to the target. Possible reasons for the failure: 
a) The target is not switched on. 
b) The target is not connected to your host machine. 
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target. 
Caused by: 
An error occurred attempting to open an rtIOStream. More detail may be reported in the MATLAB command window 
Component:Simulink | Category:Block diagram error 
Unable to connect to the 'Arduino Mega 2560' target for 'model1_test'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 Mar 2021
Edited: MathWorks Support Team on 9 Mar 2021
As you may observe, the error message provides the likely causes for this error. However, there is an additional cause related to the background daemon that MATLAB uses to establish connection with the Arduino.
The daemon could be timing out before external mode is able to start successfully. The expected time needed to establish connection varies from computer to computer, and as a result, you may need to modify the timeout value to use external mode. Some users have only noticed this error when I2C sensors are connected to the Arduino.
Please follow these instructions to modify the timeout value:
1. Delete the file, which will be located in the following directory within the Support Package Root Directory:
To determine the support package root on your local machine, please execute the following command:
>> SupportPackageRoot = matlabshared.supportpkg.getSupportPackageRoot
For example, if the above command returns "C:\ProgramData\MATLAB\SupportPackages\R2017a\", then the file will be located at:
For more information on this command, please refer to the documentation:
2. Copy the file startDaemon.m (attached) to 
3. Adjust the timeout value for your system by modifying the "ethernetTimeout" variable at line 80 of startDaemon.m and save the file.
4. Run the following commands at MATLAB command prompt:
>> clear classes;
>> clear pcode;
>> rehash toolboxcache
After making these changes, you should be able to run the external mode connection as before. Repeat steps 3 and 4 to tune the timeout value as needed for your system. If the issue persists, please contact technical support .
Xiaoxiao Liu
Xiaoxiao Liu on 29 Sep 2020
hi, i got the same error on ZC706 platform, but i can't find \+registry\startDaemon.p under the folder: <RootDirectory>\toolbox\target\supportpackages\zynq\+codertarget\+zynq.

Sign in to comment.

More Answers (1)

serhat çetin
serhat çetin on 20 Apr 2019
1- Check the baundrate(from device manager)
on the command window;
2- >>codertarget.arduinobase.registry.setBaudRate('untitled',9600)
untitled is sample simulink folder name, write the what your folder name.
9600 is the sample baundrate, write your baundrate.
check the baundrate:
then connect external mode...
good luck


Find more on Introduction to Installation and Licensing in Help Center and File Exchange



No release entered yet.

Community Treasure Hunt

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

Start Hunting!