I'm trying to use an HC-SR04 distance sensor with the AIY voice kit. I used the setup in the image link below, except using bonnet PIN_A and PIN_B instead of RPi GPIO23 and 24, and I used a 1000 Ohm and 2000 Ohm resistor for the voltage divider (rather than a 330 and a 470).
gpiozero docs distance sensor basic recipe
Here is my script:
from gpiozero import DistanceSensor
from time import sleep
from aiy.pins import PIN_A
from aiy.pins import PIN_B
sensor = DistanceSensor(echo=PIN_A, trigger=PIN_B)
while True:
print('Distance to nearest object is ', sensor.distance, 'm')
sleep(1)
When I run it, I get the following error:
Traceback (most recent call last): File "sensor_demo.py", line 6, in sensor = DistanceSensor(echo=PIN_A, trigger=PIN_B) 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/gpiozero/input_devices.py", line 856, in init partial=partial, ignore=frozenset({None}), pin_factory=pin_factory File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 277, in init pin_factory=pin_factory) File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 197, in init super(EventsMixin, self).init(*args, **kwargs) File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 103, in init self.pin.pull = pull File "/usr/lib/python3/dist-packages/gpiozero/pins/init.py", line 337, in lambda self, value: self._set_pull(value), File "/home/pi/AIY-projects-python/src/aiy/pins.py", line 605, in _set_pull 'Only pull up is supported right now (%s)' % pull) gpiozero.exc.PinFixedPull: Only pull up is supported right now (down)
When I run it on a RPi 1 B+ directly (with RPi GPIO pins), it works fine, so I think it has to do with the GPIO expansion pins on the bonnet, especially when they are used for input, like here, here, and here.
Is there any way to make this work with the GPIO expansion pins, or do I have to take the RPi 0 out of the box and use its pins?