Ultrasonic sensor

Good evening, I’m testing Pidog by running the robot-hat/examples/ultasonic script. It works, and it shows me various distances. Running Pidog/examples/3-patrol.py always gives me -1 as the distance. The touch sensor always shows R.
Thanks

1 Like

Regarding the ultrasonic sensor always showing -1:When running pidog/examples/3_patrol.py, the sensor may return -1 because the head movement could cause the ultrasonic module’s cable connection to become loose. Please try reconnecting the cable on both ends.

Regarding the touch sensor always showing “R”:This is a known issue in older versions of the code. Please check your current PiDog code version by running:pidog -v

If your version is not 1.3.13 or newer, please update to the latest version by running the following commands:

cd ~/pidog
git pull
sudo pip3 install . --break-system-packages

After updating, reboot your PiDog and test again. The touch sensor should then behave correctly.Let me know if the issue persists after these steps.


Hi, I checked the cable, but I think it’s OK, also because the ultrasonic.py script works. The code version is 1.3.13.


Could you tell me on which PIDs the ultrasonic sensor and the dual touch sensor should be placed and their position in the v2 version board?

First, please check the robot-hat version and your HAT board version:pip3 show robot-hat

Does your Robot HAT PCB say V4 or V5?

We believe we have reproduced the issue. Please check your ultrasonic sensor wiring:

White → V5: GPIO 17 / V4: D0 Yellow → V5: GPIO 4 / V4: D1 Red → 3.3V Black → GND

After correcting the wiring, test with:

cd ~/pidog/examples
sudo python3 3_patrol.py

Does your Robot HAT PCB say V4 or V5?We believe we have reproduced the issue. Please check your ultrasonic sensor wiring:White → V5: GPIO 17 / V4: D0 Yellow → V5: GPIO 4 / V4: D1 Red → 3.3V Black → GND

After correcting the wiring, test with:

cd ~/pidog/examples
sudo python3 3_patrol.py

Note: robot-hat/examples/ultrasonic.py uses D2/D3, so it will return -1 with this wiring. Please ignore that example.

For the touch sensor (always shows “R”), please re‑seat its wiring:Green → V5: GPIO 27 / V4: D2 Yellow → V5: GPIO 22 / V4: D3 Red → 3.3V Black → GND

If it still shows “R” after re‑seating, we will send you a replacement.


Everything’s fine. Thank you so much.

Congratulations on solving the problem! If you run into any other issues in the future, please feel free to ask us.