Code covered by the MathWorks Limited License

Highlights from
MATLAB Support Package for Arduino (aka ArduinoIO Package)

4.28571

4.3 | 30 ratings Rate this file 1726 Downloads (last 30 days) File Size: 170 KB File ID: #32374

MATLAB Support Package for Arduino (aka ArduinoIO Package)

by

 

28 Jul 2011 (Updated )

MATLAB class and Simulink blocks for communicating with an Arduino microcontroller board

| Watch this File

File Information
Description

Arduino (www.arduino.cc) is a low-cost open-source electronics prototyping platform.
MATLAB Support Package for Arduino (also referred to as "ArduinoIO Package") allows you to communicate with an Arduino board over a serial port. It consists of a MATLAB API (really just a class definition file) on the host computer and a server sketch program that runs on the Arduino.

Together, they allow you to access Arduino analog I/O, digital I/O, operate servo motors, read encoders, and even handle dc and stepper motors using the adafruit motor shield, all from the MATLAB command line.

Simulink blocks for communicating with the Arduino are also included.

For more information about the Support Package, see:
 http://www.mathworks.com/hardware-support/arduino-matlab.html

and:
http://www.mathworks.com/matlabcentral/fileexchange/27843-arduino-io-package--slides-and-examples

For Simulink blocks that support code generation, see:
 http://www.mathworks.com/hardware-support/arduino-simulink.html

Sample usage:
-------------

 %-- connect to the board
 a = arduino('COM9')

 %-- specify pin mode
 a.pinMode(4,'input');
 a.pinMode(13,'output');

 %-- digital i/o
 a.digitalRead(4) % read pin 4
 a.digitalWrite(13,0) % write 0 to pin 13

 %-- analog i/o
 a.analogRead(5) % read analog pin 5
 a.analogWrite(9, 155) % write 155 to analog pin 9

 %-- serial port
 a.serial % get serial port
 a.flush; % flushes PC's input buffer
 a.roundTrip(42) % sends 42 to the arduino and back

 %-- servos
 a.servoAttach(9); % attach servo on pin #9
 a.servoWrite(9,100); % rotates servo on pin #9 to 100 degrees
 val=a.servoRead(9); % reads angle from servo on pin #9
 a.servoDetach(9); % detach servo from pin #9

 %-- encoders
 a.encoderAttach(0,3,2) % attach encoder #0 on pins 3 (pin A) and 2 (pin B)
 a.encoderRead(0) % read position
 a.encoderReset(0) % reset encoder 0
 a.encoderStatus; % get status of all three encoders
 a.encoderDebounce(0,12) % sets debounce delay to 12 (~1.2ms)
 a.encoderDetach(0); % detach encoder #0

 %-- adafruit motor shield (with AFMotor library)
 a.motorRun(4, 'forward') % run motor forward
 a.stepperStep(1, 'forward', 'double', 100); % move stepper motor

 %-- close session
 delete(a)

Acknowledgements

This file inspired I2 C Block For Arduino Io Simulink Package.

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (96)
20 Jul 2014 Christian Dachmann

I have an error with the combination Matlab(2010a), Arduino Uno R3, Arduino Motor Shield R3 and this package here. There is a Warnig:
"the sketch running on the Arduino does not support the motor shield. No operation will be performed on the Arduino board"
Did anybody set up the original Motor Shield successfully?

26 Jun 2014 Ana  
21 Jun 2014 EDWIN ALVAREZ

i have solutions for most the problems about matlab and arduino, if u need help with that, write to Giampiero mathworks email or me. it is my page on fb https://www.facebook.com/arduinomatlab

05 Jun 2014 Luis

it have error

04 Jun 2014 Marty Rothwell

Does this IO package include support for ultrasound sensors? My students haven't been able to communicate with ultrasound sensors via matlab.

30 May 2014 Lionel torres

i tried to create a model block with simulink and some elemets of the library, but i cant use a in variable because it keeps giving me this error.

