szazo / DHT11_Python

Pure Python library for reading DHT11 sensor on Raspberry Pi
MIT License
301 stars 227 forks source link

RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM) #20

Closed emichester closed 3 years ago

emichester commented 3 years ago

I had the following issue when using the package in a loop:

  File "/home/pi/Workspace/miwebsitebot/modulos/dht11/__init__.py", line 34, in read
    RPi.GPIO.setup(self.__pin, RPi.GPIO.OUT)
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)

Solved changing __init__.py. Just add after line 31 the initialization mode. It will result like this:

30     def __init__(self, pin):
31         self.__pin = pin
32         RPi.GPIO.setmode(RPi.GPIO.BCM)