How to control Raspberry Pi to measure distance using SRF05 ultrasonic sensor on MATLAB?

4 vues (au cours des 30 derniers jours)
I am trying to control my Raspberry Pi 3 Model B to use SRF05 ultrasonic sensor on MATLAB. This is my hardware connection as shown in the image - Vcc to 5V - Trig to GPIO 21 - Echo is connected to a voltage divider circuit to ensure the input is around 3.3V, the input is connected to GPIO 20 - GND to GND
Here is my code:
clear all
mypi=raspi;
pin=mypi.AvailableDigitalPins;
trig=pin(18);
echo=pin(17);
configureDigitalPin(mypi,trig,'output');
configureDigitalPin(mypi,echo,'input');
writeDigitalPin(mypi,trig,0);
while 1
writeDigitalPin(mypi,trig,0);
pause(2)
writeDigitalPin(mypi,trig,1);
pause(0.00001)
writeDigitalPin(mypi,trig,0);
while readDigitalPin(mypi,echo)==0
continue
end
tic
while readDigitalPin(mypi,echo)==1
continue
end
duration= toc
distance=duration*17150
end
I try this code, but the result is not shown, please help me to correct the code. I'm a beginner in MATLAB. Thank you everyone!

Réponses (0)

Catégories

En savoir plus sur MATLAB Support Package for Raspberry Pi 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