Raspberry Pi and SHT31 sensor example

SHT31 is the next generation of Sensirion’s temperature and humidity sensors. It builds on a new CMOSens® sensor chip that is at the heart of Sensirion’s new humidity and temperature platform.

The SHT3x-DIS has increased intelligence, reliability and improved accuracy specifications compared to its predecessor. Its functionality includes enhanced signal processing, two distinctive and user selectable I2C addresses and communication speeds of up to 1 MHz. The DFN package has a footprint of 2.5 x 2.5 mm2 while keeping a height of 0.9 mm.

This allows for integration of the SHT3x-DIS into a great variety of applications.

Features

Fully calibrated, linearized, and temperature compensated digital output
Wide supply voltage range, from 2.4 V to 5.5 V
I2C Interface with communication speeds up to 1 MHz and two user selectable addresses

I bought the following module

If you’re using an Raspberry Pi simply connect the VIN pin to the 3v3 voltage pin, GND to ground, SCL1 (D5) to I2C Clock (Analog 5) and SDA1 (D3) to I2C Data (Analog 4).

Here is a layout drawn up in fritzing to illustrate this

Layout

Code

Save the following as sht31

[codesyntax lang=”python”]

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# SHT31 address, 0x44(68)
bus.write_i2c_block_data(0x44, 0x2C, [0x06])

time.sleep(0.5)

# SHT31 address, 0x44(68)
# Read data back from 0x00(00), 6 bytes
# Temp MSB, Temp LSB, Temp CRC, Humididty MSB, Humidity LSB, Humidity CRC
data = bus.read_i2c_block_data(0x44, 0x00, 6)

# Convert the data
temp = data[0] * 256 + data[1]
cTemp = -45 + (175 * temp / 65535.0)
fTemp = -49 + (315 * temp / 65535.0)
humidity = 100 * (data[3] * 256 + data[4]) / 65535.0

# Output data to screen
print "Temperature in Celsius is : %.2f C" %cTemp
print "Temperature in Fahrenheit is : %.2f F" %fTemp
print "Relative Humidity is : %.2f %%RH" %humidity

[/codesyntax]

 

testing

Run the python script – sudo python sht31.py

Link
1PCS/LOT SHT31 Temperature & SHT31-D Humidity Sensor module Breakout Weather for Arduino

Related posts

TLV493D magnetic sensor and Raspberry Pi 4 python example

SHT40 Digital Humidity Sensor and Raspberry Pi 4 python example

LTR390 UV Light Sensor a Raspberry Pi 4 in python

1 comment

Davis Vantage Pro 2 Open Weather Station – Part 3: Mistakes were made – Zach's Blog 11th January 2021 - 3:03 pm
[…] I was not sure what version the VP2 used, so I tried hooking it up via I2C and i found this page (http://www.pibits.net/code/raspberry-pi-sht31-sensor-example.php#codesyntax_1) that I thought would work. Well as i’m finding out, the Davis colors don’t always […]

Comments are closed.

Add Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More