Dcube Tech Ventures
Published

Temperature Monitoring Using MCP9808 and Raspberry Pi

MCP9808 is a highly accurate digital temperature sensor ±0.5°C I2C mini module.

IntermediateProtip4 hours3,939
Temperature Monitoring Using MCP9808 and Raspberry Pi

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
ControlEverything.com MCP9808 Digital Temperature Sensor
×1
ControlEverything.com I²C Cable
×1
ControlEverything.com Raspberry 2 & 3 Compatible Shield
×1

Story

Read more

Schematics

MCP9808

Code

Code snippet #1

Python
import smbus
import time
# Get I2C busbus = smbus.SMBus(1)
# MCP9808 address, 0x18(24)
# Select configuration register, 0x01(1)
#		0x0000(00)	Continuous conversion mode, Power-up default
config = [0x00, 0x00]bus.write_i2c_block_data(0x18, 0x01, config)
# MCP9808 address, 0x18(24)
# Select resolution rgister, 0x08(8)
#		0x03(03)	Resolution = +0.0625 / C
bus.write_byte_data(0x18, 0x08, 0x03)
time.sleep(0.5)
# MCP9808 address, 0x18(24)
# Read data back from 0x05(5), 2 bytes
# Temp MSB, TEMP LSB
data = bus.read_i2c_block_data(0x18, 0x05, 2)
# Convert the data to 13-bits
ctemp = ((data[0] & 0x1F) * 256) + data[1]
if ctemp > 4095 :	
ctemp -= 8192
ctemp = ctemp * 0.0625
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

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.