I am having trouble with a dht22 sensor. It works well for most of the time but randomly the library I am using can no longer receive a reading until I unplug then plug the sensor back in. (just disconnecting and reconnecting the GND pin is often enough) Then it will work for a while longer until the problem repeats.
I will try to describe my setup pictured in the drawing above in detail. The picture above is not a proper diagram drawing so please ask any questions if my text description falls short as well...
The DHT22 hookup is pretty straight forward 5V to
GND pin to ground,
DATA pin to a
GPIO pin (
GPIO 24 in my case). I am pulling up the
DATA to 3V3 with a 4.7K Ohm resistor. I am using the
pgpio DHT22 library. Here is the code which involve a loop in order to ignore the first couple of "bad" readings from the DHT22. (the DHT22 always gives the first two or three reading for temp and humidity as -999) also An important note is I am using about 10 feet of cat5e cable to connect the sensor directly to the pi.
#!/usr/bin/python import pigpio import DHT22 from time import sleep # initiate GPIO for pigpio pi = pigpio.pi() dht22 = DHT22.sensor(pi, 24) def readDHT22(): #get reading dht22.trigger() humidity = '%.2f' % (dht22.humidity()) temp = '%.2f' % (dht22.temperature()) return (humidity, temp) r = 0 while r < 10: humidity, temp = readDHT22() print ("trying to read temp...") r = r + 1 if '999' in humidity or '999' in temp: sleep(sleeptime) continue sleep(sleeptime) print ("H:"+humidity+"") print ("T:"+temp+"") sleep(2) break
The other part of my diagram shows the connection for a
5V relay. There is actually 5 relays connected. they each share a
5V rail and a
Ground rail. Each relay has its own
GPIO connection used to send a
HIGH signal to a transistor that acts as a switch for the relay.
The reason I mention the relays in my problem is I suspect that my issue could be that I am drawing to much current from the pi.
What basic steps should I take to begin trouble shooting an issue like this?
How can I accurately calculate the amperage of my circuit to determine if I am drawing more than avaible? ( As I understand the mx from the 3v3 rail is
50mA, and the max from
5V is the max of the power supply to the
raspberry pi which is 2000mA in my case) I dont know the resistance of the relays or how to figure that out accurately either.
As a secondary question id like to ask about a recommendation for wiring the dht22 that was detailed in the DHT22.py library file:
For 5V operation connect pin 1 to 5V and pin 4 to ground. The following pin 2 connection works for me. Use at YOUR OWN RISK. 5V--5K_resistor--+--10K_resistor--Ground | DHT22 pin 2 -----+ | gpio ------------+
Here is a drawing of how I understand to wire this up... Is it correct?