Changed the name of the .py file to adafruit_dht; update api.rst and … (#2)

* Changed the name of the .py file to adafruit_dht; update api.rst and example file to reference new name.

* re-raise the exception after the import of adafruit_dhtlib

* Remove lib from comment.
This commit is contained in:
Michael McWethy 2017-09-19 12:55:07 -07:00 committed by Scott Shawcroft
parent 9b594687c4
commit 7f964a840e
3 changed files with 18 additions and 14 deletions

View file

@ -30,8 +30,12 @@ CircuitPython support for the DHT11 and DHT22 temperature and humidity devices.
import array
import time
import pulseio
try:
import pulseio
except ImportError as excpt:
print("adafruit_dht requires the pulseio library, but it failed to load."+
" Note that CircuitPython does not support pulseio on all boards.")
raise excpt
class DHTBase:
""" base support for DHT11 and DHT22 devices
@ -66,9 +70,9 @@ class DHTBase:
stop is the index to convert upto but not including
Returns an integer containing the converted 1 and 0 bites
Returns an integer containing the converted 1 and 0 bits
"""
# humidity 16 bites
binary = 0
hi_sig = False
for bit_inx in range(start, stop):
@ -99,20 +103,20 @@ class DHTBase:
with pulseio.PulseIn(self._pin, 81, True) as pulse_in:
# The DHT type device use a specialize 1-wire protocol
# The microprocess first sends a LOW signal for a
# specific length of time. Then the device send back a
# series HIGH and LOW signals. The length the signals
# determine the device values.
# The microprocessor first sends a LOW signal for a
# specific length of time. Then the device sends back a
# series HIGH and LOW signals. The length the HIGH signals
# represents the device values.
pulse_in.pause()
pulse_in.clear()
pulse_in.resume(self._trig_wait)
# loop until we get the return pulse we need or
# time out after 2 seconds
# time out after 1/2 seconds
while True:
if len(pulse_in) >= 80:
break
if time.monotonic()-tmono > 0.5: # time out after 2 seconds
if time.monotonic()-tmono > 0.5: # time out after 1/2 seconds
break
pulse_in.pause()
@ -140,7 +144,7 @@ class DHTBase:
buf = array.array('B')
for byte_start in range(0, 80, 16):
buf.append(self._pulses_to_binary(pulses, byte_start, byte_start+16))
#print(bites)
#print(buf)
# humidity is 2 bytes
if self._dht11:

View file

@ -2,5 +2,5 @@
DHT Libary Documentation
============================
.. automodule:: adafruit_dhtlib
.. automodule:: adafruit_dht
:members:

View file

@ -5,7 +5,7 @@ the DHT device data wire is connected to board.D2
"""
# import for dht devices
import time
import adafruit_dhtlib
import adafruit_dht
from board import D2
#imports for 7-segment display device
@ -22,7 +22,7 @@ display = bcddigits.BCDDigits(spi, cs, nDigits=8)
display.brightness(5)
#initial the dht device
dhtDevice = adafruit_dhtlib.DHT22(D2)
dhtDevice = adafruit_dht.DHT22(D2)
while True:
try: