Data acquisition using Arduino Uno. I controlled the Arduino Uno board through Matlab. How can I control the sampling rate and the acquisition time? I post my codes. Thank you!

2 views (last 30 days)
Hello Everyone! I am using Arduino Uno for data acquisition. My sampling rate is 1 kHz. I am doing the sampling through Matlab.I am controlling the Arduino Uno Board through Matlab. For some reason, my function loop infinitely. Can anyone help me figure out what I am doing wrong.
{
myArduino = arduino('COM4','Uno');
% Configure Arduino A0 = 0; myArduino.configureAnalogPin(A0,'Input');
Fs = 1000; % Sampling rate Ts = 1/Fs; % Sampling Period t1 = 0; % Sampling starting time t2 = 60; % Duration of collection in second t = t1:Ts:t2; % Data acquisition Time range n = length(t); % Length of the time matrix
voltage = zeros(n,1); % Initializing the voltage matrix time = zeros(n,1); % Initializing the time matrix
for i=1:n time(i) = t(i); voltage(i) = myArduino.readVoltage(A0);
end
}
  1 Comment
Geoff Hayes
Geoff Hayes on 22 Oct 2014
Paul - as your function iterates from 1 to 60001 (given your sampling rate), it isn't looping "infinitely" but it could be just getting stuck waiting for a return from readVoltage. Have you stepped through the code to see what is happening? Or, try adding the following fprintf statement to display something on each iteration of the loop
for i=1:n
fprintf('at iteration %d \n',i);
% etc.
end
The above may give you a clue as to when you are getting stuck.

Sign in to comment.

Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!