Code covered by the MathWorks Limited License

Highlights from
MATLAB Support for Arduino (aka ArduinoIO Package)

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

MATLAB Support 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.
For new projects using R2014a or higher, it is recommended that you use the MATLAB Support Package for Arduino hardware which can be downloaded here from this link:

http://www.mathworks.com/matlabcentral/fileexchange/47522

For projects based on R2013b or earlier, use this submission.

MATLAB Support for Arduino avaialble with this submission (formerly "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 Arduino Support, see:
 http://www.mathworks.com/hardware-support/arduino-matlab.html

For more infromation about the supported provided with this submission, see:

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 (122)
06 Apr 2015 zyselvis

Have installed the package, but still can not use the arduino functions. Do not know why

Comment only
04 Apr 2015 Sergei Paleichuk  
01 Apr 2015 gayathri raghu

can't download support file please send us the download link

Comment only
17 Mar 2015 heisenberg

how to do transmit serial data using .pde file and matlab gui?

Comment only
11 Mar 2015 Roberto Laso Gutiérrez

It is possible to send a Matlab variable through serial port for having Arduino taking decisions depending of the value of this variable (that btw, it changes with the time)?

Comment only
21 Feb 2015 brandon leshchinskiy

When I input

a = arduino('COM3');

I get the following error message:
Warning: Unsuccessful read: A timeout occurred before the Terminator was
reached.
Error using arduino (line 104)
Connection unsuccessful, please make sure that the board is powered on,
running a sketch provided with the package, and connected to the
indicated serial port. You might also try to unplug and re-plug the USB
cable before attempting a reconnection.

I've tried using different USB ports, and I'm not sure what else to do. Any help would be much appreciated, thanks!

Comment only
17 Feb 2015 Jason

Jason (view profile)

Major problem!

When I install the arduino HW package for Matlab it works fine for me but not for anyone else. Since these are lab PCs many students use them. So the install has to work for all users.

This is needed. However to make matters worse, by installing the arduino software it has messed up the path file. So now when anyone other than me tries to use Matlab at all it comes up with an error (serious) and then requires them to re-run the defaultpath command to run at all.

So in short, by me installing the arduino package has broken all the lab PCs now. Please tell me how to install the arduino so that all users can use it without breaking the path.

Help!

Comment only
11 Feb 2015 chfakht chfakht

when i'm trying to establish a connection it didn't work

>> a = arduino
>> Undefined function or variable 'arduino'.

help plzz

Comment only
06 Feb 2015 chfakht chfakht

you must add the package to matlab path :)

Comment only
04 Feb 2015 OLGA Jumbo Sanchez

I am having problems with rotating a servo and acquiring values from a sensor at the same time. If I do not use the servo, the analog readings are accurate, but once I attach it, the sensor data shows only noise. Help please?

Comment only
04 Feb 2015 chfakht chfakht

please i need an example for the MPU6050 : reading values with arduino and plotting them in real time in matlab

Comment only
22 Jan 2015 Andrew Teh

Do you know the function to change the timer frequency of Arduino Leonardo or any function that can change the frequency of PWM of Arduino? Because I want to change the frequency of PWM signals that Arduino sends out to other devices. Thanks.

Comment only
18 Jan 2015 sagie meshulam

hello, im working on a project with matlab and arduino+adafruit motor shild; to control a stepper motor.
i've conected to the arduino board thorow to arduino software and succeed to contorl the motor.
my problem is when im using matlab code to control the motor i get this

a = arduino('COM4');
Attempting connection ................
Basic I/O Script detected !
Arduino successfully connected !

but what i really need is to conect with the adafruit motor shild and what i get is

a = arduino('com4', 'uno', 'Libraries', 'Adafruit\MotorShieldV2');
Error using arduino
Too many input arguments.

can someone help me?

Comment only
28 Dec 2014 Andrew

Andrew (view profile)

I tried to use the package on R2012a, with a UNO R3. The following script just leads to the built in LED on pin 13 being always on when I run the script however if I go into debug mode and step through the script then the LED turns on and off as you would expect as you execute the lines one by one. The Rx LED flashes approximately once per second when the script is running.

