Skip to content

Latest commit

 

History

History
111 lines (85 loc) · 4.71 KB

File metadata and controls

111 lines (85 loc) · 4.71 KB

  • I2C interface
  • excellent ±2% relative humidity and ±0.3°C accuracy
  • two address options
  • Pin「ADR」tie to pin「Vin」could change address from 0x44 to 0x45

Overview

  1. SHT31-D wired to Raspberry Pi with I2C
  2. Install Libraries
  3. Using SHT31-D with Adafruit library
  4. Single Page Reference

SHT31-D wired to Raspberry Pi with I2C

SHT31-D Raspberry Pi
VIN 3V3
GND GND
SCL SCL
SDA SDA

Raspberry Pi GPIO Pin

  • 3V3:1、17
  • GND:6、9、14、20、25、30、34、39
  • SCL:5
  • SDA:3

Check the I2C devices

  • SHT31-D0x44
pi@raspberrypi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Install Libraries

pip3 install adafruit-circuitpython-sht31d
pip3 install adafruit-circuitpython-busdevice
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 C" % sensor.temperature)
    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)

Docs

Single Page Reference