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

4 vues (au cours des 30 derniers jours)
Soo Chong
Soo Chong le 15 Mai 2017
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

Réponses (1)

Sadam Hussain
Sadam Hussain le 10 Août 2018
Hello, friend, I have the same problem I can not get accurate data did you get correct once

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by