Error due to multiple causes.
* The ArduinoIO library blocks can only handle discrete sample times
* Error evaluating registered method 'PostPropagationSetup' of M-S-Function 'msfun_arduino_digitalwrite' in 'blink_block/Arduino Digital Write4'. The ArduinoIO library blocks can only handle discrete sample times The following is the MATLAB call stack (file names and line numbers) that produced this error:

anyone can help me

30 May 2014 Lionel torres

i tried to create a model block with simulink and some elemets of the library, but i cant use a in variable because it keeps giving me this error.

Error due to multiple causes.
* The ArduinoIO library blocks can only handle discrete sample times
* Error evaluating registered method 'PostPropagationSetup' of M-S-Function 'msfun_arduino_digitalwrite' in 'blink_block/Arduino Digital Write4'. The ArduinoIO library blocks can only handle discrete sample times The following is the MATLAB call stack (file names and line numbers) that produced this error:

anyone can help me

30 May 2014 John

Does not work at all for me:
when i run file "encoder_sim" in this package I got an error : " The corresponding 'msfun_arduino_io_setup.tlc' file for the MATLAB S-function 'msfun_arduino_io_setup' in block 'encoder_sim/Arduino IO Setup' must be located in the current working directory, the MATLAB S-function directory 'C:\Users\QuocToan\Downloads\matlab and arduino\ArduinoIO\simulink', or the directory 'C:\Users\QuocToan\Downloads\matlab and arduino\ArduinoIO\simulink\tlc_c'"

24 May 2014 Alexandru  
14 May 2014 newkid2202

when i run file "encoder_sim" in this package I got an error : " The corresponding 'msfun_arduino_io_setup.tlc' file for the MATLAB S-function 'msfun_arduino_io_setup' in block 'encoder_sim/Arduino IO Setup' must be located in the current working directory, the MATLAB S-function directory 'C:\Users\QuocToan\Downloads\matlab and arduino\ArduinoIO\simulink', or the directory 'C:\Users\QuocToan\Downloads\matlab and arduino\ArduinoIO\simulink\tlc_c'"

how to solve it ? Please

07 May 2014 Yolanda Jiang  
25 Apr 2014 CRVLAB  
21 Apr 2014 Comunity

Is it possible with this support package to control a stepper motors with a different driver board or only with adafruit motor shield ?

10 Apr 2014 Koko

I have tried the source code. I use Arduino uno and ACS712 current sensor. how to improve the current measurement data transmission via the Arduino to matlab? i want the data to be transferred 1 second = 100 data (in Matlab).

09 Apr 2014 Rajeev Yadav

Can we do SPI write?

05 Mar 2014 Panouoilis

Ι Cannot connect my arduino due with matlab. I keep trying to export the adioe.pde to arduino, but i keep gettinh the erros message "Board at COM1 is not available"

Any ideas?

28 Feb 2014 Vanessa

hi, i have 2 other codes aside from adioes and I have to compile the three together as one sketch. how an I do this?

26 Feb 2014 Milan Srndovic

Matlab and Arduino due? Are they compatible? Does anybody know it?
Thank you

17 Feb 2014 ashish arun

every time i run code on simulink(for arduino duemilanove) following error msg will apper
The corresponding 'msfun_arduino_analogread.tlc' file for the MATLAB S-function 'msfun_arduino_analogread' in block 'test1/Arduino Analog Read' must be located in the current working directory, the MATLAB S-function directory '/usr/local/MATLAB/R2011a/bin/ArduinoIO/ArduinoIO/simulink', or the directory '/usr/local/MATLAB/R2011a/bin/ArduinoIO/ArduinoIO/simulink/tlc_c'
please help me

09 Feb 2014 Sanjay Raam

Please try to include Software Serial option into this!

08 Feb 2014 khaled ramadan  
02 Feb 2014 Vanessa

??? Attempt to reference field of non-structure array.

