MATLAB Answers

Real-Time Data Acquisition from Arduino using Simulink

57 views (last 30 days)
Giuseppe Naselli
Giuseppe Naselli on 2 Jan 2014
Hi All,
I am writing my question here after many attempts to solve the problem by myself and after being confused by the very fragmented information found on the web about the following subject.
First of all, I run the "Matlab R2012a", I also have (where relevant): "Arduino IO Library" and "Target for Use with Arduino" Simulink libraries.
  • My aim is to acquire analog data from a Arduino board (analog input A0), plot them in real time and also write them into a file for post processing. *
In order to create an analog input, I created the simple hardware configuration in Fig.1
Voltage (5Volts) is provided to a variable potentiometer and the pin in the middle provide a voltage (analog) that is directed into the analog input of the Arduino UNO board. The connections are fine as checked with a voltmeter and also read through the Arduino Serial Monitor (0 - 1023). Finally a LED is connected to the digital (PWM) output 9.
The following model is then downloaded on the Arduino board using the "Run on Target" function in Simulink
The hardware response is as expected: as the potentiometer lever is turned the LED lights up, from zero to max light intensity.
With the Arduino running, a second model is created in Simulink and run (at the same time the potentiometer is turned) but as shown in the picture an error is given.
Can anyone suggest a way of achieving my goal ?
Thanks in advance
G

  0 Comments

Sign in to comment.

Answers (2)

Brody
Brody on 2 Apr 2014
Which mode are you running in? External or normal? I think you need to run in external mode to get realtime data, but I don't think that's supported on the Uno (or Nano, probably not enough memory).
I'm trying to do the same thing, and I spoke to a Mathworks FAE who suggested [Analog Pin] > [Convert] > [Serial TX] for the target and a separate model with Serial RX (if you have it, needs Instrument Control toolbox I think) or serial read in MATLAB.
Anyway for your attempt wouldn't running your second model overwrite the first one? Also if you're using multiple Analog Read blocks, the description mentions that you can't have multiple blocks set to the same input.

  1 Comment

Giuseppe Naselli
Giuseppe Naselli on 2 Apr 2014
Hi Brody,
thanks for your answer.
Regarding your question " Anyway for your attempt wouldn't running your second model overwrite the first one? "
I see your point and I think you are right.
Does the solution provided by the Mathworks FAE work?
If so would you like to share a screen shot of your model?
G

Sign in to comment.


ercan duzgun
ercan duzgun on 28 Apr 2014
Dear Giuseppe,
Have you succeed to do this Simulink model? I also want to use Arduino for Real time applications. Your example is good and simple for the first step, but it doesn't work. It gives error like yours. Have you found something out, if so could you share?
Ercan

  2 Comments

Giuseppe Naselli
Giuseppe Naselli on 30 Apr 2014
Hi Ercan,
sorry I have not solved the problem so took a complete different approach by using the Arduino language in order to achieve my goal and put on side Simulink (it was not worth for me to loose more time on that when I could achieve my goal differently :)
G
Tobias Flores-Wentz
Tobias Flores-Wentz on 28 Jul 2015
I tried to use scope with this example and I was wondering if someone knows of a more effective method of data logging from the analog input.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!