Ultrasonic Module not working on the PiDog

I just built the PiDog and everything seems to be working but the ultrasonic module. I tried swapping it out with another I’ve had on hand and tired a different cable. The multimeter shows 3.3V when testing ground so the pins seem to be getting power. I tired using d2 and d3 with the test script. I know these pins work since the touch switch works using them.

The following is the output I get in the terminal:

paulhammond@raspberrypi:~ $ cd ~/pidog/examples
paulhammond@raspberrypi:~/pidog/examples $ sudo python3 4_response.py
config_file: /home/paulhammond/.config/pidog/pidog.conf
robot_hat init … done
imu_sh3001 init … done
rgb_strip init … done
dual_touch init … done
sound_direction init … done
sound_effect init … pinctrl set 20 op dh
done
ultrasonic init … fail
Process sensory_process:
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 411, in pin
pin = self.pins[info]
~~~~~~~~~^^^^^^
KeyError: PinInfo(number=7, name=‘GPIO4’, names=frozenset({‘BOARD7’, ‘BCM4’, 4, ‘WPI7’, ‘J8:7’, ‘GPIO4’, ‘4’}), pull=‘’, row=4, col=1, interfaces=frozenset({‘’, ‘dpi’, ‘spi’, ‘uart’, ‘i2c’, ‘gpio’}))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.11/dist-packages/pidog-1.3.9-py3.11.egg/pidog/pidog.py”, line 583, in sensory_process_work
trig = Pin(‘D1’)
^^^^^^^^^
File “/usr/local/lib/python3.11/dist-packages/robot_hat/pin.py”, line 96, in init
self.setup(mode, pull, active_state)
File “/usr/local/lib/python3.11/dist-packages/robot_hat/pin.py”, line 134, in setup
self.gpio = OutputDevice(self._pin_num)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/gpiozero/devices.py”, line 108, in call
self = super().call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/gpiozero/output_devices.py”, line 74, in init
super().init(pin, pin_factory=pin_factory)
File “/usr/lib/python3/dist-packages/gpiozero/mixins.py”, line 75, in init
super().init(*args, **kwargs)
File “/usr/lib/python3/dist-packages/gpiozero/devices.py”, line 553, in init
pin = self.pin_factory.pin(pin)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 413, in pin
pin = self.pin_class(self, info)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/gpiozero/pins/lgpio.py”, line 126, in init
lgpio.gpio_claim_input(
File “/usr/lib/python3/dist-packages/lgpio.py”, line 755, in gpio_claim_input
return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/lgpio.py”, line 458, in _u2i
raise error(error_text(v))
lgpio.error: ‘GPIO busy’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.11/multiprocessing/process.py”, line 314, in _bootstrap
self.run()
File “/usr/lib/python3.11/multiprocessing/process.py”, line 108, in run
self._target(*self._args, **self._kwargs)
File “/usr/local/lib/python3.11/dist-packages/pidog-1.3.9-py3.11.egg/pidog/pidog.py”, line 590, in sensory_process_work
raise ValueError(e)
ValueError: ‘GPIO busy’
distance.value: -1.0 cm, touch N
distance.value: -1.0 cm, touch N
distance.value: -1.0 cm, touch N
distance.value: -1.0 cm, touch N

From the error message, the problem mainly lies in the failed initialization of the ultrasonic sensor, which prevents subsequent GPIO operations from proceeding normally.
Ensure that the ultrasonic sensor is properly connected to the GPIO pins of the Raspberry Pi.
Check for loose or damaged connecting wires.
Sometimes the state of the GPIO pins may remain occupied because they were not properly released by the previous program, restarting the Raspberry Pi can release all GPIO pins.

Hi, Thanks for your quick reply. I’ve done all of the above and get the same result. Not sure what to do next. I’m suspecting a hardware issue with the hat.

I have the same indication. Contacted the service they replied nicely with the check cable advice. I also tried with a new cable and another ultrasonic module (same as original) and it does not work. Contacted the service today…let’s see.

We tested the program and it seems to be fine. You mentioned before that you measured GND to get 3.3v, is that the GND of the ultrasonic module? Did you reverse the GND and 3v3 of the cable?
Also if you want to modify the pin test, you need to modify the pin of the touch module or not initialize the touch module, otherwise it will lead to “GPIO busy, in fact, you can run ultrasonic_test. py in ‘~/pidog/test/’ directory, it will only initialize the touch module, but it will not initialize the touch module, it will not initialize the touch module. In fact you can run ultrasonic_test.py in the “~/pidog/test/” directory, which will only initialize the ultrasonic module.

I ran the ultrasonic_test.py in the ~/pidog/test directory and got the error output in the attached document. I noticed there is no ultrasonic.py file in the robot-hat folder (see screenshot).

(Attachment ultrasonic_error.rtf is missing)

(attachments)

Not sure if the attachment came through. Here is the error I get from running ultrasonc_test.py. Also, as mentioned before there is no ultrasonic.py in the robot_hat directory.

%Run ultrasonic_test.py
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 411, in pin
pin = self.pins[info]
KeyError: PinInfo(number=7, name=‘GPIO4’, names=frozenset({‘J8:7’, 4, ‘WPI7’, ‘4’, ‘BCM4’, ‘GPIO4’, ‘BOARD7’}), pull=‘’, row=4, col=1, interfaces=frozenset({‘’, ‘uart’, ‘i2c’, ‘gpio’, ‘dpi’, ‘spi’}))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/paulhammond/pidog/test/ultrasonic_test.py”, line 4, in
ultrasonic = Ultrasonic(Pin(“D1”), Pin(“D0”))
File “/usr/local/lib/python3.11/dist-packages/robot_hat/pin.py”, line 96, in init
self.setup(mode, pull, active_state)
File “/usr/local/lib/python3.11/dist-packages/robot_hat/pin.py”, line 134, in setup
self.gpio = OutputDevice(self._pin_num)
File “/usr/lib/python3/dist-packages/gpiozero/devices.py”, line 108, in call
self = super().call(*args, **kwargs)
File “/usr/lib/python3/dist-packages/gpiozero/output_devices.py”, line 74, in init
super().init(pin, pin_factory=pin_factory)
File “/usr/lib/python3/dist-packages/gpiozero/mixins.py”, line 75, in init
super().init(*args, **kwargs)
File “/usr/lib/python3/dist-packages/gpiozero/devices.py”, line 553, in init
pin = self.pin_factory.pin(pin)
File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 413, in pin
pin = self.pin_class(self, info)
File “/usr/lib/python3/dist-packages/gpiozero/pins/lgpio.py”, line 126, in init
lgpio.gpio_claim_input(
File “/usr/lib/python3/dist-packages/lgpio.py”, line 755, in gpio_claim_input
return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))
File “/usr/lib/python3/dist-packages/lgpio.py”, line 458, in _u2i
raise error(error_text(v))
lgpio.error: ‘GPIO busy’

