Created
February 21, 2022 20:41
-
-
Save makvoid/a199751656515b7e81319fe18e0a361b to your computer and use it in GitHub Desktop.
AHT20 initial script
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
import adafruit_ahtx0 | |
import board | |
# Setup I2C Sensor | |
sensor = adafruit_ahtx0.AHTx0(board.I2C()) | |
# Convert Celsius to Fahrenheit | |
def c_to_f(input): | |
return (input * 9 / 5) + 32 | |
# Convert to two decimal places cleanly | |
# round() won't include trailing zeroes | |
def round_num(input): | |
return '{:.2f}'.format(input) | |
print('Temperature', round_num(c_to_f(sensor.temperature)), 'F') | |
print('Humidity', round_num(sensor.relative_humidity), '%') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment