Ejemplo n.º 1
0
                time.sleep(NO_RESPONSE_DELAY)
            elif res == ERROR_BAD_DATA_CHECKSUM.value:
                if DEBUG:
                    print "bad checksum"
                time.sleep(0)
            if DEBUG:
                print "retry #%d" % (i+1)
        else:
            raise IOError("read failed after %d attempts" % (READ_ATTEMPTS,))
            
        return (humidity.value, temperature.value)

###############################################################################
# TEST CODE
###############################################################################
if __name__ == "__main__":
    DHTLibrary.setup('BCM')
    DATAPIN = 4
    dht = DHT22(pin = DATAPIN)
    
    try:
        while True:
            print "---"
            H, T = dht.read()
            print "timestamp: %s" % time.time()
            print "humidity: %0.2f" % H
            print "temperature: %0.2f" % T
            time.sleep(1.0)
    except KeyboardInterrupt:
        pass
Ejemplo n.º 2
0
def setup(pinmode = DEFAULT_PINMODE):
    DHTLibrary.setup(pinmode=pinmode)