Can anyone tell me why the LED doesn't flash on and off once per second for 60 seconds when I execute the script? thanks.

% create arduino object and connect to board
if exist('a','var') && isa(a,'arduino') && isvalid(a),
% nothing to do
else
a=arduino('DEMO');
end

% specify pin mode for pins 13
a.pinMode(13,'OUTPUT');

tic
while toc/60 < 1
% toggle the digital value of pin 13 LED
a.digitalWrite(13,1);
pause(1);
a.digitalWrite(13,0);
end

Comment only
01 Dec 2014 John Hedengren

We used MATLAB and an Arduino UNO (Ruggediuno) for our process control lab starting in 2013. We built 40 lab kits for ~$50 each and distributed them to students. Below is a link to our source code for the lab.

https://www.mathworks.com/matlabcentral/fileexchange/48016-arduino-matlab-process-control-lab

The lab is featured in the December issue of CACHE news. The article includes a number of lessons learned with regards to improving student experience. It was a positive experience the second year (2014) after we worked out some important details.

http://apmonitor.com/che436/uploads/Main/Hands_on_Process_Control_CACHE.pdf

We're interested in continuing to improve the Arduino lab. Please contact me with any suggestions on additional modules related to Process Dynamics and Control: john.hedengren@byu.edu.

23 Nov 2014 Eduardo

I just installed the package but I keep getting this error whenever I try to use it:

EDU>> a = arduino();
Updating server code on Arduino Uno (COM5). Please wait.
Cannot program Arduino board Uno (COM5). Please make sure the board is supported and the port and board type are correct.

Do I still need to install something else?

Comment only
07 Nov 2014 Tristan Beau

Under MacOSX 10.10 and matlab 2011b, I didn't succeed in connecting the arduino whereas it works with the arduino SDK using the port. I got the error :

>> a=arduino('/dev/tty.usbmodem1421')
Attempting connection .............
Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.
Error using arduino (line 104)
Connection unsuccessful, please make sure that the board is powered on......

Any idea ?

Comment only
04 Nov 2014 Ole

Ole (view profile)

Is there a way to control PWM duty cycle of voltage?

Comment only
17 Oct 2014 Flo20

Flo20 (view profile)

When I try to find the arduino on the serial port with:

a = arduino('COM 5', 'uno')

I get the following message.

Unable to load a message catalog 'MATLAB:arduinoio:general'. Please check the file location and format.

I already reinstalled matlab and all the packages, but still the same issue occurs.

Anyone with a solution?

Thanks in advance!

Comment only
10 Oct 2014 Isa

Isa (view profile)

Hi, I was wondering if the Arduino IO package also allows me to use a Arduino library such as AccelStepper? If so do I have to take care of anyting special while installing Arduino IO, for example a special pde file? Thanks in advancefor your help!

Comment only
04 Sep 2014 wayan

wayan (view profile)

need help..

Error evaluating registered method 'Start' of MATLAB S-Function 'msfun_arduino_io_setup' in 'library_test/Arduino IO Setup'. The following is the MATLAB call stack (file names and line numbers) that produced this error:
['D:\Documents\Arduino\ArduinoIO\arduino.m'] [104]
['D:\Documents\Arduino\ArduinoIO\simulink\msfun_arduino_io_setup.m'] [76]

Caused by:
Connection unsuccessful, please make sure that the board is powered on, running a sketch provided with the package, and connected to the indicated serial port. You might also try to unplug and re-plug the USB cable before attempting a reconnection.

Comment only
20 Aug 2014 Dylan

Dylan (view profile)

I can't get any of these blocks to work for me. I'm running Matlab 2013b and using an Arduino Mega 2560. Any help? every time I try running one of the Simulink Blocks I get the following:
" 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,...

Comment only
11 Aug 2014 Nick

Nick (view profile)

Trying to incorporate the support package with Max32 ChipKit, carried out simple initial set-up. In MATLAB returns;

>> a=arduino('com6')
Attempting connection .............
Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.
Error using arduino (line 104)
Connection unsuccessful, please make sure that the board is powered on, running a
sketch provided with the package, and connected to the indicated serial port. You
might also try to unplug and re-plug the USB cable before attempting a
reconnection.

Any help?

