Temperature Sensor DHT11/22 via GPIO using Adafruit Libraries

  • Hey,

    i am trying to connect a DHT11/22 temperature sensor to my Libreelec/RPi2 using the GPIO connectors to get current room temperature (and humidity).

    I have installed the "Adafruit Libraries" Addon from the Official "LibreELEC" Addon repository. This includes "Adafruit_DHT" Libraries that are intended to do that.

    But unfortunately i am struggeling with using this Libraries properly. ?(

    I tried a simple python example script to put out the current temperature:

    Script source: adafruitdht.py

    I added these lines to load the DHT libraries:

    Python
    libPath = '/storage/.kodi/addons/virtual.adafruit-libraries/lib/'
    if not libPath in sys.path: sys.path.append(libPath)
    import Adafruit_DHT

    But still only get errors /shrug

    Are there some docs i can read regarding Libreelec and the Adafruit Libraries? (I have found nothing so far)

    Are the Adafruit Libraries intended to be used from the commandline?

    Or do i need to call them from Kodi?

    Are there any examples i can have a look at?

    I appreciate any hint or Idea. :)

    Thanks

    Thomas

  • Hi Thomas,

    good news first:

    your code looks ok.

    bad news:

    this can be an problem in adafruit library itself. Is not the first library, with this kind of problem.

    But i need more information, about your setup.

    1. which LE version, you are running?

    2. which RPi do you use?

    3. output of `cat /proc/cpuinfo` from your RPi console


    Bye,

    Sascha

  • Hey Sascha,

    sorry, missed the notification of your reply :rolleyes:

    • Libreelec is the latest official Version: LibreELEC (official): 8.2.5 (RPi2.arm)
    • Board is a RPi2 / B
    • cat /proc/cpuinfo puts out:
  • 8|

    Code
    /storage#> python ./AdafruitDHT.py 22 4
    Temp=21.6*  Humidity=54.4%

    This is ... woah! This makes me sooo happy :love:


    THANK YOU!!

    Will this updated library go into the official repo so all users will receive it?

  • Just to have mentioned it: the retrieval seems quite slow:

    Code
    time python ./AdafruitDHT.py 22 4
    Temp=21.7*  Humidity=54.4%
    real    0m 8.38s

    But i have no experience if this is faster when using s/th like raspbian. /shrug

    At all this is no problem for my needs

    Now i can order some more sensors 8o

    Thanks again for your fast help!

  • Hello,

    I am having almost the same problem with bad Adafruit Libraries on LE 9.2.4 running on RPI3 and RPI4.

    Traceback (most recent call last):
    File "./dht.py", line 42, in <module>
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    File "/storage/.kodi/addons/virtual.adafruit-libraries/lib/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
    File "/storage/.kodi/addons/virtual.adafruit-libraries/lib/Adafruit_DHT/common.py", line 80, in read
    platform = get_platform()
    File "/storage/.kodi/addons/virtual.adafruit-libraries/lib/Adafruit_DHT/common.py", line 55, in get_platform
    from . import Raspberry_Pi_2
    File "/storage/.kodi/addons/virtual.adafruit-libraries/lib/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in <module>
    from . import Raspberry_Pi_2_Driver as driver
    ImportError: cannot import name Raspberry_Pi_2_Driver

    If I install old library from Sascha I don't have any more python error but I don't get any reading from DHT11:

    Failed to get reading. Try again!

    Any ideas ?

    Thank you

  • I tested the DHT sensor on latest Raspberry Pi OS and it is OK, I can get the values from it.

    Upgraded to latest stable LE 9.2.6 both RPI3+ and RPI4 and I have the same problems as before.

    It is a problem with latest Adafruit libraries from LibreELEC.

    Any chance for a fix from LE team ?

    Thank you