4 from __future__
import absolute_import, division, print_function, unicode_literals
12 The DHT11 class is a stripped version of the DHT22 sensor code by joan2937. 13 You can find the initial implementation here: 14 - https://github.com/srounet/pigpio/tree/master/EXAMPLES/Python/DHT22_AM2302_SENSOR 18 >>> sensor = DHT11(pi, 4) # 4 is the data GPIO pin connected to your sensor 19 >>> for response in sensor: 20 .... print("Temperature: {}".format(response['temperature'])) 21 .... print("Humidity: {}".format(response['humidity'])) 26 pi (pigpio): an instance of pigpio 27 gpio (int): gpio pin number 40 Clears the internal gpio pull-up/down resistor. 43 self.pi.set_pull_up_down(self.
gpio, pigpio.PUD_OFF)
44 self.pi.set_watchdog(self.
gpio, 0)
49 Monitors RISING_EDGE changes using callback. 59 Either Edge callbacks, called each time the gpio edge changes. 60 Accumulate the 40 data bits from the dht11 sensor. 67 handler = level_handlers[level]
87 self.pi.set_watchdog(self.
gpio, 0)
90 if not (total & 255) == self.
checksum:
92 elif 16 <= self.
bit < 24:
94 elif 0 <= self.
bit < 8:
114 Handle Either signal. 116 self.pi.set_watchdog(self.
gpio, 0)
120 Start reading over DHT11 sensor. 122 self.pi.write(self.
gpio, pigpio.LOW)
124 self.pi.set_mode(self.
gpio, pigpio.INPUT)
125 self.pi.set_watchdog(self.
gpio, 200)
130 Stop reading sensor, remove callbacks. 132 self.pi.set_watchdog(self.
gpio, 0)
134 self.either_edge_cb.cancel()
139 Support the iterator protocol. 145 Call the read method and return temperature and humidity informations. 155 if __name__ ==
'__main__':
159 print(
"temperature: {}".format(d[
'temperature']))
160 print(
"humidity: {}".format(d[
'humidity']))
def _edge_FALL(self, tick, diff)
def _edge_RISE(self, tick, diff)
def __init__(self, pi, gpio)
def _edge_EITHER(self, tick, diff)
def register_callbacks(self)
def either_edge_callback(self, gpio, level, tick)