How can i set the sampling rate for Arduino analogRead in matlab code?

3 次查看(过去 30 天)
I want to use current sensor ACS712 to read the real time value for of 50Hz line current with the following code I found on the internet, but it not given the real-time signal. How can I set the sampling rate?
if true
% code
end
a = arduino(); % Create a figure window to monitor the live data
tmax = 10; % Total time for data collection in seconds
figure(1),
grid on,
xlabel ('Time (s)'), ylabel('Voltage');
axis([0 tmax -2.5 2.5]); % set initial index value, starting value
k = 0; %index
v = 0; %voltage
t = 0; %time
tic % Start timer
while toc <= tmax
k = k + 1;
v(k) = readVoltage(a,'A0')-1.47; %maximum value=3.935
t(k) = toc;
% Now plot the data
if k > 1
line([t(k-1) t(k)],[v(k-1) v(k)]);
drawnow;
end
end

回答(1 个)

Sadam Hussain
Sadam Hussain 2018-8-10
Hello, friend, I have the same problem I can not get accurate data did you get correct once

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by