Hi,
I'm trying to use a DHT22 humidity sensor with the Raspberry Pi 5. I figured it would be simple to do but I am struggling and I would appreciate any help. I've downloaded Raspi-blinka after activating my venv. However, I keep receiving the error that there is no module named 'board' when I run the following code (that I found online):
I am very confused. Please help me.
Thank you.
I'm trying to use a DHT22 humidity sensor with the Raspberry Pi 5. I figured it would be simple to do but I am struggling and I would appreciate any help. I've downloaded Raspi-blinka after activating my venv. However, I keep receiving the error that there is no module named 'board' when I run the following code (that I found online):
Code:
import timeimport boardimport adafruit_dht# Initial the dht device, with data pin connected to:dhtDevice = adafruit_dht.DHT22(board.D4)# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.# This may be necessary on a Linux single board computer like the Raspberry Pi,# but it will not work in CircuitPython.# dhtDevice = adafruit_dht.DHT22(board.D24, use_pulseio=False)while True: try: # Print the values to the serial port temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity print( "Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format( temperature_f, temperature_c, humidity ) ) except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going print(error.args[0]) time.sleep(2.0) continue except Exception as error: dhtDevice.exit() raise error time.sleep(2.0)
Thank you.
Statistics: Posted by oldchapstick — Mon Mar 18, 2024 2:30 am