forked from mrmcwethy/Adafruit_CircuitPython_DHT
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from jerryneedell/jerryn_fix_pr_14
Add RPi (non-pulseio) support
- Loading branch information
Showing
3 changed files
with
68 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import time | ||
from board import D2 | ||
import board | ||
import adafruit_dht | ||
|
||
#initial the dht device | ||
dhtDevice = adafruit_dht.DHT22(D2) | ||
# Initial the dht device, with data pin connected to: | ||
dhtDevice = adafruit_dht.DHT22(board.D18) | ||
|
||
while True: | ||
try: | ||
# show the values to the serial port | ||
temperature = dhtDevice.temperature * (9 / 5) + 32 | ||
# Print the values to the serial port | ||
temperature_c = dhtDevice.temperature | ||
temperature_f = temperature_c * (9 / 5) + 32 | ||
humidity = dhtDevice.humidity | ||
print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) | ||
print("Temp: {:.1f} F / {:.1f} C Humidity: {}% " | ||
.format(temperature_f, temperature_c, humidity)) | ||
|
||
except RuntimeError as error: | ||
print(error.args) | ||
# Errors happen fairly often, DHT's are hard to read, just keep going | ||
print(error.args[0]) | ||
|
||
time.sleep(2.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,6 @@ | |
display.show() | ||
|
||
except RuntimeError as error: | ||
print(error.args) | ||
print(error.args[0]) | ||
|
||
time.sleep(2.0) |