You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
514 B
Python
23 lines
514 B
Python
5 months ago
|
import time
|
||
|
from machine import Pin, I2C
|
||
|
|
||
|
import ahtx0
|
||
|
|
||
|
I2C_A = I2C(scl=Pin(1), sda=Pin(2))
|
||
|
|
||
|
# Create the sensor object using I2C
|
||
|
sensor = ahtx0.AHT10(I2C_A)
|
||
|
|
||
|
|
||
|
def celsius_to_fahrenheit(celsius: float):
|
||
|
return (celsius * (9 / 5)) + 32
|
||
|
|
||
|
|
||
|
while True:
|
||
|
temp_c = sensor.temperature
|
||
|
temf_f = celsius_to_fahrenheit(temp_c)
|
||
|
raw_humidity = sensor.relative_humidity
|
||
|
print("\nTemperature: {:.2f} C / {:.2f} F".format(temp_c, temf_f))
|
||
|
print("Humidity: {:.2f} %".format(raw_humidity))
|
||
|
time.sleep(5)
|