How to control Raspberry Pi to measure distance using SRF05 ultrasonic sensor on MATLAB?
4 次查看(过去 30 天)
显示 更早的评论
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!
回答(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!