View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Embedded Coder Target for Arduino

4.5 | 17 ratings Rate this file 192 Downloads (last 30 days) File Size: 916 KB File ID: #30277 Version:
image thumbnail

Embedded Coder Target for Arduino



03 Feb 2011 (Updated )

Custom target for Arduno and other processors

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

This file exchange submission is an Embedded Coder custom target for Arduino. It uses the Arduino platform as the example hardware, yet the examples it shows can be used to learn and then be applied on any custom target. In an applied way - it shows capabilities and steps that leverage many features of Embedded Coder and creating custom targets. Arduino has been selected since it is widely accessible, has a large DIY community, and is a great platform to explore the varying things that a custom target would need as the various Arduino platforms change.
A custom target author can use this submission to extend/create more Arduino targets, or to simply use this as an example to create your own. An end user that has Embedded Coder can use this submission for their Arduinos.
Some highlights included in this custom target include:
- Shows how to handle dependencies for different Arduino boards (and even non-Arduino boards). Current set includes Uno, Leonardo, Mega2560.
- Options available to drive to minimal footprint and memory
- Processor in the Loop (PIL)
- Numerous scheduling and timing modes explored.
- Overrun detection exposed in the Simulink algorithm directly to allow for algorithmic adjustments when overrun is detected during execution.
- A wealth of examples on how to add/change peripherals blocks/capabilities (LCD, Servo Motor, UART, printf into UART, DIO, Ultrasonic sensor, Async interrupt, I²C Master, I²C Slave, etc, etc).
Additional resources for creating custom targets
- Embedded Coder Product Documentation (account/license required)
- Embedded Coder for Production Code Generation Training Course
- Developing Embedded Targets Advisory Service
- MATLAB Answers: example of developing a custom target
Note: Only Arduino IDE version 1.0.5 is supported and this submission is not maintained to support new IDEs.
For additional Arduino support, see


Device Drivers inspired this file.

This file inspired Embedded Coder Arduino Servo Write Block.

Required Products Simulink Coder
Embedded Coder
MATLAB release MATLAB 8.2 (R2013b)
MATLAB Search Path
Other requirements - Windows 32/64 only
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (88)
03 Jan 2017 Aashifa Rafiq

07 Oct 2016 Art Malyutin

What version of MATLAB is need for run?

Comment only
06 Oct 2016 Art Malyutin

Hello all. I have problem during installation. Matlab displays error

Error using arduino_ec.Prefs.setBoard (line 75)
Unable to find board specification file. Ensure that
the path to the Arduino IDE is set correctly, e.g.

Error in setup_customtarget_arduino (line 34)
arduino_ec.Prefs.setBoard('mega2560'); % Choose a specific board name

Installation is spent on the instructions issued in pdf, pointed the way to a Arduino, name of the platform and port

Comment only
25 Sep 2016 Helmuth


first of all: thanks for this support package.

I do also get timeout error message when PIL simulation is started.

Unfortunately, latest fix described by Tomas does not work for me. Any futher ideas?

Thanks in advance.

Best regards,

Comment only
21 Sep 2016 Tomas

Tomas (view profile)

The reason for hanging PIL is the fact, that Arduino "eats" first byte from UART after reset. So we need to modify function "runAvrDude.m". Look for line ~80 and modify it as follows:

if ~strcmp(arduino_ec.Prefs.getBoard, 'leonardo')
% Reset the board; this is needed for PIL to start it properly!
% Very often Arduino "eats" first byte after flashing

After that, add following function on the end of that file:

function sendDummy(port)
% Send dummy byte to Arduino to re-establish COM port after flashing

% Open the port
lib = 'libmwrtiostreamserial.dll';
portID = rtiostream_wrapper(lib,'open', '-port', port, '-baud', '9600');
if portID == -1
error('Cannot open COM port after target flashing');

% Send the data
[errorCode, dataLength] = rtiostream_wrapper(lib, 'send', portID, uint8('a'), 1);
if errorCode ~= 0
error('Cannot send to COM port after target flashing');

% Close the port
res = rtiostream_wrapper(lib, 'close', portID);

Comment only
26 Aug 2016 HY_360

HY_360 (view profile)

@Matthias Weber
Thank you!

Comment only
07 Jun 2016 Yashar Kouhi

