Adafruit_CircuitPython_DHT: DHT-Blinka fail when using libgpiod

I just wanted to test the DHT22 sensor as in https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup but first test the functionality of Blinka.

Also I just encountered this using digitalio.DigitalInOut:

In [9]: dhtDevice = adafruit_dht.DHT22(pin)

In [10]: dhtDevice.temperature
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-bb6e5b54f869> in <module>()
----> 1 dhtDevice.temperature

/usr/local/lib/python3.7/dist-packages/adafruit_dht.py in temperature(self)
    225             data returned from the device (try again)
    226         """
--> 227         self.measure()
    228         return self._temperature
    229 

/usr/local/lib/python3.7/dist-packages/adafruit_dht.py in measure(self)
    179                 pulses = self._get_pulses_pulseio()
    180             else:
--> 181                 pulses = self._get_pulses_bitbang()
    182             #print(len(pulses), "pulses:", [x for x in pulses])
    183 

/usr/local/lib/python3.7/dist-packages/adafruit_dht.py in _get_pulses_bitbang(self)
    135         """
    136         pulses = array.array('H')
--> 137         with DigitalInOut(self._pin) as dhtpin:
    138             # we will bitbang if no pulsein capability
    139             transitions = []

/usr/local/lib/python3.7/dist-packages/digitalio.py in __init__(self, pin)
     82 
     83     def __init__(self, pin):
---> 84         self._pin = Pin(pin.id)
     85         self.direction = Direction.INPUT
     86 

AttributeError: 'DigitalInOut' object has no attribute 'id'

and using the board.PXX I get this:

In [1]: import board

In [2]: import adafruit_dht

In [3]: dhtDevice = adafruit_dht.DHT22(board.PC4)

In [4]: dhtDevice.temperature
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-4-bb6e5b54f869> in <module>()
----> 1 dhtDevice.temperature

