Azzera filtri
Azzera filtri

Improve speed in writeRead loop while communicating with Raspberry Pi 3 B+

4 visualizzazioni (ultimi 30 giorni)
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);

Risposte (0)

Categorie

Scopri di più su MATLAB Support Package for Raspberry Pi Hardware in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by