-
Notifications
You must be signed in to change notification settings - Fork 2
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
root
committed
Jan 28, 2021
1 parent
fa13e56
commit ce480b8
Showing
2 changed files
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/python3 | ||
import Adafruit_DHT | ||
|
||
gpiopin=17 | ||
|
||
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, gpiopin) | ||
print("Temperature: {:.1f} °C Humidity: {:.1f} %".format(temperature, humidity)) |
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,19 @@ | ||
#!/usr/bin/python3 | ||
import time, adafruit_dht | ||
|
||
gpiopin=4 | ||
|
||
# Initial the dht device, with data pin connected to: | ||
dhtDevice = adafruit_dht.DHT22(gpiopin) | ||
|
||
try: | ||
# Print the values to the serial port | ||
temperature, humidity = dhtDevice.temperature, dhtDevice.humidity | ||
print("Temperature: {:.1f} °C Humidity: {:.1f} %".format(temperature, humidity)) | ||
|
||
except RuntimeError as error: | ||
# Errors happen fairly often, DHT's are hard to read, just keep going | ||
time.sleep(2.0) | ||
# Print the values to the serial port | ||
temperature, humidity = dhtDevice.temperature, dhtDevice.humidity | ||
print("Temperature: {:.1f} °C Humidity: {:.1f} %".format(temperature, humidity)) |