adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
439 stars 327 forks source link

AttributeError: pin instead of pin.id #762

Closed matevz closed 6 months ago

matevz commented 6 months ago

Board Name

Raspberry Pi 3

Steps

On a Raspberry Pi 3 with a fresh 64-bit Raspian 2023-12-05 version I did

  1. pip install adafruit-circuitpython-dht
  2. run my temperature reading script:
    import adafruit_dht
    SENSOR = adafruit_dht.DHT22(4)
    t, h = SENSOR.temperature, SENSOR.humidity
    print(t,h)
    SENSOR.exit()
  3. Got error:
    File "/home/pi/chickencoop/backend/temperature.py", line 38, in read_temp_and_humidity
    t, h = SENSOR.temperature, SENSOR.humidity
    File "/home/pi/.local/lib/python3.9/site-packages/adafruit_dht.py", line 273, in temperature
    self.measure()
    File "/home/pi/.local/lib/python3.9/site-packages/adafruit_dht.py", line 220, in measure
    pulses = self._get_pulses_bitbang()
    File "/home/pi/.local/lib/python3.9/site-packages/adafruit_dht.py", line 162, in _get_pulses_bitbang
    with DigitalInOut(self._pin) as dhtpin:
    File "/home/pi/.local/lib/python3.9/site-packages/digitalio.py", line 182, in __init__
    self._pin = Pin(pin.id)
    AttributeError: 'int' object has no attribute 'id'

Description

When changing this line https://github.com/adafruit/Adafruit_Blinka/blob/60fa43167c45c1ab162292dcf26d6dce9e001851/src/digitalio.py#L182

to

self._pin = Pin(pin)

it worked. Not sure, if there are some versions borked in pypi or it's an actual bug.

Additional information

No response

makermelissa commented 6 months ago

It's giving an attribute error because it expects pin to be a pin instead of an integer. It looks like this is caused by initializing the DHT22 with an integer instead of a pin. The 4 should actually be something like board.D4 instead. See the DHT simpletest for example: https://github.com/adafruit/Adafruit_CircuitPython_DHT/blob/main/examples/dht_simpletest.py