Data acquisition from Arduino Uno and realtime plotting

5 views (last 30 days)
Hi guys, I have an Arduino Uno board and I want to aquire a signal values from a potentiometer and plot it in realtime, I've found a code to do it as you can se below:
line(nan, nan, 'color','blue');
while 1
pot = readVoltage(arduino,'A1');
x=get(line, 'xData');
y=get(line, 'yData');
x=[x i];
y=[y pot];
set(line, 'xData', x, 'yData', y);
pause (1);
The problem is that is gives some several errors when I run the program such as: "Failed to open serial port COM3 to communicate with Arduino board Uno. Make sure there is no other MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware Troubleshooting."
"Invalid pin format. Pin number must be a scalar integer."
I hope someone can help me

Accepted Answer

Menghan on 8 Jun 2018
Edited: Hans Scharler on 12 Jun 2018
arduino function creates a connection to the board each time you call it and only one connection to the board can exist at one time. You should change the code to something like this,
a = arduino;
while 1
pot = readVoltage(a, 'A1');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!