- D4 issue with distance measurer

Hi,
Just got a new pi-top, struggling to get the distance measurer to work with D4 output, as getting error - works fine with different (D5 etc)

  • Traceback (most recent call last):
    File “/home/pi/mu_code/us.py”, line 9, in
    ultrasonic_sensor = PMAUltrasonicSensor(“D4”)
    File “/usr/lib/python3/dist-packages/gpiozero/devices.py”, line 124, in call
    self = super(GPIOMeta, cls).call(*args, **kwargs)
    File “/usr/lib/python3/dist-packages/ptpma/ultrasonic_sensor.py”, line 39, in init
    self.pin.when_changed = self._echo_changed
    File “/usr/lib/python3/dist-packages/gpiozero/pins/init.py”, line 450, in
    lambda self, value: self._set_when_changed(value),
    File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 314, in _set_when_changed
    self._enable_event_detect()
    File “/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py”, line 250, in _enable_event_detect
    bouncetime=self._bounce)
    RuntimeError: Failed to add edge detection

Any ideas?!

This works:
from ptpma.components import PMAUltrasonicSensor, PMALed
from time import sleep

ultrasonic_sensor = PMAUltrasonicSensor(“D2”)
red_led = PMALed(“D4”)

while True:
print(ultrasonic_sensor.distance)
sleep(0.1)
if ultrasonic_sensor.distance < 0.30:
red_led.on()
else:
red_led.off()

But if the assignment to pins is swapped, I get the error:
ultrasonic_sensor = PMAUltrasonicSensor(“D4”)
red_led = PMALed(“D2”)