有没有如何在谷歌 aiy 语音板上使用 GPIO 的数字输入或模拟输入的示例?



我无法读取运动传感器 (HC-SR501( 的输入,该传感器连接到我的 aiy 语音套件语音引擎盖上的PIN_A扩展引脚。

下面是代码和错误消息,请阐明一些内容。

法典:

from gpiozero import MotionSensor
from aiy.pins import (PIN_A, PIN_B, PIN_C, PIN_D)
pir = MotionSensor(PIN_A)
pir.wait_for_motion()
print("Motion detected!")

错误信息:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 51, in __init__
self.pin.pull = pull
File "/usr/lib/python3/dist-packages/gpiozero/pins/__init__.py", line 279, in <lambda>
lambda self, value: self._set_pull(value),
File "/opt/aiy/projects-python/src/aiy/pins.py", line 569, in _set_pull
'Only pull up is supported right now (%s)' % pull)
gpiozero.exc.PinFixedPull: Only pull up is supported right now (down)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "motion_sensor.py", line 4, in <module>
pir = MotionSensor(PIN_A)
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 95, in __call__
self = super(GPIOMeta, cls).__call__(*args, **kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 451, in __init__
pin_factory=pin_factory
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 163, in __init__
pin, pull_up, pin_factory=pin_factory
File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 164, in __init__
super(EventsMixin, self).__init__(*args, **kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 53, in __init__
self.close()
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 185, in close
super(SmoothedInputDevice, self).close()
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 393, in close
self.pin_factory.release_pins(self, self._pin.number)
AttributeError: 'HatPin' object has no attribute 'number'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 483, in _shutdown
_devices_shutdown()
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 476, in _devices_shutdown
dev.close()
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 185, in close
super(SmoothedInputDevice, self).close()
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 393, in close
self.pin_factory.release_pins(self, self._pin.number)
AttributeError: 'HatPin' object has no attribute 'number'
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 122, in __del__
self.close()
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 185, in close
super(SmoothedInputDevice, self).close()
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 393, in close
self.pin_factory.release_pins(self, self._pin.number)
AttributeError: 'HatPin' object has no attribute 'number'

你解决了吗?

通过查看 API 和错误消息,尝试更改代码的第 3 行

pir = MotionSensor(PIN_A)

pir = MotionSensor(PIN_A, pull_up=True)

相关内容

  • 没有找到相关文章

最新更新