what is this kind of error? i used the digital pin 10 as input. so when i receive 1, my camera triggers and captures. after,pin 9 must output 1. THEN an error occurs:
??? Attempt to reference field of non-structure array.

y???

01 Feb 2014 Vanessa

This package is really awesome and make automation much easier! :)
But, how am I able to compile my .m file with the arduino codes through MCR? It always gives me an error... :(( help

28 Jan 2014 Cristian Ioan  
21 Jan 2014 Stas Diadechko

Excuse me, I have a problem(does not work analog and digital inputs in model of Simulink(Arduino)...constantly shows "0" on Scope( What can I do ??

13 Jan 2014 Anthony Brown

Matlab is the best software tool out there!

27 Dec 2013 nofri andi

why encoder read the value only in steps (-32768 to 32767) via serial port??

24 Dec 2013 Suraj Kamya

Super Like for this package! Work Wonderfully. I tried a lot of others with live update but nothing worked.

23 Nov 2013 UPVM UPVM

please help me, I have this message when I try use the analog input in simulink

The corresponding 'msfun_arduino_io_setup.tlc' file for the MATLAB S-function 'msfun_arduino_io_setup' in block 'arduinouno_servocontrol_potentiometer/Arduino IO Setup' must be located in the current working directory, the MATLAB S-function directory 'E:\Arduino\arduinoIO\simulink', or the directory 'E:\Arduino\arduinoIO\simulink\tlc_c'

13 Nov 2013 MCVN  
06 Nov 2013 Roland

Does the new Version (from 29.Oct 2013) work with the 'official' Motorshield + Stepper Motor? The old one doesn't?

Are there informations how to run the 'official' Motorshield.

thx

07 Sep 2013 Thomas

I have successfully installed all IO files, .pde files, and can connect my arduino (plus motor shield) to matlab. However, when the connection is established, matlab lists off servos 2-69, instead of the 2 associated with my motor shield. Additionally, no commands will operate my stepper, servos or motors (which I have tested in the IDE workspace, they work fine).

Matlab says
EDU>> a=arduino('COM3')
Attempting connection .............
Motor Shield Script detected !
Arduino successfully connected !
But nothing works? Any idea?

28 Jul 2013 Alon

Generally works nicely!

Please note there is problem with MATLAB communication with some Mega boards with un-updated firmware. See here:
http://www.mathworks.com/matlabcentral/answers/40698#answer_92927

10 Jul 2013 Karen Manuel

Hi! I have this project to do but suddenly i encounter this

??? Error using ==> arduino>arduino.arduino at 101
Connection unsuccessful, please make sure that the Arduino is
powered on, running either srv.pde, adiosrv.pde or mororsrv.pde,
and that the board is connected to the indicated serial port. You
might also try to unplug and re-plug the USB cable before
attempting a reconnection.

please help.. thank you.

01 Jul 2013 Bella

Hi, I am trying to run a stepper motor using a seeedstudio motor shield v1.0 paired with an arduino uno, and it is totally fine running the stepper in the arduino IDE but I haven't managed to budge it using MATLAB. I have been successful moving servos and reading analog voltages through MATLAB, so maybe the problem is the motor shield?
Any help would be greatly appreciated!

12 Jun 2013 addie irawan

Dear Sir/Mdm;

I would like to ask, how can I expand the number of pins for each block example Digital Write Block to up to 31 pins. As you know Arduino Mega have 31 pins of Digital IO and 16 A/D pins. The block is limited to 15 pins for Digital Write I/O. Please help me on this because I need more pins for my current project.

Thank you,

A.Irawan

11 Jun 2013 Christopher

OK, found a video that helps figuring it out.

http://www.youtube.com/watch?v=RAkw-lnaZR0

11 Jun 2013 Christopher

Undefined function 'arduino' for input arguments of
type 'char'.

Can't figure out the problem, even after following Gagan's advices.

Please help.

Simulink is working properly!

28 May 2013 Rodrigo R. Oliveira

Installed in my MAC pro, MATLAB R2012b, and Arduino UNO.

23 May 2013 Omar Perez

When Arduino and Matlab work together using the arduino io library. What's the clock speed?

18 May 2013 Dheerendra Rathor

When i start with a=arduino('COM5');
it returns a error
"??? Undefined function or method 'arduino' for input arguments of type 'char'."
i can't figure out why. can anybody help me?

12 May 2013 Jiri Vejvoda  
12 May 2013 Jiri Vejvoda  
06 May 2013 Miguel

it works well, bot sometimes it doesnt recognize any COM port......
A question: someone have tried to send a value of angle to a servo from a variable?

i want to send an angle to a servo, but it changes depending some conditions, so i want to send something like this

target.servoWrite(10,ang);

where"ang" is variable. I have tried to program this, but matlab says it isnt a valid argument.......some ideas?

PD: sorry for bad english

30 Apr 2013 Zhuo Li  
24 Apr 2013 Tracy

Hi all,

Is there a similar srv.pde file for Aeroquad shields instead of Adafruit shields?

Thanks,
Tracy

31 Mar 2013 Hadeel

Hello all , I have this problem please help me
a= arduino('com32')
Java exception occurred:
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.CommPortIdentifier

at com.mathworks.toolbox.instrument.SerialComm.findAllPorts(SerialComm.java:1019)

at com.mathworks.toolbox.instrument.SerialComm.isValidPort(SerialComm.java:540)

at com.mathworks.toolbox.instrument.SerialComm.openHardware(SerialComm.java:373)

at com.mathworks.toolbox.instrument.Instrument.fopen(Instrument.java:1604)

??? Error using ==> arduino>arduino.arduino at 83
Could not open port: com32

thank you

08 Feb 2013 Petteri T

Thanks a lot for providing this package and I did not seem to have any problems with Arduino Uno.

However I was just wondering before getting Leonardo if the Matlab I/O package would work with it as apparently it doesn't behave exactly the same way as the older Arduinos do? Namely in regard to the DtrEnable: http://arduino.cc/forum/index.php?topic=140090.0

30 Jan 2013 Dilip Aldar

THe Error and warning occurred while onnecting arduino: Warning: Unsuccessful read: A timeout occurred before the Terminator was reached. Error using arduino (line 101) Connection unsuccessful, please make sure that the Arduino is powered on, running either srv.pde, adiosrv.pde or mororsrv.pde, and that the board is connected to the indicated serial port. You might also try to unplug and re-plug the USB cable before attempting a reconnection.

27 Jan 2013 Kevin

??? Error using ==> arduino>arduino.arduino at 103
Connection unsuccessful, please make sure that the Arduino is powered on, running either
srv.pde, adiosrv.pde or mororsrv.pde, and that the board is connected to the indicated
serial port. You might also try to unplug and re-plug the USB cable before attempting a
reconnection.

Error in ==> ard at 1
a=arduino('com7')

Now I have this error, tried changing the adiosrv code but doesn't help, any help would be appreciated

25 Jan 2013 Kevin

??? Error using ==> arduino
Error: File: arduino.m Line: 1 Column: 10
A class definition must be in an "@" directory.

I have this error on my matlab which is MATLAB R2010b when i run a=arduino('COM7')

please help

08 Jan 2013 Gagan

Hi YXING,
here are the solution:
1.In matlab use[ tic
while(pingpin~=1)
toc]
this will give u the elapsed time till pingpin goes high.
2.Use SD card shield to record the data and plot it if u don't need to plot it realtime. if u require real time plot then go for 1.
3.This method is the alternative of 2 without using sd card shield and is 'JUGAD' method. serial print the distance data in the monitor.once u r done copy paste it as a variable in matlab and do synthesis or analysis whatever u want.
HOpe this will prove helpful for you

07 Jan 2013 YXING

I am using a ultrasonic distance sensor in my project and it seems that the ArduinoIO Package doesn't support it. Reading the sensor requires the "pulsein" function, which seems not available in the Matlab environment. Any possible solution?
P.S. I need to control DC motors (using PWM) according to the distance read from the sensors. At the same time, the distance data needs to be taken down, analyzed and used to draw graph so Matlab seems essential.

14 Dec 2012 Ejri

I am working on a project to run 2 stepper motors simultaneously using Matlab. I was able to run the 2 motors in Matlab using an Uno and a motorshield (after uploading the srv.pde. The srv.pde is required for the shield to work in my case.), but I wasn't able to run the motors simultaneously.

I tried I2C with an another Uno and using the Wire library (http://arduino.cc/en/Tutorial/MasterWriter) in addition to the AccelStepper library, I was able to run the motors simultaneously using the Arduino 1.0.2 software.

Is there a way of adding the Wire and AccelStepper libraries to the srv.pde so that I can use I2C and AccelStepper in Matlab?

Is there another way of running 2 motors simultaneously using Matlab?

Thank you

25 Nov 2012 Angus  
21 Nov 2012 Merlin Mifsud

Dear all,
I had some mistakes regarding previous comment.

I want to interface an adis16480 IMU sensor with matlab, however this is not possible using the ug-287 evaluation board.

1)Now I am wondering if it is possible to read spi ports using arduino and read from arduino using matlab in real time?

2)And how possible it is to write and read from Maltab to the Spi Ports of the ADIS16480 (through arduino)?

3)Should I use arduino uno, Duemilanove or MEGA 2560 for simplest communications between ADIS16480 spi ports and matlab?

many thanks :)

21 Nov 2012 Merlin Mifsud

Dear all,
I want to interface an adis16480 IMU sensor with matlab, however this is not possible using the ug-287 evaluation board.

1)Now I am wondering if it is possible to read serial ports using arduino and read from arduino using matlab in real time?