Kemo, could you figure out where the problem is? It seems there should be a problem with rtiostream.cpp file.

Comment only
26 May 2016 kemo

kemo (view profile)

@yashar Kouhi
I had the same problem exactly as you described !!

Comment only
04 May 2016 Yashar Kouhi

Hi, My board is mega2560. I get the following error message when I run the PIL Simulation (myarduino_blink2_PIL), although the code generation has been completed successfully.
"The timeout of 5 seconds for receiving data from the rtiostream interface has been exceed....". I changed the receiving data time several times but did not solve the issue. Can someone help me?


Comment only
28 Apr 2016 Matthias Weber

Hi, I also just downloaded IDE v1.6.8 for testing. boardsFile in Prefs.m needs to be adjusted to find the file:

boardsFile = fullfile(arduino_ec.Prefs.getArduinoPath(), 'hardware', 'arduino', 'avr', 'boards.txt');

Comment only
15 Apr 2016 Carlos

Carlos (view profile)

This package does not seem to work with IDE 1.6.8. as the board files are located in AppData instead of being together with the installation files.

Comment only
08 Dec 2015 fenix.d.0831

sry, can i also use this package on my matlab 2014a?
and i do not know where to put this package.

thx if some one can help.

Comment only
01 Dec 2015 Sm EmbeddedSystem

Dan Lluch, can you gave me you email ?

Comment only
30 Nov 2015 Dan Lluch

Dan Lluch (view profile)

@ Saad - make sure you work through the README.PDF when you first install. The setup script also runs a "build all s-functions" - which generate the required s-functions that are distributed with the target. From the error - it seems that you may not have built them, or added to the path. both of those things are handled via the set up script. good luck.

In case useful - there is a description on the various differences options for arduino here:

Comment only
29 Nov 2015 Sm EmbeddedSystem

when i'm trying to simulate the model i have this problem "Error in S-function 'myarduino_blink2_PIL/Digital Output': S-Function 'sfunar_digitalOutput' does not exist"

Comment only
11 Aug 2015 Neil

Neil (view profile)

Hello Todd,

I've been able to get the embedded support package to work with the latest IDE (1.6.5). What you have to do is find the under the '\arduino_ec' path. Edit this to include the correct file paths within the ARDUINO_INC_LIBS, TARGET_INC_DIR, and TARGET_SRC_DIR variables.The final step is to comment out the lines within the EXTRA_SRCS variables (the new IDE does not use malloc.c, and realloc.c)

So my corrected lines look like:

ARDUINO_INC_LIBS = -I$(ARDUINO_ROOT)/hardware/arduino/avr/libraries/Wire \
-I$(ARDUINO_ROOT)/hardware/arduino/avr/libraries/Wire/utility \
-I$(ARDUINO_ROOT)/libraries/Servo \
-I$(ARDUINO_ROOT)/libraries/LiquidCrystal \
-I$(ARDUINO_ROOT)/libraries/Ethernet \
-I$(ARDUINO_ROOT)/libraries/Ethernet/utility \
-I$(ARDUINO_ROOT)/hardware/arduino/avr/libraries/SPI \

TARGET_INC_DIR = -I$(ARDUINO_ROOT)/hardware/arduino/avr/cores/arduino
TARGET_INC_DIR += -I$(ARDUINO_ROOT)/hardware/arduino/avr/variants/$(VARIANT)

TARGET_SRC_DIR = $(ARDUINO_ROOT)/hardware/arduino/avr/cores/arduino


# Here we add some Arduino library files from different folders
# EXTRA_SRCS = $(TARGET_SRC_DIR)/avr-libc/malloc.c \
# $(TARGET_SRC_DIR)/avr-libc/realloc.c

Pardon the formatting. This setup works for me.

16 Jul 2015 Todd

Todd (view profile)

I was able to use this target for the Zumo32U4, which is an Arduino Leonardo-like board. In fact, I can treat it as a Leonardo within the Arduino IDE without any issues. However, the Simulink support package for Arduino has trouble communicating with the Zumo32U4.

One outstanding problem I have was that part of the board support code does not work with Arduino 1.0.5, and I could not get the Embedded Coder target for Arduino to work with Arduino 1.6.5.

Is there any interest in the Embedded Coder Team in helping me make the target work with Arduino 1.6.5?

