5.0

5.0 | 3 ratings Rate this file 344 Downloads (last 30 days) File Size: 1.88 MB File ID: #27843
image thumbnail

Arduino IO package: Slides and Examples

by Giampiero Campa

 

06 Jun 2010 (Updated 14 Sep 2010)

Slides for the webinar: "Learning Basic Mechatronics Concepts Using the Arduino Board and MATLAB".

| Watch this File

File Information
Description

This zip file contains the slides (and some code examples) used for this webinar: http://www.mathworks.com/company/events/webinars/wbnr43537.html

The webinar introduces the ArduinoIO package, which allows the user to perform Analog and Digital Input and Output, as well as to control DC, Servo and Stepper Motors interactively from the MATLAB command window, without having to write, debug, compile, upload and run C programs.

NOTE: You can download the Arduino IO package from here:
http://www.mathworks.com/academia/arduino-software/arduino-matlab.html

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (23)
09 Feb 2011 Mohd Ismail  
09 Feb 2011 Mohd Ismail

Hi,

Found your link from Arduino blog. I just started to work on interfacing Arduino with Matlab. But unable to run the example file. Matlab connection unsuccessful when send command a=arduino('com7'). Any idea?

??? Error using ==> arduino>arduino.arduino at 100
Connection unsuccessful, please make sure that the Arduino is powered on, running
either 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.

Cheers

09 Mar 2011 fremond khoo

yeah..same prob..can u tell us how to solve it?

20 Mar 2011 Simon

To run in R2008a, line 21 of arduino.m needs to be:
addpath(fullfile(pwd,''));
instead of:
addpath(fullfile(pwd));

I sussed it out and thought I'd share it here. I have yet to test it with a more up to date version of Matlab. I guess the function could have changed(?).

Without this modification the fullfile function returns:
??? Error using ==> fullfile at 21
Not enough input arguments.

22 Mar 2011 fremond khoo

can i ask how do i plot a graph in MATLAB GUI using the data i obtained through arduino?

06 Apr 2011 Tee

I have some question on obtain data from arduino which connect to optical encoder. I have using following code to obtain data from Arduino

        function encoder1pushbutton9_Callback(hObject, eventdata, handles)
        handles.a.pinMode(2,'input');
        handles.a.digitalRead(2)
        numberOfDatas = 200;
        data = zeros(1, numberOfDatas);
        i = 1;
      % Main graph figure
      figure(1);
      hold on;
      title('Incomming Data from External Device');
      xlabel('Data Number');
      ylabel(' output (0-1)');
      for i=1:numberOfDatas
            % Get the data from the serial object
            data(i) = handles.a.digitalRead(2);
            % Plot the data
            figure(1);
            plot(i, data(i), 'm*');
            drawnow;
      end
Did i have to set the Baudrate, databits and stopbits to acquire data from arduino???

06 Apr 2011 Giampiero Campa

Thanks Simon !

Tee, the connection is automatically set up as 9600baud, 8,N,1, on both the MATLAB and Arduino (adiosrv.pde) sides.

If you want to change the baudrate you will need to do that in both the arduino.m and adiosrv.pde files.

19 May 2011 mario

   Hi I´m using Matlab R2010a, target arduino UNO, software arduino-0022, but i have a problem when I use my board in SIMULINK,
I follow steps in README

Arduino Target for Use With Simulink Software, Version 1.0 (R2010a) 01-July-2010
>> cd c:\ARDUINO_TARGET
>> addpath(fullfile(pwd,'arduino'),fullfile(pwd,'blocks'),fullfile(pwd,'demos'))
>> savepath
>> sl_refresh_customizations
>> arduino.Prefs.setArduinoPath('c:\Program Files\ArduinoPRGM\arduino-0022')
>> arduino.Prefs.setMcu('atmega328p')
>> comPorts=arduino.Prefs.searchForComPort;
>> arduino.Prefs.setComPort(comPorts{1});
??? Cell contents reference from a non-cell array object.

but i don´t know why this problem
I try to use arduino.Prefs.setComPort('COM1')
but demo_arduino_blink.mdl doesn´t work

Download failed. Check your serial connection and and run the command arduino.Prefs.getMcu to check you have specified the correct MCU.

The call to arduino_make_rtw_hook, during the after_make hook generated the following error:
Download failed. Check your serial connection and and run the command arduino.Prefs.getMcu to check you have specified the correct MCU.
The build process will terminate as a result.

### If your target board has TX and RX LED you should see them flashing ...
avrdude: stk500_getsync(): not in sync: resp=0x30
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

What can I do?
Thankyou
Mario Camacho

09 Jun 2011 Dave Rowland

Thanks for the very helpful submission! I was curious if there are files for 64bit windows? For example, when I try to run serial('COM3'), I get an error saying:
"The serial port object is supported on the Solaris, 32-bit Windows and
32-bit Linux platforms only."
Thanks,
Dave Rowland

07 Jul 2011 Ryan Stafford