2)And how possible it is to write and read from Maltab to the Serial Ports of the ADIS16480 (through arduino)?

3)Should I use arduino uno, Duemilanove or MEGA 2560 for simplest communications between ADIS16480 serial ports and matlab?

many thanks :)

11 Nov 2012 Rodolfo Buschle

Hello all,

I'm running Arduino IO with an Arduino MEGA 2560.
I need 16 analog ports, however I can only access ports 0 to 5...

Anyone knows how to solve this issue?
This is the error message I get:
"Error using arduino/analogRead (line 499)
Unallowed value for analog input pin number, the value must be an integer going from 0 to 5"

10 Nov 2012 Gagan

HI ZHU

There might be three things gone wrong with you
1.Check the right COM port in device manager
2.Define a variable for your arduino...like a=arduino('COM3')
3.The IDE must be closed or disconnected so that MATLAB can use the serial connection.

Hope this will be beneficial for you...GUD LUCK and enjoy support package its really good stuff.

10 Nov 2012 Gagan

HI ZHU

There might be three things gone wrong with you
1.Check the right COM port in device manager
2.Define a variable for your arduino...like a=arduino('COM3')
3.The IDE must be closed or disconnected so that MATLAB can use the serial connection.

Hope this will be beneficial for you...GUD LUCK and enjoy support package its really good stuff.

