Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Data acquistion with Simulink 2012b and Arduino UNO

Asked by Rodolfo Buschle on 29 Sep 2012
Latest activity Commented on by Nico on 24 Aug 2014

Hello everyone,

I've been trying to read data from my arduino UNO on simulink with no success.

I connected a potentiometer on analog port 3 (A3) on the arduino. On simulink I have an Analog Input block connected to a scope block.

I run on target and then play the simulation, but I only read 0 on the scope.

To be honest, I'm pretty confused. The help files were not really helpful and I have tried every possible combinations of blocks. Maybe it's best using a Serial Receive block?!

By the way, I'm quite new to Simulink.

Any help will be greatly appreciated, as I need to get this working for my project.

Thanks!

3 Comments

Giuseppe Naselli on 2 Jan 2014

Hi ROdolfo, (happy new year) I saw your post as I am having the same problem today. I was wondering if you manage to solve it. If so, would like to share the solution with us?

Thanks

G

Gene on 16 Mar 2014

I found that the easiest method of accomplishing this is to use the serial transmit block and then open a serial port in Matlab to read the data in.

Gerald on 7 Jun 2014

Gene do you have an example?

Rodolfo Buschle

Products

9 Answers

Answer by Ryan G on 1 Oct 2012

Make sure you have the right pin selected in the input block. When you play the model, set it to run 'inf' so you can play around with your board and Simulink will keep running.

Are you sure you're setup to run on the arduino board? In the configuration parameters there is a 'Run on Target Hardware' section. You can select the Arduino Uno from here.

How are you running the model? Try tools -> run on target hardware -> run.

0 Comments

Ryan G
Answer by Rodolfo Buschle on 1 Oct 2012
Edited by Rodolfo Buschle on 1 Oct 2012

Hello Ryan,

Thanks for your answer.

First of all, I should point out my specs: I'm running a Windows 7 x64 Professional, Core i7 720QM, 8gb Dual-Channel DDR3, nVidia Quadro FX 880m, Matlab 2012b (Arduino support package installed through MATLAB target installer). Everything is up-to-date.

Here's a walk through of what I'm doing: 1) Start a new model; 2) Insert a Analog Input block (Set pin to 0 and sample time to 0.1); 3) Insert a scope block and connect to the Analog Input block; 4) Set the simulation time to "inf"; 5) Tools > Run on Target Hardware > Prepare to Run...; 6) Set target hardware to Arduino UNO; 7) Set host COM port: to COM5 (tested on the arduino IDE to make sure it's the right port, and it is.); 8) Apply and close prepare to run window; 9) Tools > Run on Target Hardware > Run...; ("Model successfully downloaded to 'Arduino UNO'); (In my understanding the Tx LED on the Arduino should be blinking, but isn't) 10) Run simulate and get nothing but zero's on the scope;

I have checked the circuit, and it works just fine on the Arduino IDE. It must be a detail that I'm missing, but frankly, I have no idea how to make it work.

I thought maybe I could run it on External mode, but I have an Arduino UNO and the external mode only runs on the Arduino MEGA.

I tried running through YouTube and the MATLAB community but I couldn't see a single video or post about someone running a model on the Arduino and viewing the results on simulink.

I kind of managed to make it run, by making one model with Analog input connected to Serial Transmit and download it to the Arduino. Then, on a new block a set a Serial receive block connected to a scope (I also set a Serial Configuration block, both found on the Instrument Control Toolbox) a run a simulation with 'inf'. It kind of works, but very sluggish, and I'm not satisfied with that solution.

Anyway, any help will be greatly appreciated.

To format of the text isn't coming as I wrote it, but I guess you can read it, sorry for that.

1 Comment

Ryan G on 1 Oct 2012

"I connected a potentiometer on analog port 3 "

When you wrote that in the main post I read it as 'pin' 3, is this the case? Try stting the Input block to 3 instead of 0. Essentially it is trying to read whatever is at pin 0, which at this point there does not seem to be anything on that pin.

I just went to the product page and think I found the main problem.

"Interactive parameter tuning and signal monitoring of applications running on the Arduino Mega (not available on Arduino Uno)"

"Model deployment for stand-alone operation"

Essentially your model is 'deploying' on the target. This means there is not really any more interaction with Simulink. You could start the Arduino running and unplug it from the PC. However, if you do want to monitor it you can either use MATLAB or Simulink to read from the serial port in the PC (which it sounds like you've found is slow).

The Ardunio Input block in this case is simply used in whatever type of design you are planning in Simulink (like a feedback control).

Rodolfo Buschle
Answer by Yan on 23 Jan 2013

Have you solved the problem? I have the same issue. The sensor works very well at Arduino IDE. I also detects voltage change at the pin using a multimeter. But i cannot make it work at Simulink. I tried Rodolfo's way of using the serial port receive/send, it did not work either. I use win7 64bit + Matlab 2012a. Any suggestions?

0 Comments

Yan
Answer by Robalivry on 14 Feb 2013

What did you do exactly to read with Simulink ?

For my part, I always :

 * make a new variable with my Arduino in command line :
>> Due = arduino('COM4');

(I use a Duemilanove)

 * go to Simulink, put a scope in my model and link it to the Analog Input found in the ArduinoIO library AND put a Setup block (found at the same place) in the model
 * Double-click on the setup block and chose "existing variable #1" (or something like this) and enter the name of my variable "Due" in the field below.
 * Then go to the Analog Input block and chose the *same* "existing variable #1".
 * Run my model and it works.

Hope that will help !

0 Comments

Robalivry
Answer by shri raje on 5 Mar 2013

Can anybody will give me pictorial representation of communicating virtual com port with proteus and simulink(2012a) for detecting analog signal and displaying it on scope of simulink(2012a)???????????????

0 Comments

shri raje
Answer by Joaquin on 17 Jul 2013

Rodolfo, Can you solve your problem with data acquisition?

0 Comments

Joaquin
Answer by Kashyap on 17 Nov 2013

Could anyone solve the problem with data acquisition using Arduino uno and simulink?? Any help would we greatly appreciated.

Thank You.

0 Comments

Kashyap
Answer by William sanchez on 27 May 2014

Any help us please! i have the same problema with arduino uno and preset.

0 Comments

William sanchez
Answer by Valmir Sadiku on 27 May 2014
Edited by Valmir Sadiku on 27 May 2014

I tried two years ago and it worked for me fine. The attached picture shows you, how you can build a simple analog read from arduino into simulink.

First model read the analog sensor (in my an poti) and write it to the serial com port (byte by byte). this model must be uploaded to the arduino!

The second model reads the serial port as shown in this picture.

hope this will help you!

2 Comments

Valmir Sadiku on 27 May 2014

it will maybee confusing for someone: the uint8(8) are the Headerbyte and the uint8(0) are the terminator for the data-string - so it a little data encoding to get the right value we want.

Nico on 24 Aug 2014

Do you have to modify anything on the Serial Receive block to accomodate for start bit uint8(A) and uint8(0)?

Valmir Sadiku

Contact us