Raspberry Pi - SI7006-A20 Humidity & Temperature Sensor Python Tutorial
by Dcube Tech Ventures in Circuits > Electronics
12 Views, 0 Favorites, 0 Comments
Raspberry Pi - SI7006-A20 Humidity & Temperature Sensor Python Tutorial
SI7006-A20 is a humidity and temperature sensor which can operate on I2C communication protocol. It has a monolithic CMOS IC integrating humidity and temperature sensor elements, an analog-to-digital converter etc. Incorporated with highly advanced signal processing elements and callibration data feature this sensor forms one of the most efficient device to measure humidity and temperature. Here is its demonstration with raspberry pi using python code.
What You Need..!!
Connections:
Take a 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 SI7006-A20 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 SI7006-A20 can be downloaded from our github repository- DCUBE Store Community.
Here is the link for the same :
https://github.com/DcubeTechVentures/SI7006-A20/blob/master/python/Si7006_A20.py
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.
# SI7006-A20
# This code is designed to work with the SI7006-A20_I2CS I2C Mini Module
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# SI7006_A20 address, 0x40(64)
# 0xF5(245) Select Relative Humidity NO HOLD MASTER mode
bus.write_byte(0x40, 0xF5)
time.sleep(0.5)
# SI7006_A20 address, 0x40(64)
# Read data back, 2 bytes, Humidity MSB first
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
# Convert the data
humidity = (125.0 * (data0 * 256.0 + data1) / 65536.0) - 6.0
# SI7006_A20 address, 0x40(64) # 0xF3(243) Select temperature NO HOLD MASTER mode
bus.write_byte(0x40, 0xF3)
time.sleep(0.5)
# SI7006_A20 address, 0x40(64)
# Read data back, 2 bytes, Temperature MSB first
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
# Convert the data
cTemp = (175.72 * (data0 * 256.0 + data1) / 65536.0) - 46.85
fTemp = cTemp * 1.8 + 32
# Output data to screen
print "Relative Humidity is : %.2f %%RH" %humidity
print "Temperature in Celsius is : %.2f C" %cTemp
print "Temperature in Fahrenheit is : %.2f F" %fTemp
Applications:
SI7006-A20 is a highly efficient and reliable sensor that can be incorporated in indoor weather stations that can maintain the optimum indoor environment in terms of humidity and temperature suited for human body.It forms an integral part in automotive climate control and defogging systems. It can also be employed in mobile phones and tablets.