Dcube Tech Ventures
Published

Temperature Measurement Using STS21 and Raspberry Pi

STS21 Digital Temperature Sensor offers superior performance and a space saving footprint.

IntermediateProtip4 hours708
Temperature Measurement Using STS21 and Raspberry Pi

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
ControlEverything.com STS21
×1
I²C Cable
×1
ControlEverything.com I2C Shield for Raspberry Pi 3 & Pi 2
×1

Story

Read more

Schematics

STS21 Schematic

Code

Working Code

Python
import smbus
import time
# Get I2C busbus = smbus.SMBus(1)
# STS21 address, 0x4A(74)
# Select Command
#		0xF3(243)	Temperature measurement in NO HOLD mode
bus.write_byte(0x4A, 0xF3)
time.sleep(0.5)
# STS21 address, 0x4A(74)
# Read data back, 2 bytes, MSB first
data0 = bus.read_byte(0x4A)
data1 = bus.read_byte(0x4A)
# Convert the data
temp = (data0 * 256 + data1) & 0xFFFC
cTemp = -46.85 + (175.72 * temp / 65536.0)
fTemp = cTemp * 1.8 + 32
# Output data to screen
print "Temperature in Celsius is :  %.2f C" %cTemp
print "Temperature in Fahrenheit is :  %.2f F" %fTemp

Github file

Credits

Dcube Tech Ventures
34 projects • 16 followers
Dcube Tech Ventures Pvt Limited is collaboration of Hardware, Embedded and Software endeavour's to create the Internet of things. www.dcubestore.com
Contact

Comments

Please log in or sign up to comment.