My new raspeberry picar 3b+ was working well until I run sudo python3 4.obstacle_avoidance.py , it keeps spamming the phrase “distance:-1” and the Picar-x keeps going backwards in a circle continously.
Based on your description, the ultrasonic sensor is continuously outputting “distance:-1”, which usually indicates that the sensor is not reading distances correctly. The most common cause is a wiring issue or poor contact.
Please follow these steps to troubleshoot:
-
Check and re-plug the ultrasonic sensor: Make sure the Trig pin of the ultrasonic sensor is connected to the D2 pin on the Robot HAT, and the Echo pin is connected to the D3 pin. We recommend unplugging the sensor’s cable and plugging it back in firmly to ensure good contact.
-
Send us photos: Please take a photo of the ultrasonic sensor wiring, as well as a photo of the screen output when running the obstacle avoidance example, and send them to us. This will help us determine whether it’s a wiring issue or a faulty module.
If it still outputs -1 after re-plugging and the wiring is correct, the ultrasonic sensor itself is likely faulty. We will confirm based on the photos you provide, and if it’s a hardware issue, we will send you a replacement ultrasonic module.
Hola, yo también tengo un problema con el detector electrónico en el Pidog V2. Según las instrucciones de montaje Trig se conecta a pin 4 y Echo al pin 17 al conector DIGITAL me da como resultado lo mismo que a Ashishjain. No detecta nada, he cambiado el sensor y ocurre lo mismo.
We are sorry to hear that your PiDog V2 ultrasonic sensor is not working properly.
Please start by running the standalone ultrasonic test program:
cd ~/pidog/test
sudo python3 ultrasonic_test.py
Before running the test, please confirm that the wiring is correct:
Trig → D4
Echo → D17
After running the test, please send us the complete output and let us know whether it consistently shows distance: -1 or if there are any other errors.
If the issue persists, please also provide photos showing the ultrasonic sensor wiring and the program output.
Comprobado el cableado,todo bien.
Este es el resultado:
Traceback (most recent call last):
File “/home/gos/pidog/test/ultrasonic_test.py”, line 4, in
ultrasonic = Ultrasonic(Pin(“D1”), Pin(“D0”))
~~~^^^^^^
File “/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py”, line 77, in init
self.setup(mode, pull, active_state)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py”, line 123, in setup
lgpio.gpio_claim_output(Pin._chip, self._pin_num, 0, pull_mode)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/lgpio.py”, line 781, in gpio_claim_output
return _u2i(_lgpio._gpio_claim_output(handle&0xffff, lFlags, gpio, level))
File “/usr/lib/python3/dist-packages/lgpio.py”, line 458, in _u2i
raise error(error_text(v))
lgpio.error: ‘GPIO busy’
Regarding your PiCar-4WD issue where the ultrasonic sensor continuously outputs “distance:-1” and the car keeps moving backward in circles, this typically indicates that the sensor is not reading distances correctly. The most common cause is a faulty cable or poor contact.
Please follow these steps to troubleshoot:
-
Replace the ultrasonic sensor’s connecting cable: We recommend replacing it with a new cable directly. A worn or internally broken cable can prevent the signal from transmitting properly, and replacing the cable often resolves this type of issue.
-
If the issue persists, please provide the following information so we can further diagnose:
- A photo of the ultrasonic sensor wiring
- A screenshot of the screen output when running the test program
We will confirm based on the photo and output you provide. If it is a hardware issue, we will handle it further.
Additionally, regarding the PiDog V2 GPIO busy error, we recommend restarting the device and then running the example program again to see if the issue persists.
Finally, we would like to confirm: Are we discussing two different issues for two different products (PiCar and PiDog V2)? Please confirm so we can follow up on each separately.
Mi problema es con PiDog V2 en el sensor ultasonico.
He comprobado el cableado y esta perfecto.
Segue dando el poblema:
gos@PiGos:~/pidog/test $ sudo python3 ultrasonic_test.py
Traceback (most recent call last):
File “/home/gos/pidog/test/ultrasonic_test.py”, line 4, in
ultrasonic = Ultrasonic(Pin(“D1”), Pin(“D0”))
~~~^^^^^^
File “/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py”, line 77, in init
self.setup(mode, pull, active_state)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py”, line 123, in setup
lgpio.gpio_claim_output(Pin._chip, self._pin_num, 0, pull_mode)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/lgpio.py”, line 781, in gpio_claim_output
return _u2i(_lgpio._gpio_claim_output(handle&0xffff, lFlags, gpio, level))
File “/usr/lib/python3/dist-packages/lgpio.py”, line 458, in _u2i
raise error(error_text(v))
lgpio.error: ‘GPIO busy’
gos@PiGos:~/pidog/test $ sudo python3 ultrasonic_iic_test.py
Traceback (most recent call last):
File “/home/gos/pidog/test/ultrasonic_iic_test.py”, line 28, in
bus.write_byte(address, cmd)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^
OSError: [Errno 5] Input/output error
He reiniciado varias veces y siempre da el mismo problema.
Gracias
Thank you very much for the detailed information, and we’re sorry for the inconvenience.
First, an important correction: the ultrasonic module that comes with the PiDog V2 uses D1 and D0 as the Trig/Echo pins — it is NOT an I²C module. Therefore ultrasonic_iic_test.py does not apply to this module, and the I²C input/output error it produces can be ignored for now — there’s no need to troubleshoot that part.
What we need to focus on is this error:
lgpio.error: ‘GPIO busy’
This error means that one of the GPIO pins used by the ultrasonic test program is already occupied by another program, a system service, or a device-tree configuration. Based on where the error occurs, the program fails while initializing D1, which corresponds to GPIO4.
You have already restarted multiple times but the problem persists, so it is very likely that some Python program or service starts automatically on boot and re-occupies that GPIO. Please run the following commands and send us the complete output:
ps aux | grep python | grep -v grep
sudo lsof /dev/gpiochip0
grep -nE “gpio-fan|w1-gpio|gpiopin=4” /boot/firmware/config.txt
If it says lsof is not installed, please run this first:
sudo apt update
sudo apt install lsof
Also, please close the PiDog APP and any other running PiDog or Python programs first, then run only the correct ultrasonic test:
cd ~/pidog/test
sudo python3 ultrasonic_test.py
Please note that this error does not yet prove that the ultrasonic module has a hardware fault — the program stops while trying to occupy the GPIO, before it actually starts reading the ultrasonic module. Once we receive the output of the commands above, we can further identify exactly which program or system configuration is occupying GPIO4 and provide you with the corresponding solution.
Thank you again for your cooperation.