09 Nov 2012 zhu

I installed the arduino on windows xp. And I followed the steps to install the arduino package in Matlab. "install_arduino" works fine. "arduino('COM3')" always fail. It said that "Undefined function or variable 'private'. "

Andy body know what's wrong with it?

Thank you so much!

25 Oct 2012 Alan Chen

Very very useful for the arduino's increasing capabilities!

17 Oct 2012 fabius

very usefull for arduino increasing capabilities.
The only limit of this project is a better serial communication (still too many errors serial port controls)

14 Sep 2012 Chien-Hung Lin

When I use a=arduino('COM6')
to connect arduino by matlab2010a, but error. What problem is it? The board is OK?

>> a=arduino('COM6')
Attempting connection .............
Warning: A timeout occurred before the Terminator was reached.
??? Error using ==> arduino>arduino.arduino at 101
Connection unsuccessful, please make sure that the Arduino is powered on, running either srv.pde, adiosrv.pde or
mororsrv.pde, and that the board is connected to the indicated serial port. You might also try to unplug and
re-plug the USB cable before attempting a reconnection.

05 Sep 2012 Suhaib  
05 Sep 2012 Suhaib

hi,thank you for this update. but i cant see any change of "digital write and read .... analog write and read " in the simulink library ..it supports the same pins as previous versions. thank you ^^