Is there any plan to update the Simulink support package for arduino, or this coder target, for Arduino 1.6.5?

Finally, what would it take to add the A-star/Zumo32U4 target to the Simulink support package for Arduino?

Thank you,

29 May 2015 Suytry KY

Anyone know!
I wonder what are the different among Embedded coder target for arduino, ArduinoIO, and Simulink support package for arduino?
Right now, i am confusing with these package, Can anyone here explain me about that please?
Thanks in advance!

Comment only
27 May 2015 Tomas

Tomas (view profile)

The message "S-Function 'sfunar_digitalOutput' does not exist" means that S-Funtions were not created (compiled) during the setup. Please check/pick-up the C-compiler running of:
mex -setup
Then re-compile the S-Functions via script:

After that, in the directory "blocks" should be files with extension ".mexw32" resp. ".mexw64", depending on MATLAB version.

Comment only
24 May 2015 Abubakar Muqaddas

Hi, I am having problem while running the myarduino_blink.slx demo.

My MATLAB version is R2015a, and I am using an Arduino Uno. I ran the file setup_custom_target_arduino.m after changing the relevant directory listing and the arduino version in the m file, and I got the output of Arduino on COM 3, which was correct.

After this, I checked the Simulink Library Browser and I had the Custom C/C++ Target Arduino Library will all its modules. Now when I simulate the model, I get the following error:

Error in S-function 'myarduino_blink/Digital Output': S-Function 'sfunar_digitalOutput' does not exist

Kindly help me out, what could I have done wrong?

Comment only
28 Mar 2015 kemo

kemo (view profile)

Hello every one , i have a simple model that integrates an input signal and it works fine in PIL mode where the integrator part only is coded to arduino , now i want to use the output signal to drive some electronics (servo ,LED) , but i couldn't do that , thanks

Comment only
12 Feb 2015 kemo

kemo (view profile)

thank you Mikhail for your answer , i realized it the hard way , but i have another question :
now my simulation is running "Model block PIL" for some controller on UNO ,i need to output the control action to a servo using "servo block" in the arduino_lib , when i try to add this little part to the "Model block PIL" i end up with an error in the building stage.

14 Jan 2015 Mikhail

Mikhail (view profile)

Scopes only work in simulation part of the model. If you are doing "Top model PIL", scopes will not work, because the whole model is running on target. You should do "Model block PIL" with scopes in higher level model (running in simulation) to observe signals in scopes.

Comment only
14 Jan 2015 kemo

kemo (view profile)

Why scope is not working in PIL mode ,given that the model is running good from Tx&Rx LED

Comment only
30 Jun 2014 Tomas

Tomas (view profile)

When you have message like "... does not exist", it looks that directory "blocks" is not on the MATLAB path. It should be, because it is done in function "setup_customtarget_arduino.m" on first functional line and next this path is saved:
addpath(fullfile(pwd,'arduino_ec'), fullfile(pwd,'blocks'))
result = savepath;
Try to run "setup_customtarget_arduino.m" again.

Comment only
19 Jun 2014 Kirill

Kirill (view profile)

