Arduino Nano won't work with simulink Arduino Support Package

17 views (last 30 days)
Hi, I'm trying to connect my Arduino Nano to Simulink using the Arduino Support package, but when i try to upload the program, it shows the following error:
%
Error occurred while executing External Mode MEX-file 'ext_comm':
Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
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.
Component:Simulink | Category:Block diagram error
Unable to connect to the 'Arduino Nano 3.0' target for 'Caracterizacion'.
%
I've already changed the Model configuration parameters to Arduino ano 3.0 I've already set the COM port to the one connected to the Arduino and also I've set the Simulation mode to external.
I know that the Arduino is working because i've tried it using the Arduino IDE, I think the problem is setting the processor (Changed it from ATmega328P TO ATmega328P (old bootloader)), because that's what i had to do in the Arduino IDE in order to make the Nano work, but i don't know how to change the processor from Simulink.
Thanks in advance for any help you can provide.

Accepted Answer

Nicolás Duque Suarez
Nicolás Duque Suarez on 2 Nov 2018
Okay, I think i found the answer!! This issue depends solely on the Arduino board. In my case I was using an Arduino nano with a CH340G chip. The default settings on the simulink package have the baud rate set at 921600 and the Arduino boards that have the CH340G chip can support a maximum baud rate of 230400, then it is necessary to set the baud rate of the simulink model at 230400 or less if the error still appears. This is the link where I found the solution, hope this results useful for you!!
https://la.mathworks.com/matlabcentral/answers/351957-do-simulink-deploy-to-hardware-and-external-modes-work-with-arduino-uno-clones
  2 Comments
Angel Casas
Angel Casas on 4 Dec 2019
En efecto Nicolás, muchas gracias por tu respuesta. En mi caso probé un Arduino NANO (clon) con una velocidad de 230400 Baudios y me funcionó bien.
El comando para checar en que velocidad se encuenra (default External mode baudrate), es;
>> codertarget.arduinobase.registry.setBaudRate (gcs)
Cambié el valor de la velocidad, que se encontraba en 921600, por una de 230400, mediante el comando:
>> codertarget.arduinobase.registry.setBaudRate(gcs,230400).
Jason Wang
Jason Wang on 28 Mar 2020
Edited: Jason Wang on 28 Mar 2020
I've tried this method and it didn't work. Just the commands above? codertarget.arduinobase.registry.setBaudRate(gcs,57600).
Note I am using an official Arduino Nano with the old bootloader set.
See the question I asked here

Sign in to comment.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!