19 Aug 2012 Manko

Hi. I just recently started to play with the Arduino Uno. I have a problem where whenever I try to close the session, I get a "segmentation violation detected" error. Does anyone have any insights to this problem? I am using MBP lion and Matlab 7.8.0

I tried delete(a) and delete(instrfind({'port'},{/dev/tty.usbmodem1d11'})) but both gave the same error message

18 Aug 2012 Prem

Everything works for me. There are limitations but it is cool.

26 Jul 2012 Sanchitha wijayawardhana

Hello
I successfully used this support package.My problem is,how to use this support package for another code in another path.When i used this package for another code,it gives the following error

??? Error using ==> install_arduino at 15
There is at least another arduino.m file in the path, please delete any other versions
before installing this one

Do i have to delete all the support package .m files in the existing path to work with a new code in a different path???

16 Jun 2012 fabius

I had a problem timeout and error communication.
I use Arduino duemilanove (ATMEGA 168)

I fixed this issue by changing ADIORSV:PDE on line 40, where there is a cicle for 20 PINS (insetad of 13 of Arduino Duemilanove).

i posted better explanation on my own question about, Here:
http://www.mathworks.com/matlabcentral/answers/40698-error-timeout-communication-matlab-arduino-in-support-package-for-arduino-aka-arduinoio-package

07 Jun 2012 Hernan

Hello, I was wondering if the arduino io would work with the liquid crystal library for the Arduino? I am trying to display a message from matlab on an LCD using the arduino.

25 May 2012 Jean-Marc ALLENBACH

I successfully used Arduino I/O with MATLAB R2009b. Only some Port COM problems due to XP platform: return to default port number after a deconnexion of Arduino board.

25 May 2012 Jean-Marc ALLENBACH

I successfuly used Arduino with R2011a

I tried the same in the classroom with R2007b
No problem with install_arduino, but with
arduino('COM5') I received an error message:
??? Error: File: arduino.m Line: 6 Column: 35
Undefined function or variable 'private'.

Error in ==> StartArd at 10
a=arduino('COM5')
Is it possible to solve the problem on this version R2007b of Matlab or have I to take time to install R2012a on all classrooms?

17 Apr 2012 Muhammad Adeel khan

hello
i am trying to control the motion of a motor by using simulink blocks(of arduino matlab support package).i need an encoder(position) input as feed back in my control model.
can any one help me how can i read encoder value in my control model?

10 Apr 2012 Nancy

Can I control a servo motor from Matlab without using a motor shield
I tried to use this code:

a=arduino('COM3');
a.pinMode(10, 'OUTPUT');
a.analogWrite(10, x); % where x= from 0 up to 255

but it did not work
can anyone help me??

05 Apr 2012 Gautam Vallabha

Abhineet, please post your question at http://www.mathworks.com/matlabcentral/answers, as noted above. I will be happy to answer it there.

04 Apr 2012 Abhineet Mishra

Hello
First of all I must thank you for providing us with such a nice interface between MATLAB and Arduino.
Actually I was wondering if you have any function like Arduino's 'MAP' function which can actually map analoginput data into a specific range.
Thanks in Advance

03 Apr 2012 MathWorks Classroom Resources Team

General guidelines

* Please use this FileExchange page for general comments and ratings on the support package

* If you have questions about using this support package, post your question at http://www.mathworks.com/matlabcentral/answers (with tag "arduino", and product "matlab")

03 Apr 2012 Gautam Vallabha

Jose: The readme.txt file included with the support package has instructions for how to modify the code to work with Arduino Mega (search for "ARDUINO MEGA" in the readme.txt).

03 Apr 2012 José Antonio Segura

Hello.

I'm actually using and Arduino Mega 2560 and API_Matlab. But I have a problem, I cant's access to all PWM outputs, because the library just recognize as PWM the digital pins 3 5 7 9 10 and 11, that are the PWM pins of Arduino Uno Board.

Did you know how can I access to all PWM pins of Arduino Mega 2560?

25 Mar 2012 Andrey Zagvazdin

Hello! I MatLAB 7.12 (R2011a) 64-bit. OS Windows 7
Fee clone Arduino, Russian assembly Freeduino (http://freeduino.ru/arduino/index.html), a complete analog Ardruino Uno / Duemilanove w/ATmega328.
My actions:
1 - Connection "Arduino" to MatLAB
* Set ArduinoIO (http://www.mathworks.com/matlabcentral/fileexchange/32374);
* Unpack the package into C: \ arduinoIO;
* >> Cd c: \ arduinoIO
* >> Install_arduino
* >> Savepath
* Flashed "Arduino" core srv.pde (https://github.com/adafruit/Adafruit-Motor-Shield-library/zipball/master);
* >> 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 (http://www.mathworks.com/matlabcentral/fileexchange/30277);
* "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
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);
>> 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')

TRIED TO IGNORE THIS OPTION AND KEEP SETTING, BUT IN MODELING, DEMANDS categorically specify the model.

22 Mar 2012 MathWorks Classroom Resources Team

Alex, thanks for the feedback, i'll think about it.

Abdullah, it's because the servo methods were made to support the adafruit motor shield, which only supports servo connected to pins 9 and 10. I will remove this limitation sometime this summer. However if you look at the code it should not be too hard to modify it to extend it to 6 servos.

20 Mar 2012 Abdullah CAKAN

why ı can connect servo just pin 9 and 10. I have 4 more pwm pin.. ? anyone can edit the files and blocks to add 6 servos to the arduino.

23 Feb 2012 alexander

using a.stepperStep() has a maximum number of steps of 255 and causes unexpexted results with for loops. How can i avoid this and get the number of steps i want.

10 Jan 2012 Giampiero Campa

UPDATE: in the new version (3.2) the problem due to the fact that INTERNAL is not declared for the MEGA has been solved (basically now there is a macro that defines INTERNAL as equal to INTERNAL1V1 when compiling for the MEGA).

Please consider downloading the last version if you often switch between the UNO and MEGA boards.

09 Jan 2012 Gautam Vallabha

Sun, the MATLAB Support Package does not support code generation. The included Simulink blocks communicate with the Arduino in Simulink "normal" (aka. simulation) mode only.

For blocks that support code generation, see http://www.mathworks.com/academia/arduino-software/arduino-simulink.html

08 Jan 2012 Sun

Hello
When I try to call block analogread, everytime I build will pop:

The corresponding 'msfun_arduino_analogread.tlc' file for the MATLAB S-function 'msfun_arduino_analogread' in block 'test1/Arduino Analog Read' must be located in the current working directory, the MATLAB S-function directory 'C:\Users\Julio\Documents\MATLAB\ArduinoIO\simulink', or the directory 'C:\Users\Julio\Documents\MATLAB\ArduinoIO\simulink\tlc_c'

and I ingnore it matlab just quit. Even the demo cannot work. Anyone has ideas?

Julio

20 Dec 2011 Alonso

For the INTERNAL problem with the mega2560 I found this: http://arduino.cc/en/Reference/AnalogReference

INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)

So just replace "INTERNAL" with "INTERNAL1V1" and it should work.

09 Dec 2011 Sotiris

Hello everyone, I am trying to Upload,"adiosrv.pde" on the arduino mega2560 but I get the following message:

"adiosrv.cpp: In function 'void loop()':
adiosrv:239: error: 'INTERNAL' was not declared in this scope"

Any suggestions??

Thank you in advance

07 Dec 2011 Michael

This is a total hack, but for those of you who are getting 'Connection unsuccessful' error and are sure that the serial port is working fine (i.e. by checking it with a program like TeraTerm and typing in '99') then you can set chk to be 1 (or 2 or 3), depending on which pde you had uploaded into the Arduino.

% query script type
fwrite(a.aser,[57 57],'uchar');
chk=fscanf(a.aser,'%d');
chk = 1; % SHOULDN'T HAVE TO DO THIS!

06 Dec 2011 JULIO DE LUNA

I had the same problem, all we did was add a / * in
/ * Case 49:
analogReference (INTERNAL);
break;

then, I had no problems =)

05 Dec 2011 Fardin

I am having problem with loading the srv.pde file to Arduino Mega 2560.
When compiling, the error is on line 553:
analogReference(INTERNAL);
and the error message is:
srv.cpp: In function 'void loop()':
srv:552: error: 'INTERNAL' was not declared in this scope

I have done all the steps before this step.
Please Help. And thanks in advance.

07 Nov 2011 Roman

I have installed all packages for Arduino support. In Matlab command line can successfully connect to Arduino and operate all its pins.

I want to use function msfun_arduino_analogread(block), link:
http://www.mathworks.com/matlabcentral/fileexchange/32374-matlab-support-package-for-arduino-aka-arduinoio-package/content/simulink/msfun_arduino_analogread.m

But when add in Simulink block "Level-2 MATLAB S-Function" I have the following error (screen shot): http://habrastorage.org/storage1/fdff41a7/f8668eac/77eb249a/38eb67f6.png

Can I go another way to read data from Arduino in Simulink? I just want to use my Arduino as Analog Input in Simulink.

30 Oct 2011 Tony Stark

Your problem seems like the one I ran into as well. What I did was double check my COM port in device manager. Opened up matlab and clicked in the "Current Folder" pane, navigated to where I unzipped the "ArduinoIO" package, right clicked the folder and added it and its subdirectories othe path, then execute the "savepath" command.

If that doesnt work, force your COM port to be COM8 or COM5. Also run matlab as admin (SHIFT + Right Click "Run as Adminstrator")

26 Oct 2011 Ernesto

I've been following the steps on the Readme file. I already added the arduino folders path successfully. Now I'm trying to run the a=arduino('port') in my case COM4 and I get the error:

??? Error: File: xx/xx/xx Line: 6 Column: 26
The expression to the left of the equals sign is not a valid target for an assignment.

Does anyone know what might be going wrong? I already also tried a=arduino('/dev/ttyUSB0') instead of COM4 but I got the same error.

09 Oct 2011 Cameron  
Updates
18 Aug 2011

* Minor changes to readme, Simulink example models, and .pde files
* Added images for Simulink model preview

26 Oct 2011

Minor fixes to demo mode for servo handling

24 Dec 2011

Minor fixes and improvements, mainly for the MEGA and ChipKIT32 boards.

04 Sep 2012

1) Simulink library now handles pre-existing Arduino objects
2) MEGA board fully supported
3) Servo support greatly improved
4) Full encoder support
5) Example function for customization
6) Assorted minor improvements

17 Oct 2012

Encoder debouncing function added

29 Oct 2013

Reorganized sketch handling and examples, improved docs and added support for Adafruit Motor Shield V2.

21 Jul 2014

Improved handling of mega-related pins from Simulink ADIO blocks. Also added instruction (in the readme.txt file) on how to use the official stepper.h Arduino library with this package.

Contact us