Skip to content

Instantly share code, notes, and snippets.

@makvoid
Created February 21, 2022 20:41
Show Gist options
  • Save makvoid/a199751656515b7e81319fe18e0a361b to your computer and use it in GitHub Desktop.
Save makvoid/a199751656515b7e81319fe18e0a361b to your computer and use it in GitHub Desktop.
AHT20 initial script
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