I have some trouble when I try to run simulate/build/flash any model from example (Error in S-function 'myarduino_blink/Digital Output': S-Function 'sfunar_digitalOutput' does not exist). But installation was successful (all path saved in matlab (2014/64). What do I do wrong?

Comment only
26 May 2014 Tomas

Tomas (view profile)

This is strictly AVR-based Arduino with IDE version 1.0.5. This cannot be working with Due because of different MCU, different compiler and mainly, different internal structure of IDE 1.5.x.
If there will be more interest, we can consider port for Arduino Due.

Comment only
25 May 2014 Thomas

Thomas (view profile)

I am trying to use the package with my arduino Due.
In the comments I read, the Arduino 1.5.x is not supported. So I installed 1.0.5 and set the path in the setup file correctly. When I try to build the demo "myarduino_blink.slx" I get the following error:

ompiling: C:/Users/thomas/Desktop/arduino_ec_target/blocks/io_wrappers.cpp
Compiling: myarduino_blink.cpp
unknown MCU 'cortex-m3' specified
Known MCU names:
C:/Users/thomas/Desktop/arduino_ec_target/blocks/io_wrappers.cpp:1: error: MCU 'cortex-m3' supported for assembler only
In file included from c:/arduino/hardware/tools/avr/lib/gcc/../../avr/include/avr/pgmspace.h:82,
from C:/Arduino/hardware/arduino/cores/arduino/Arduino.h:8,
from C:/Users/thomas/Desktop/arduino_ec_target/blocks/io_wrappers.cpp:10:
c:/arduino/hardware/tools/avr/lib/gcc/../../avr/include/avr/io.h:330:6: warning: #warning "device type not defined"
In file included from C:/Users/thomas/Desktop/arduino_ec_target/blocks/io_wrappers.cpp:10:
C:/Arduino/hardware/arduino/cores/arduino/Arduino.h:213:26: error: pins_arduino.h: No such file or directory

Did anybody use this package with the Arduino Due? Please help me on that.

Comment only
07 May 2014 salah tajori

07 May 2014 salah tajori

it's good

02 May 2014 Tomas

Tomas (view profile)

I have never seen before this message. In principal, last task of the makefile (arduino_ec.tmf) is line 248 with this content:
@echo ### Created $(PRODUCT) successfully (or it was already up to date)

The first part of that message is like sign that makefile process went smoothly to the end. There can be stdout flushing problem, e.g. the last part of the text is still in buffer.
Please try following steps:
1. Go to directory with generated code, e.g. it can be like “mymodel_arduino”.
2. Open here DOS command window.
3. Run BAT file like “mymodel.bat” – the name depends on name of the model; there is only one BAT-file. Path to this file cannot be used, DOS window needs to be opened in folder where is the BAT file located.
4. This file was generated and was invoked by Embedded Coder to build the project
5. Observe, if you will see on the last line the messages like “### Created mymodel successfully ...”
6. If you can see that, Simulink is not receiving this part of the message
7. If you not see that, there is issue in template makefile “arduino_ec.tmf”

Anyway, it looks like the HEX file was created, only this message has not arrived to Simulink.

Comment only
25 Apr 2014 Moataz

Moataz (view profile)

Please help on this issue.
### Unable to find build success string.'***Created* in build log.
Can you please help on this

Comment only
24 Apr 2014 Moataz

Moataz (view profile)

Thank you for your reply. I was successful to flash the arduino uno with the myarduino_hc04_test model. However, when I try to build it I get the error message
### Unable to find build success string.'***Created* in build log.
Can you please help on this

Comment only
24 Apr 2014 Tomas

Tomas (view profile)

In my case original model is working, newly created model employing SR04 block from library is working. Problem can appear when original library was manipulated (library itself, S-Function or TLC file). If you want to investigate, look for the file "sfunar_hcsr04.tlc". There is line like:
%assign errTxt = "Unsupported function parameter: %<mode>"
From here you have your error message. You wrote that the message is "untitled_ConstP.HCSR04_p4". This is really strange, because this values is coming from the S-Function as numeric parameter and expected value is between 1 to 3, coming originally from the dialog.
Please check your installation and recompile all S-Functions again.

Comment only
24 Apr 2014 Moataz

Moataz (view profile)

I also want to not that in order to flash my own model to the arduino board, I had to copy and paste the model in the myarduino_hc04_test model and flash it. If I copy the SR04 block into my model, it does not work.

Comment only
23 Apr 2014 Tomas

Tomas (view profile)

The message "Unsupported function parameter" means that Measuring Mode (Raw / Centimeter / Inch) is out of these three values. Please try original model file “myarduino_blink_sr04”.

Comment only
23 Apr 2014 Moataz

Moataz (view profile)

When I try to use the HCSR04 block to download on arduino uno board I get the following error
Error: Simulink Coder Error in block: "untitled/HC-SR04", block type "S-Function": Unsupported function parameter: untitled_ConstP.HCSR04_p4

I'm using 2013b. Please help

Comment only
16 Apr 2014 Tomas

Tomas (view profile)

To Marta: Arduino Version 1.5.x is not supported, you have to use 1.0.5. The reason is that 1.5.x uses different folder structure and header files are on different paths.

Comment only
16 Apr 2014 Tomas

Tomas (view profile)

Most of the new blocks are requiring to use C++ code generation. Please check under "Code Generation" -> "Language" -> "C++".

Comment only
14 Apr 2014 EDUARDO

I recently downloaded the files and i am trying to use some of the examples included, but on many i get this type of error when trying to deploy on an Arduino Uno board.

Error: Simulink Coder Error in block: "myarduino_LCD_LED/LCD Shield", block type "S-Function": Formated LCD output block requires C++

I am currently using the newest version of MATLAB 2014a.

Comment only
11 Apr 2014 Marta

Marta (view profile)

I downloaded and did setup for Arduino Mega 2650. I run through README.pdf file. When I tried to run myarduino_blink.slx I got error message when doing build stage.
Please advise.
Below is the error message.


Compiling: myarduino_blink.cpp
Compiling: ert_main.cpp
In file included from myarduino_blink_data.cpp:16:
myarduino_blink.h:21:21: error: Arduino.h: No such file or directory
gmake: *** [myarduino_blink_data.o] Error 1
gmake: *** Waiting for unfinished jobs....


gmake: *** [io_wrappers.o] Error 1
In file included from myarduino_blink.cpp:16:
myarduino_blink.h:21:21: error: Arduino.h: No such file or directory
myarduino_blink.cpp: In function 'void myarduino_blink_step()':
myarduino_blink.cpp:58: error: 'digitalWrite' was not declared in this scope
myarduino_blink.cpp: In function 'void myarduino_blink_initialize()':
myarduino_blink.cpp:87: error: 'OUTPUT' was not declared in this scope
myarduino_blink.cpp:87: error: 'pinMode' was not declared in this scope
gmake: *** [myarduino_blink.o] Error 1
In file included from ert_main.cpp:16:
myarduino_blink.h:21:21: error: Arduino.h: No such file or directory
ert_main.cpp:20: error: 'uint8_t' does not name a type
ert_main.cpp:21: error: 'uint8_t' does not name a type
ert_main.cpp: In function 'int main()':
ert_main.cpp:34: error: 'init' was not declared in this scope
ert_main.cpp:38: error: 'micros' was not declared in this scope
ert_main.cpp:48: error: 'uOverrunCounter' was not declared in this scope
gmake: *** [ert_main.o] Error 1
### Build procedure for model: 'myarduino_blink' aborted due to an error.

Comment only
24 Oct 2013 Arut

Arut (view profile)

The arduino comunity is growing, so it will be nice to exitend the support also to the OSX platform

10 Oct 2013 Tobias

Tobias (view profile)


I'm trying to run these Embedded Coder Plugin on Matlab2011b with Linux Debian 64bit and Arduino 1.0.5.
I followed the instructions given here in the command section and on the linked websites. But when I'm trying to build the "demo_arudino_blink" model Simulink gives the error:
"makeCmd must default to PC Make command".

In the Matlab Command window I could read:

### Writing header file rtwtypes.h
### Writing source file demo_arduino_blink.c
### Writing header file demo_arduino_blink_private.h
### Writing source file demo_arduino_blink_data.c
### Writing source file ert_main.c
### TLC code generation complete.
### Creating project marker file: rtw_proj.tmw
### Processing Template Makefile: /home/testuser/.Programs/Matlab/simulink_support_package_arduino/arduino/arduino.tmf
### Build procedure for model: 'demo_arduino_blink' aborted due to an error.

so I think the error is caused from an wrong arduino.tmf file. I think the coder is trying to compare the pcMakeCmd with the Arduino makeCmd, but where is the arduino makeCmd located in Linux?

I would appreciate if anyone could help me getting these thing to work.


Comment only
26 Sep 2013 fox tan

@Dan Liuch- thanks for your advice I made a interrupt block after I check out .

Comment only
17 Sep 2013 Dan Lluch

Dan Lluch (view profile)

@fox tan - check out this submission (and contributors taht made other peripherals with it) that may help:

Comment only
14 Sep 2013 fox tan

this is a good package!
but where can get arduino interrrupt block? or who can tell me how to create this block? thanks for you help!

12 Mar 2013 Nathan Crosty

I've gone ahead and created a tutorial for integrating the new Arduino 1.0.3 libraries in with this support package. There are some directions in this post that I have borrowed from to compose it, but I thought it would be useful to keep everything in once place.

Comment only
10 Mar 2013 klob

klob (view profile)


I have a problem using the arduino target.
I am trying to send data via serial communication from a model running on arduino to a model running in my computer.

The problem is that I get wrong values when the data I am about to send are negative (i.e. the transmission is fine when I am sending values 0 or greater but wrong when they are below zero (instead of -4 I receive 252 etc)).
I also tried to send negative values through the example that you have (demo_arduino_serial_communication and demo_arduino_serial_communication_host), by changing the Analog input block with a constant block and once again it works fine when using values zero or greater but I am getting the following error message when I am trying to send negative values through the serial communication.
"Parameter overflow occurred for 'Value'. The parameter's value is outside the range that the run-time data type can represent. The specified value was saturated to the closest representable value. You can control this diagnostic on the Diagnostics pane of the Configuration Parameters dialog."

I thought to try and change something on the Diagnostics pane, but I thought that it would be wiser to ask someone more experienced first.

What do you think?

I have an arduino UNO and MATLAB R2011b.

Thanks in advance,
a desperate student

Comment only
06 Mar 2013 Fabien

Fabien (view profile)

This also works with (at least) Arduino 1.01 on Mac OS Mountain Lion with the fixes by Stefan Disch and at least:

-Set the comport to whatever is stated in Arduino, usually /dev/tty..., the find comport does not work
-Adapt /arduino/+arduino/runAvrDude.m by removing whatever is in between "-P" and "%s" on line 23
-You will get a check for Arduino.exe, which does not exist. Remove it and set the path with arduino.Prefs.setArduinoPath('/Applications/')
-Go to the Arduino folder and copy Arduino.h, name it WProgram.h. (whoever decided this was a good idea..)

Good luck.

01 Oct 2012 Gautam Vallabha

Aditya, the C code for S-functions and corresponding TLC files are in the "blocks" directory. For more info on creating custom blocks: see

Comment only
01 Oct 2012 Aditya

Aditya (view profile)

Is there a tutorial on how to create custom simulink blocks that encode standard arduino libraries, such as the lcd display library? I think you have to create your own s-functions. Also can you expose the s-functions that are behind the included arduino block library - that way other people can build and create new blocks.

Comment only
02 Jul 2012 Jedediah Frey

Jedediah Frey (view profile)

This is very trivial to get working on OS X and Linux too.

@Andrey Zagvazdin: The parsing of boards.txt is horrible. I have a new one that I would like to post however the licensing forbids it. I will work on making a patch file.

Comment only
21 Jun 2012 Mohammad

Has anyone ever try to use the arduino target package on chipkit max32 microcontroller? Or know whether it will support this package?

Comment only
19 Apr 2012 Gautam Vallabha

@ceverus33 question answered at

Comment only
15 Apr 2012 cerverus33

What's the diference with the file "Simulink Support Package for Arduino Uno Hardware"? I'm a little confuse about it

Comment only
30 Mar 2012 MathWorks Classroom Resources Team

General guidelines:
* Please use this FileExchange page to post general comments and ratings on the support package

* If you have questions about using this support package, post your question at (with tag "arduino", and product "Embedded Coder")

Comment only
30 Mar 2012 Gautam Vallabha

Gerald, it has been tested with R2010b. There are no guarantees whether it will or will not work with R2009a.

If you are working with Mega, take a look at the support in R2012a (it only requires Simulink):

Comment only
28 Mar 2012 Gerald

Gerald (view profile)

I just need to know if this support package also works with Matlab R2009a?

I want to do small models in Simulink and flash it to the Arduino Mega 2560 Board. I can just use R2009a!

Comment only
28 Mar 2012 Andrey Zagvazdin

Hello! I MatLAB 7.12 (R2011a) 64-bit. OS Windows 7
Fee clone Arduino, Russian assembly Freeduino (, a complete analog Ardruino Uno / Duemilanove w/ATmega328.
My actions:
1 - Connection "Arduino" to MatLAB
* Set ArduinoIO (;
* Unpack the package into C: \ arduinoIO;
* >> Cd c: \ arduinoIO
* >> Install_arduino
* >> Savepath
* Flashed "Arduino" core srv.pde (;
* >> A = arduino ('COM4');
At this point, everything is OK! From the window MatLAB, board responds and takes command.

2 - Connection "Arduino" to SIMULINK
* Downloading the package Simulink Support Package for Arduino (;
* "Simulink Support Package for Arduino" unpacked to C: \ arduino_simulink
* Downloading Wednesday Arduino IDE (arduino-1.0) and extract it to c: \ ArduinoTarget
* >> Cd c: \ arduino_simulink
* >> Addpath (fullfile (pwd, 'arduino'), fullfile (pwd, 'blocks'), fullfile (pwd, 'demos'))
* >> Savepath
* >> Sl_refresh_customizations
* Plug-in board "Arduino" to your computer.
* Indicates the path to the environment Arduino IDE >> arduino.Prefs.setArduinoPath ('c: \ ArduinoTarget')

That's all up to this point NORMALLY PUT.

* Determine the current platform team
>> Arduino.Prefs.setBoard ('atmega328') or >> arduino.Prefs.setMcu ('atmega328')
Throws an error
>> Arduino.Prefs.setBoard ('atmega328')
?? Reference to non-existent element of a cell
Error in ==> Prefs> Prefs.parseBoardsFile at 227
lhs = parsedLines {i} {1} {1}%
can be of the form xx.yy.zz
Error in ==> Prefs> Prefs.setBoard at 66
boards =
arduino.Prefs.parseBoardsFile (boardsFile);
>> Arduino.Prefs.setMcu ('atmega328')
?? Error using ==> Prefs> Prefs.setMcu at 129
This function is deprecated. Use
arduino.Prefs.setBoard instead, e.g.
arduino.Prefs.setBoard ('uno')


Comment only
16 Mar 2012 Mikhail

Mikhail (view profile)

Thumbs up MathWorks for providing a more free license on this package (as of 14th March 2012 release), allowing to distribute and share the code!
It's a pity though that the contents itself had not been updated for a long time.

Comment only
16 Mar 2012 Nils

Nils (view profile)

14 Mar 2012 Gary

Gary (view profile)

Would like to change the AnalogOut PWM frequency, need to know if changing timer1 & timer2 is safe for integrity of simulink time base (assuming timer0 is used by simulink)?

Comment only
29 Feb 2012 Mikhail

Mikhail (view profile)

Here i added the Servo Write block, which works with motor shield:

You are welcome to incorporate this patch into official package.


Comment only
27 Feb 2012 Nitin

Nitin (view profile)

Is it possible to access the I2C pins (SDA/SCL) via the blockset? If not, would appreciate a workaround!!

Comment only
24 Feb 2012 Mikhail

Mikhail (view profile)

It would be great to have motor shield support, just like in MATLAB support package for Arduino.

Comment only
13 Feb 2012 Gary

Gary (view profile)

Excellent package, works great on my Uno

In the block directory there is an LCDOutput 'S' function can this be made functional & if so how?

28 Jan 2012 Raja Rout

I did'nt find any option for accessing the others serial port.

Comment only
26 Jan 2012 Raja Rout

very very thanks, keep up the good work. It works with 2011a successfully installed. Can we access the extra serial ports of Arduino using this toolbox??.....

19 Jan 2012 Mark

Mark (view profile)

Can this be used to configure pins as interrupts?

09 Jan 2012 Nuri Temurlenk

Do you plan to support Chipkit Max32 kit?

Comment only
03 Jan 2012 Stefan Disch

I also tried fix 2) (using Arduino 1.0).

With Arduino 1.0 there came some changes in naming and layout of the includes (see for details).

I made the following changes to the current version of the arduino target:

1. Edit boards.txt and delete lines 145 through 181 (as told in a previous post)
2. Substitute every occurence of "WProgram.h" with "Arduino.h".
3. Add an additonal include path in rtwmkcfg.m in order to find the "pins_arduino.h" header file (moved to the new variants dir).
4. Commented out line 33 in arduino_smain.tlc because __cxa_pure_virtual is now defined in the Arduino 1.0 libs (see new.h).

These changes allowed me to compile the blink demo without errors.

Comment only
30 Dec 2011 Curtis

Curtis (view profile)

I tried this fix: 1) Use an older IDE (0023)

And everything worked.

Comment only
30 Dec 2011 Curtis

Curtis (view profile)

I tried this fix (2) Edit boards.txt and delete lines 145 through 181 (inclusive).)

And got this error after.

demo_arduino_blink.h:23:22: error: WProgram.h: No such file or directory
gmake: *** [demo_arduino_blink_data.o] Error 1

Comment only
22 Dec 2011 MathWorks Classroom Resources Team

There is a problem parsing hardware/arduino/boards.txt for the latest Arduino IDE (Arduino 1.0). For the time being, try one of the following workarounds:

1) Use an older IDE (0023 or 0022), or

2) Edit boards.txt and delete lines 145 through 181 (inclusive).