/usr/local/lib/python3.7/dist-packages/adafruit_dht.py in temperature(self)
    225             data returned from the device (try again)
    226         """
--> 227         self.measure()
    228         return self._temperature
    229 

/usr/local/lib/python3.7/dist-packages/adafruit_dht.py in measure(self)
    179                 pulses = self._get_pulses_pulseio()
    180             else:
--> 181                 pulses = self._get_pulses_bitbang()
    182             #print(len(pulses), "pulses:", [x for x in pulses])
    183 

/usr/local/lib/python3.7/dist-packages/adafruit_dht.py in _get_pulses_bitbang(self)
    147             dhtval = True   # start with dht pin true because its pulled up
    148             dhtpin.direction = Direction.INPUT
--> 149             dhtpin.pull = Pull.UP
    150             while time.monotonic() - timestamp < 0.25:
    151                 if dhtval != dhtpin.value:

/usr/local/lib/python3.7/dist-packages/digitalio.py in pull(self, pul)
    137             self.__pull = pul
    138             if pul is Pull.UP:
--> 139                 self._pin.init(mode=Pin.IN, pull=Pin.PULL_UP)
    140             elif pul is Pull.DOWN:
    141                 if hasattr(Pin, "PULL_DOWN"):

/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py in init(self, mode, pull)
     45                 if pull != None:
     46                     if pull == self.PULL_UP:
---> 47                         raise NotImplementedError("Internal pullups not supported in libgpiod, use physical resistor instead!")
     48                     elif pull == self.PULL_DOWN:
     49                         raise NotImplementedError("Internal pulldowns not supported in libgpiod, use physical resistor instead!")

NotImplementedError: Internal pullups not supported in libgpiod, use physical resistor instead!

Is it possible to set a different pull on pin? Let’s say I have already connected the physical resistor on the sensor.

More details:

Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> board.detector.chip.id
'SUN8I'
>>> board.detector.board.id
'ORANGE_PI_PLUS_2E'
>>> 

This relates to: https://github.com/adafruit/Adafruit_Blinka/issues/245

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (1 by maintainers)

Commits related to this issue

Most upvoted comments

@dherrada, @makermelissa maybe a possible solution would be:

  1. Set an environment bool variable to suppress warnings and just pass over the exception if it is set up on this lines within Blinka.
  2. In this module (DHT one) maybe a bit of refactoring to take the last 80 pulses if the length of the pulses is within a threshold (81-83) ?.

@SecT0uch both DHT11 modules I used had the resistor on it. The board seems like it does not have a built-in pull resistor as per the datasheet and I could also not see any information regarding PWM but I guess it can be simulated somehow. BTW sorry for not replying earlier to your questions.

If there something else needed on my side just let me know.

Hey! Another update.

I finally got to read at least once 😃 with another sensor (Seems like the other one was defective) SEE TRY NUMBER 9:

Try number 1
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
81 pulses: [87, 85, 51, 35, 53, 18, 51, 35, 52, 68, 52, 18, 68, 68, 52, 68, 53, 18, 68, 18, 51, 18, 68, 18, 52, 20, 52, 35, 51, 18, 51, 35, 51, 18, 51, 36, 51, 18, 51, 35, 51, 67, 52, 18, 68, 67, 53, 18, 51, 84, 52, 18, 51, 35, 126, 18, 51, 35, 54, 19, 52, 35, 52, 18, 51, 35, 51, 18, 51, 68, 68, 18, 55, 68, 52, 35, 52, 68, 51, 68, 51]
Checksum did not validate. Try again.


Try number 2
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
0 pulses: []
DHT sensor not found, check wiring


Try number 3
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
81 pulses: [51, 18, 52, 34, 51, 18, 52, 83, 52, 18, 51, 83, 51, 18, 52, 67, 67, 18, 51, 35, 51, 18, 51, 36, 51, 18, 51, 35, 51, 18, 51, 35, 51, 19, 50, 35, 51, 18, 67, 67, 51, 18, 67, 67, 52, 18, 51, 84, 51, 18, 51, 55, 22, 35, 51, 18, 53, 34, 51, 18, 51, 34, 51, 18, 67, 18, 51, 18, 67, 67, 53, 18, 67, 68, 51, 18, 51, 84, 51, 18, 51]
Checksum did not validate. Try again.


Try number 4
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
0 pulses: []
DHT sensor not found, check wiring


Try number 5
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
81 pulses: [52, 18, 52, 35, 52, 18, 52, 84, 51, 18, 51, 68, 68, 18, 53, 68, 52, 35, 51, 18, 51, 35, 51, 19, 51, 35, 51, 18, 51, 35, 51, 18, 51, 36, 51, 18, 51, 35, 51, 68, 51, 34, 51, 68, 53, 18, 68, 68, 52, 18, 51, 35, 51, 18, 51, 35, 53, 18, 51, 35, 51, 18, 59, 19, 52, 35, 51, 18, 51, 67, 70, 18, 51, 68, 51, 35, 51, 68, 51, 18, 67]
Got temp of: 21
And hum of: 21


Try number 6
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
81 pulses: [52, 35, 52, 18, 51, 35, 52, 68, 51, 18, 68, 68, 51, 18, 53, 84, 51, 18, 51, 35, 51, 18, 51, 36, 51, 18, 51, 34, 51, 18, 51, 35, 51, 19, 58, 19, 51, 35, 51, 68, 52, 18, 67, 68, 53, 18, 68, 68, 51, 18, 51, 35, 51, 18, 51, 35, 53, 19, 52, 35, 51, 18, 51, 35, 51, 18, 51, 35, 51, 68, 53, 18, 67, 68, 51, 18, 51, 83, 51, 18, 51]
Got temp of: 21
And hum of: 21


Try number 7
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
0 pulses: []
DHT sensor not found, check wiring


Try number 8
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
81 pulses: [87, 84, 51, 35, 52, 18, 51, 35, 52, 68, 51, 18, 68, 68, 51, 67, 53, 34, 51, 18, 51, 35, 51, 18, 51, 35, 51, 18, 51, 34, 51, 18, 51, 35, 51, 19, 51, 35, 51, 18, 51, 83, 51, 18, 51, 67, 69, 18, 51, 67, 68, 18, 123, 35, 52, 18, 51, 34, 53, 18, 51, 35, 51, 18, 51, 35, 51, 18, 51, 83, 51, 18, 52, 84, 51, 18, 51, 67, 68, 67, 51]
Checksum did not validate. Try again.


Try number 9
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
81 pulses: [51, 35, 52, 18, 51, 18, 69, 68, 51, 18, 51, 84, 51, 68, 53, 18, 68, 18, 51, 18, 67, 18, 51, 36, 51, 18, 51, 35, 51, 18, 51, 35, 52, 20, 51, 35, 59, 21, 52, 67, 51, 18, 67, 68, 53, 18, 51, 84, 51, 18, 51, 35, 51, 18, 51, 35, 53, 18, 51, 35, 51, 18, 51, 35, 51, 18, 51, 34, 51, 67, 53, 35, 51, 67, 51, 18, 67, 67, 51, 67, 51]
Got temp of: 21
And hum of: 22


Try number 10
Internal pullups not supported in libgpiod, use physical resistor instead!
Invalid pull for pin: 199 with pull 1
0 pulses: []
DHT sensor not found, check wiring

So it is actually returning 81 pulses and several tries but it only converts one of the tries with the same 81 pulses.

Script I used below, I wanted to make sure there was a delay regardless of it read process was right or not.

import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT11(board.PG7)

for try_number in range(1,11):
  print(f"Try number {try_number}")
  try:
    print(f"Got temp of: {dhtDevice.temperature}")
    print(f"And hum of: {dhtDevice.humidity}")
  except RuntimeError as e:
    print(e)
    time.sleep(2)
  else:
    time.sleep(2)
  print("\n")

EDIT: it actually worked more than once 🐣 🤩