Python Forum
Raspberry PI with DHT22 Sensors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry PI with DHT22 Sensors
#1
guys please can you help the noob

i have connected 6 x DHT22 Temperature and Humidity Sensors on my Raspberry PI 4

I am getting a reading from the first DHT22 Sensor on GPIO 22 [ The Other DHT22 Sensors are Connected to GPIO 2, 3, 4, 17, 27 ]

I want to test the Other 5 x DHT22 Sensors

I am Using the Following code to test One DHT22 Sensor

I need to change the Same Code to Test All 6 x DHT22 Sensors

What do i need to do in the code to Test All 6 x DHT22 Sensors with One Python File?

CODE I am Using:

import adafruit_dht
import time


class DHT22Module:
    def __init__(self, pin):
        self.dht_device = adafruit_dht.DHT22(pin)

    def get_sensor_readings(self):
        while True:
            try:
                # Print the values to the serial port
                temperature_c = self.dht_device.temperature
                temperature_f = temperature_c * (9 / 5) + 32
                humidity = self.dht_device.humidity
                print(
                    "Temp: {:.1f} F / {:.1f} C    Humidity: {}% ".format(
                        temperature_f, temperature_c, humidity
                    )
                )
                return temperature_c, humidity

            except RuntimeError as error:
                # Errors happen fairly often, DHT's are hard to read
                print(error.args[0])
                time.sleep(2.0)
                continue
            except Exception as error:
                self.dht_device.exit()
                raise error
buran write May-11-2023, 10:45 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Raspberry PI with DHT22 Sensors - by itpilot - May-11-2023, 12:05 PM
RE: Raspberry PI with DHT22 Sensors - by deanhystad - May-11-2023, 07:02 PM
RE: Raspberry PI with DHT22 Sensors - by itpilot - May-11-2023, 08:01 PM
RE: Raspberry PI with DHT22 Sensors - by deanhystad - May-11-2023, 08:08 PM
RE: Raspberry PI with DHT22 Sensors - by itpilot - May-11-2023, 09:33 PM
RE: Raspberry PI with DHT22 Sensors - by itpilot - May-11-2023, 09:15 PM
RE: Raspberry PI with DHT22 Sensors - by deanhystad - May-12-2023, 02:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  get data (temperature and humidity) from DHT22 into CSV and sending them over the net apollo 0 5,219 Apr-16-2021, 07:49 PM
Last Post: apollo
  Convert looping home security to a one time scan of switches and sensors duckredbeard 0 2,328 Dec-08-2020, 04:31 AM
Last Post: duckredbeard

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020