How to save voltage data as a array in Matlab, using a Arduino MEGA 2560 board?

25 views (last 30 days)
Hello everyone
I appreciate if you can help me with this issue.
I'm working with Arduino MEGA 2560 and I'm using the followings commands:
clear all
a = arduino;
data = readVoltage(a,'A9');
So far, there is no problem (I'm using the analogic input A9). But I need some help with, How can I get an array with the measurement of the reading voltage in Matlab, without using Simulink and Arduino software, only Matlab?
I'm using a battery of 1.7 volts approx. as an example, next I need to apply this commands to a motor servo DC (Analogic Control System ACS-1000 from K and H fabricants.
I'm looking forward for your comments and help.
Thanks very much in advance.

Accepted Answer

Madhu Govindarajan
Madhu Govindarajan on 15 Jan 2019
Let's say you know how long of a vector you need, then use indexing.
Example -
for i = 1:100
data(i) = readVoltage(a,'A9');
Note the pause just pauses MATLAB and you might notice that the whole thing takes more than 10 seconds.
If you want to collect data till you press a pushbutton on the Arduino.
buttonPressed = false;
data = readVoltage(a,'A9');
while ~buttonPressed
data(end+1) = readVoltage(a,'A9');
buttonPressed = readDigitalPin(a,'D13'); % Here it is assumed that you have a push button connected to Pin 13.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by