Comment only
22 Dec 2011 Sean

Sean (view profile)

I'm getting an error when trying to execute arduino.Prefs.setBoard:

??? Reference to non-existent element of a cell array.

Error in ==> Prefs>Prefs.parseBoardsFile at 227
lhs = parsedLines{i}{1}{1}; % can be of the form xx.yy.zz

Error in ==> Prefs>Prefs.setBoard at 66
boards = arduino.Prefs.parseBoardsFile(boardsFile);

Anyone know why this is?

Comment only
19 Dec 2011 Stephen Williams

Just found the PWM block - it is labeled "Analog Output"

Comment only
19 Dec 2011 Stephen Williams

Please add PWM block

09 Dec 2011 Stefan Disch

Has anyone used it with Arduino version 1.0 so far?

08 Dec 2011 Marcell

30 Nov 2011 Frazer

Frazer (view profile)

Great, thank you for that.

Comment only
30 Nov 2011 MathWorks Classroom Resources Team

The Nov 22, 2011 update is the same as the Nov 29 update (the earlier date is when the file was submitted to FileExchange, the later date is when it got approved and published).

Comment only
29 Nov 2011 Frazer

Frazer (view profile)

Is there a direct link for the Nov 29, 2011 update? I can only find the Nov 22, 2011 update.

