-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
#https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup | ||
|
||
import time | ||
import board | ||
import adafruit_dht | ||
|
||
# Initial the dht device, with data pin connected to: | ||
dhtDevice = adafruit_dht.DHT22(board.D18) | ||
|
||
# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio. | ||
# This may be necessary on a Linux single board computer like the Raspberry Pi, | ||
# but it will not work in CircuitPython. | ||
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False) | ||
|
||
while True: | ||
try: | ||
# 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 / {:.1f} C Humidity: {}% ".format( | ||
temperature_f, temperature_c, humidity | ||
) | ||
) | ||
|
||
except RuntimeError as error: | ||
# Errors happen fairly often, DHT's are hard to read, just keep going | ||
print(error.args[0]) | ||
time.sleep(2.0) | ||
continue | ||
except Exception as error: | ||
dhtDevice.exit() | ||
raise error | ||
|
||
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