Comment only
07 Aug 2014 Colm

Colm (view profile)

Very good program but having trouble driving 2 motors simultaneously using adafruit motor shield. Can anyone help me out?

06 Aug 2014 Mahmoud Gaber

i just wanted to participate, it's so useful

Comment only
30 Jul 2014 Felipe Martins

Great package! Thanks a lot!

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?

Comment only
26 Jun 2014 Ana

Ana (view profile)

 
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

Comment only
05 Jun 2014 Luis

Luis (view profile)

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.

Comment only
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

Comment only
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

Comment only
30 May 2014 John

John (view profile)

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'"

Comment only
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

Comment only
07 May 2014 Yolanda Jiang  
25 Apr 2014 CRVLAB

CRVLAB (view profile)

 
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 ?

Comment only
10 Apr 2014 Koko

Koko (view profile)

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).

Comment only
09 Apr 2014 Rajeev Yadav

Can we do SPI write?

Comment only
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?

Comment only
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?

Comment only
26 Feb 2014 Milan Srndovic

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

Comment only
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???

Comment only
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

Suraj Kamya (view profile)

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'

Comment only
13 Nov 2013 MCVN

MCVN (view profile)

 
06 Nov 2013 Roland

Roland (view profile)

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

Comment only
07 Sep 2013 Thomas

Thomas (view profile)

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?

Comment only
28 Jul 2013 Alon

Alon (view profile)

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.

Comment only
01 Jul 2013 Bella

Bella (view profile)

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!

Comment only
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

Comment only
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!

Comment only
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?

Comment only
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?

Comment only
12 May 2013 Jiri Vejvoda  
12 May 2013 Jiri Vejvoda  
06 May 2013 Miguel

Miguel (view profile)

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

Zhuo Li (view profile)

 
24 Apr 2013 Tracy

Tracy (view profile)

Hi all,

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

Thanks,
Tracy

Comment only
31 Mar 2013 Hadeel

Hadeel (view profile)

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

Comment only
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

Comment only
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.

Comment only
27 Jan 2013 Kevin

Kevin (view profile)

??? 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

Comment only
25 Jan 2013 Kevin

Kevin (view profile)

??? 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

Comment only
08 Jan 2013 Gagan

Gagan (view profile)

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

Comment only
07 Jan 2013 YXING

YXING (view profile)

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.

Comment only
14 Dec 2012 Ejri

Ejri (view profile)

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

Comment only
25 Nov 2012 Angus

Angus (view profile)

 
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 :)

Comment only
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 :)

Comment only
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"

Comment only
10 Nov 2012 Gagan

Gagan (view profile)

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.

Comment only
10 Nov 2012 Gagan

Gagan (view profile)

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.

Comment only
09 Nov 2012 zhu

zhu (view profile)

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

fabius (view profile)

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.

Comment only
05 Sep 2012 Suhaib

Suhaib (view profile)

 
05 Sep 2012 Suhaib

Suhaib (view profile)

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 ^^

Comment only
19 Aug 2012 Manko

Manko (view profile)

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

Comment only
18 Aug 2012 Prem

Prem (view profile)

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???

Comment only
16 Jun 2012 fabius

fabius (view profile)

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

Hernan (view profile)

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.

Comment only
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.

Comment only
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?

Comment only
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?

Comment only
10 Apr 2012 Nancy

Nancy (view profile)

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??

Comment only
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.

Comment only
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

Comment only
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")

Comment only
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).

Comment only
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?

Comment only
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.

Comment only
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.

Comment only
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.

Comment only
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.

Comment only
10 Jan 2012 Giampiero Campa

Giampiero Campa (view profile)

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.

Comment only
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

Comment only
08 Jan 2012 Sun

Sun (view profile)

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

Comment only
20 Dec 2011 Alonso

Alonso (view profile)

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.

Comment only
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

Comment only
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!

Comment only
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 =)

Comment only
05 Dec 2011 Fardin

Fardin (view profile)

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.

Comment only
07 Nov 2011 Roman

Roman (view profile)

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.

Comment only
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")

Comment only
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.

Comment only
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.

05 Sep 2014

Updated description indicating new options for projects based on R2014a or higher.

Contact us