-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsht31.py
27 lines (23 loc) · 801 Bytes
/
sht31.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#sudo pip3 install adafruit-circuitpython-sht31d
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import adafruit_sht31d
# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C()
sensor = adafruit_sht31d.SHT31D(i2c)
loopcount = 0
while True:
print("\nTemperature: %0.1f" % (sensor.temperature * 1.8 + 32))
print("Humidity: %0.1f%%" % sensor.relative_humidity)
loopcount += 1
time.sleep(2)
# every 10 passes turn on the heater for 1 second
if loopcount == 10:
loopcount = 0
sensor.heater = True
print("Sensor Heater status =", sensor.heater)
time.sleep(1)
sensor.heater = False
print("Sensor Heater status =", sensor.heater)