What determines the sampling rate of an Arduino MKR1000 when connected over wifi?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have recently inherited a project in which I have an Arduino MKR1000 that is connecting to Matlab over wifi. It is then given a code that records the condition of a voltage sensor and a current sensor that are attached to the arduino. This code and arduino setup was all given to me as is, so I am trying to understand where it is all coming from. As of right now, the sampling rate is around 12.5 Hz, but we would like to get it up to ~200 Hz. The code that was given to me is shown below.
a=arduino('172.20.10.4','MKR1000')
Voltage=[];
Current=[];
tic
for i=1:250;
Voltage(i)=readVoltage(a,'A1');
Current(i)=readVoltage(a,'A3');
t(i)=toc;
end
Voltage=Voltage*(1/(7.5/(7.5+30)));
plot(t,Voltage)
hold on
title('Voltage vs. Time')
xlabel('Time(s)')
ylabel('Voltage(V)')
hold off
figure
plot(t,Current)
hold on
title('Current vs. Time')
ylabel('Current(mA)')
xlabel('Time(s)')
hold off
figure
P=Voltage.*Current;
plot(t,P)
title('Power vs. Time')
xlabel('Time(s)')
ylabel('Power(mW)')
hold off
x=Voltage';
y=Current';
z=[x y];
writematrix(z,'TestingPressure20.750.33.xls')
save('TestingPressure20.750.33','z')
My initial guess was that the code that was querying the sensors was not optimized, but from what I can tell, it's about as lean as possible. So my next guess was that it's possible the wifi is what is slowing down the sample rate?
The other question that I had was what is determining this sampling rate? As far as I can tell, the only thing that determines the sampling rate would be how quickly the loop can process 250 iterations.
I am new to data acquisition with using an Arduino and Matlab, but from what I understand the Arduino is capable of 1000 Hz sampling and Matlab is only limited by script speed, which should be well above the 200 Hz that we are looking for. I would appreciate any help and direction for this. There is a lot of data resources out there for sampling with a serial connection with an Arduino, but I haven't been able to find much in connection to the Wifi. Again, any help is appreciated. Thanks.
댓글 수: 0
답변 (1개)
Madhu Govindarajan
2019년 11월 20일
This approach limits the speed in a variety of ways including lack of something close to a real-time OS, Wi-Fi communication speed etc. The speeds of 200 Hz would be more realistic for Simulink Hardware Support for Arduino. There is an equivalent Analog Read block there where in you can set a much higher sampling time to get desired results.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Modeling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!