5.0

5.0 | 4 ratings Rate this file 134 Downloads (last 30 days) File Size: 3.65 KB File ID: #26711
image thumbnail

Interacting with an Arduino Using the Matlab Serial Commands

by Lowell Toms

 

16 Feb 2010

Two sets of files demonstrate serial communications between Matlab and the Arduino.

| Watch this File

File Information
Description

Using information from Matlab central, Robot Grrl, and the Arduino forums, four files (two .m and two sketches) demonstrate two way communications between Matlab and the Arduino. The first set of files, serialTest1, demonstrates arduino input with Matlab tic/toc timing information added, and the second set of files, serialTest2, uses clock information from the arduino. I think you'll find the results interesting when the two approaches are compared.

Usage:
Load the sketch on your arduino. LED13 will light, indicating that the arduino is waiting for a response from Matlab to start. Load the m file, and change the com port to the port where the arduino USB is mapped on your PC (I use Linux, thus the /dev/ttyUSB1, it will be something like 'COM3' in windows). Run the .m file, and LED13 will turn off as Matlab signls the arduino, data is read, and a plot is created of time info versus counter data (simulating sensor data). Remember to reset the arduino before each m file run (LED13 must be on)! Used an arduino mega, but should work fine on most arduinos. Thanks to Tom Igoe and Robot Grrl (see sketch references to http addresses). Robot Grrl plots as she goes, and you can do that also, although it will slow things down slightly. But, note the key to these files, is the use of the proper TERMINATOR. The matlab set terminator statement using LF and the use of serial.println in arduino is the secret ingredient to success. If you don't use these, then you are relying on inserted timing delays, yuck.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Arduino and the Arduino toolbox 018.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
06 Jun 2010 Jeff Tuhtan

Awesome submission! Was fooling around forever with the serial Arduino/Matlab connection, and could never get it to work. Can finally graph data from my Arduino in realtime. Thanks a million!

24 Aug 2010 Tanyer Alan  
21 Apr 2011 Petteri T  
09 Jul 2011 akram

hello
I am try to use an Arduino Mega 1280, with simulink but it doesn't work.
please help me.

13 Sep 2011 Adam Erskine

Looks like just what I'm after but - trange one - when I download I all four files have the same content (all serialTest1.m). Any ideas?

30 May 2012 Asiya

Very useful files. I used them since you uploaded them and I did extend them a lot to do many useful functions. I'll try to submit some works here.

Regards

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
arduino Lowell Toms 17 Feb 2010 10:50:20
serial Lowell Toms 17 Feb 2010 10:50:20
serial communications Lowell Toms 17 Feb 2010 10:50:20
atmel Lowell Toms 17 Feb 2010 10:50:20
atmega Lowell Toms 17 Feb 2010 10:50:20
set Lowell Toms 17 Feb 2010 10:50:20
usb Lowell Toms 17 Feb 2010 10:50:20
arduino Sergii 03 Oct 2010 14:37:54
arduino ghassan 12 Jan 2011 04:17:49
atmega Antonio Amorim 27 Nov 2011 15:43:31

Contact us at files@mathworks.com