Same here. I get exactly the same error with the ultrasonic_test.py in the /test directory. But there is also the ultrasonic init fail message. Also with a new module and cable. Contacted the service. So far no answer.

We are very sorry that we have not reproduced the problem you are experiencing.
Confirm that the hardware module is connected correctly.
What model of Raspberry Pi are you currently using, what system are you using, and what is the system version, please let us know so that we can reproduce the problem.

I have verified all hardware is connected correctly according to the installation instructions. I am using a Raspberry PI 4. I swapped the PI 4 out with another one and still have the same issue. I reloaded the latest version of the Raspberry PI OS onto a new SD card and installed the required modules. As stated before, I tried a new ultrasonic module and cable. I verified both modules work using an Arduino Board. This leaves the robot hat module as the problem since I don’t have another one to test. I measured the voltage from ground to D0 and D1 and get a reading of only .6 volts. You won’t be able to recreate the issue if this is a hardware issue.

Please contact our after-sales email: service@sunfounder.com
We will resend you a new RobotHat.

I discovered what the problem is. I installed the Python3 related packages listed in step 1 in the Installing All Modules section of the Quick Guide. I shouldn’t have done that since that is only for the Lite version OS. Perhaps extra wording could be added to warn people using the full version to skip this step. Anyway, I did a fresh install and now everything works.