How to control Raspberry Pi to measure distance using SRF05 ultrasonic sensor on MATLAB?
조회 수: 7 (최근 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!
댓글 수: 1
답변 (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!