Improve speed in writeRead loop while communicating with Raspberry Pi 3 B+
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a code to get a value from ADC(mpc3208).
It works fine, but to get stable value I use 'for' loop and calculate median after gathering 30 values.
Matlab is connected with Raspberry Pi by wifi, and I have encountered speed issue.
The loop spends too long time (>0.1s) to gather 30 ADCvalues, I want to improve its speed.
I have been trying to find any method, but I still haven’t found suitable way.
Here is my code, Anyone who knows the way to solve, please help me.
function raspberry_test_blackborad
clc; clear all; warning('off','all')
clear rpi
rpi = raspi();
mcp3208 = spidev(rpi, 'CE0');
NumSample=30;
ADCval_array=zeros(NumSample,1);
for i=1:NumSample
data = uint16(writeRead(mcp,[bin2dec('00000110'), bin2dec('11000000'), 0])); %ch=3
highbits = bitand(data(2), bin2dec('1111'));
ADCval = double(bitor(bitshift(highbits, 8), data(3)));
ADCval_array(i)=ADCval;
end
ADCval=median(ADCval_array);
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!