I'm having exacting the same problem as Mario... a connection issue when using the Arduino Uno with Simulink. The odd thing is, I also have the older Arduino board (Duemilanove) and this works absolutely fine with the Simulink examples provided. As far as I am aware, these two boards use exactly the same chip (328P) but the UNO now uses ATmega8U2 instead of the FTDI chip. I'm not sure how to resolve this issue or why this is causing a problem... any ideas? The Uno works fine within the Arduino environment and I can also make a connection when using the arduino.m file, but when I try to download a Simulink model to the board I receive the same error message Mario has listed above. Thanks,
-Ryan Stafford

15 Jul 2011 Giampiero Campa

The Arduino IO (works fine on 64 bit windows platforms).

The Arduino Target works with the UNO, but you have to use arduino.Prefs.setMcu('atmega328p-pu')
in the instructions above (in general this is the name printed on the microcontroller).

A newer version with a better readme file is coming out soon.

15 Jul 2011 UMAGON

hi, is there any video for this? why cant i access to it?

29 Jul 2011 Mihir Shah  
15 Aug 2011 Héctor Corte

Simon. I can´t find the line you are saying with addpath on Arduino.m ¿Anyone have the same problem and solve it the same way?

18 Aug 2011 Imran

very informative but the Arduino Uno target files don't work.

03 Sep 2011 Justin

I'm having trouble getting MATLAB to communicate w/t my Arduino Uno.

I've uploaded the adiosrv (I'm not using the motor shield), and had no errors uploading (I tried the srv file, got an error, but realized that since i'm not using the motor shield I should be using the adiosrv file anyways).

When I try a=arduino('Com6') in MATLAB 2009a, I get a timeout error. Using TMtool, I can't find the Arduino using matlab. So it seems that the adiosrv is not doing its job, but I'm not sure where to go from here!

Any help would be much appreciated!

06 Sep 2011 Giampiero Campa

You can try to use Hyperterminal (or the IDE) to communicate with adiosrv.

There are some instructions at the top of the adiosrv.pde file that tells you how to do it. For example if you establish serial connection and type "2n1" in the IDE (or in Hyperterminal) you should set pin #13 high and the led should light up.

This will allow you to further narrow the problem down.

14 Dec 2011 Deepak Mohan

can i implement all the functions in an arduino when interfaced with matlab....

31 Jan 2012 David Batterbee

I'm having similar problems with the UNO described above. In particular, typing "arduino.Prefs.searchForComPort" returns an empty results even though my Device Manager shows that the Arduino Uno is connected to COM11.

I have no problem at all with the Arduino Duemilanove and the searchForComport function works fine.

How can I get Matlab to see the UNO?

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.

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.

26 Mar 2012 Giampiero Campa

Andrey, the MATLAB support package for arduino, (ArduinoIO), and the Simulink Support Package, (now renamed Embedded Coder support package), are completely different and are not supposed to work with one another. Either you use one or the others. If you have problems regarding the Embedded Coder Package, (that's what it looks like) i suggest that you can try looking where you actually downloaded that package.

07 Apr 2012 Roger Su

hi, I am trying to read the analog input data from arduino in Matlab, but i don't know how to start. Can someone help me, please ?

Please login to add a comment or rating.
Updates
27 Aug 2010

Inserted link to download arduino class files.

09 Sep 2010

Uploaded figure, put copyrights in the two example files, and referenced the Arduino page in the description.

10 Sep 2010

Mainly i have updated the description text.

14 Sep 2010

Removed redundant license file.

Tag Activity for this File
Tag Applied By Date/Time
arduino Giampiero Campa 29 Jun 2010 12:08:01
mechatronics Giampiero Campa 29 Jun 2010 12:08:01
class Giampiero Campa 29 Jun 2010 12:08:01
motor Giampiero Campa 29 Jun 2010 12:08:01
analog Giampiero Campa 29 Jun 2010 12:08:01
digital Giampiero Campa 29 Jun 2010 12:08:01
data export Giampiero Campa 29 Jun 2010 12:08:01
robotics Giampiero Campa 29 Jun 2010 12:08:01
measurements Giampiero Campa 29 Jun 2010 12:08:01
data import Giampiero Campa 29 Jun 2010 12:08:01
pwm Giampiero Campa 29 Jun 2010 12:08:01
analog Aru Sankar 08 Oct 2010 14:13:42
arduino Jose Ercolino 05 Nov 2010 10:36:29
mechatronics Jose Ercolino 05 Nov 2010 10:36:42
motor barry 06 Jun 2011 05:45:49
analog Rahul V 27 Jun 2011 00:35:18
data export cesar rojas 28 Jun 2011 15:20:36
arduino marco flores 17 Oct 2011 01:53:45
analog Kim DW 19 Dec 2011 21:40:00
analog Jose 29 Mar 2012 11:02:05
analog Nicolae 07 Apr 2012 14:53:48
analog Neil Cai 02 May 2012 23:50:43
arduino helpeveryone 03 May 2012 06:56:20
analog k 14 May 2012 13:42:28

Contact us at files@mathworks.com