Comment only
29 Nov 2011 MathWorks Classroom Resources Team

Note: the latest version of the support package (released Nov 29, 2011) should address the above issues with Uno.

Comment only
28 Nov 2011 Frazer

Frazer (view profile)

Hey guys,

Has anyone had an issue with "multiple main errors, i.e.

main.o: In function `main':
main.cpp:(.text+0x0): multiple definition of `main'

I've followed all the instructions and I've not had any problems using eclipse to compile for my Arduino UNO.

Thanks Frazer

Comment only
20 Nov 2011 Guillaume MARTIN

Thank you Stefan.

I did as you said (but I corrected the baudrate at 155200 in Prefs.m), and it ran.

Thank you very much,

Comment only
18 Nov 2011 Stefan Disch

I needed two changes to get it working in my environment (Win 7, Matlab 2011b, Arduino-0023 Software, Arduino Uno):

- In Prefs.m I changed in the function searchForComPort the string of the device name to '\\Device\\USBSER000'
(Have a look in your registry at HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM to identify the correct string)

- In runAvrDude.m I removed the baudrate option from the avrdude call. (Before it was set to 57600 and it doesn't work)

Best regards

Comment only
11 Nov 2011 Guillaume MARTIN

The baud rate is configured at 57600, but my baud rate is 115200. (So, the upload don't works)

Do you know how to configure the baud rate in :
c:/AARDUI~1/hardware/tools/avr/bin/avrdude -V -F -C c:/AARDUI~1/hardware/tools/avr/etc/avrdude.conf -p atmega328p -P //./COM4 -c stk500v1 -b 57600 -U flash:w:demo_arduino_blink.hex ?

Bests regads,

Comment only
03 Nov 2011 Suleman Shafqat

22 Nov 2011 1.1

Version 1.2.
* Simplified workflow to specify Arduino boards (no need to set MCU and upload rate)
* Support for Arduino Uno & newer boards
* Miscellaneous bug and usability fixes

14 Mar 2012 1.2

Updated title and description

20 Aug 2013 1.4

updated other requirements

28 Mar 2014 1.6

Version 2.0
* complete update to Arduino Embedded Coder target (that can be used to create even other custom targets)
* updated to support more I/O and Arduino platforms
* many examples included

28 May 2014 1.7

- removed Due reference - target doesn't support Due yet.
- added acknowledgement to Device Driver File Exchange submission - as a means to add more peripheral blocks to any target, including this one.

01 Sep 2016

Updated license

06 Jan 2017

Updated license

Contact us