Raspberry Pi STS21 Temperature Sensor Python Tutorial
by Dcube Tech Ventures in Circuits > Electronics
29 Views, 0 Favorites, 0 Comments
Raspberry Pi STS21 Temperature Sensor Python Tutorial
STS21 Digital Temperature Sensor offers superior performance and a space saving footprint. It provides calibrated, linearized signals in digital, I2C format. Fabrication of this sensor is based on CMOSens technology, which attributes to the superior performance and reliability of STS21. The resolution of STS21 can be changed by command, low battery can be detected and a checksum helps to improve communication reliability. Here is its demonstration of interfacing it with Raspberry Pi using Python code.
What You Need..!!
Connections:
Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.
Then connect the one end of I2C cable to STS21 sensor and the other end to the I2C shield.
Also connect the Ethernet cable to the pi or you can use a WiFi module.
Connections are shown in the picture above.
Code:
The python code for STS21 can be downloaded from our GitHub repository- Dcube Store.
Here is the link for the same :
https://github.com/DcubeTechVentures/STS21...
We have used SMBus library for python code, the steps to install SMBus on raspberry pi is described here:
https://pypi.python.org/pypi/smbus-cffi/0.5.1
You can also copy the code from here, it is given as follows:
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# STS21
# This code is designed to work with the STS21_I2CS I2C Mini Module available in Dcube Store.
import smbus
import time
# Get I2C bus
bus = 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
Applications:
STS21 Digital Temperature Sensor can be employed in systems which require high accuracy temperature monitoring. It can be incorporated in various computer equipments, medical equipments and industrial control systems with the requisite of temperature measurement with proficient accuracy.