Raspberry Pi HDC1000 Temperature Sensor Python Tutorial

by Dcube Tech Ventures in Circuits > Electronics

9 Views, 0 Favorites, 0 Comments

Raspberry Pi HDC1000 Temperature Sensor Python Tutorial

Raspberry Pi HDC1000 Temperature Sensor Python Tutorial

The HDC1000 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The device measures humidity based on a novel capacitive sensor. The humidity and temperature sensors are factory calibrated. It is functional within the full -40°C to +125°C temperature range. Here is its demonstration with Raspberry Pi using python code.

What You Need..!!

HDC1000_I2CS_A_1.png
pi.jpg

Connection:

HDC1000_I2CS_A_1.png
pi.jpg
sensor.jpg
complete_connection.jpg

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 HDC1000 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:

complete_connection.jpg

The python code for HDC1000 can be downloaded from our GitHub repository- Dcube Store.

Here is the link for the same :

https://github.com/DcubeTechVentures/HDC1000...

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.

# HDC1000

# This code is designed to work with the HDC1000_I2CS I2C Mini Module available in Dcube Store.

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# HDC1000 address, 0x40(64)

# Select configuration register, 0x02(02)

# 0x30(48) Temperature, Humidity enabled, Resolultion = 14-bits, Heater on

bus.write_byte_data(0x40, 0x02, 0x30)

# HDC1000 address, 0x40(64)

# Send temp measurement command, 0x00(00)

bus.write_byte(0x40, 0x00)

time.sleep(0.5)

# HDC1000 address, 0x40(64)

# Read data back, 2 bytes

# temp MSB, temp LSB

data0 = bus.read_byte(0x40)

data1 = bus.read_byte(0x40)

# Convert the data

temp = (data0 * 256) + data1

cTemp = (temp / 65536.0) * 165.0 - 40

fTemp = cTemp * 1.8 + 32

# HDC1000 address, 0x40(64)

# Send humidity measurement command, 0x01(01)

bus.write_byte(0x40, 0x01)

time.sleep(0.5)

# HDC1000 address, 0x40(64)

# Read data back, 2 bytes

# humidity MSB, humidity LSB

data0 = bus.read_byte(0x40)

data1 = bus.read_byte(0x40)

# Convert the data

humidity = (data0 * 256) + data1

humidity = (humidity / 65536.0) * 100.0

# Output data to screen

print "Relative Humidity : %.2f %%" %humidity

print "Temperature in Celsius : %.2f C" %cTemp

print "Temperature in Fahrenheit : %.2f F" %fTemp

Applications:

HDC1000 can be employed in heating, ventilation and air conditioning (HVAC), Smart Thermostats and Room Monitors. This sensor also finds its application in Printers, Handheld Meters,Medical Devices,Cargo Shipping as well as Automotive Windshield Defog.