loading

MCP9808 is a highly accurate digital temperature sensor ±0.5°C I2C mini module. They are embodied with user- programmable registers that facilitate temperature sensing applications. The MCP9808 high-accuracy temperature sensor has become an industry standard in terms of form factor and intelligence, providing calibrated, linearised sensor signals in digital, I2C format. Here is the demonstration with a python code using Raspberry Pi.

Step 1: What You Need..!!

1. Raspberry Pi

2. MCP9808

LINK : https://www.controleverything.com/content/Temperature?sku=MCP9808_I2CS#tabs-0-product_tabset-2

3. I²C Cable

LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

4. I²C Shield for Raspberry Pi

LINK : https://www.controleverything.com/content/I2C-Master?sku=TOUTPI2

5. Ethernet Cable

Step 2: 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 MCP9808 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.

Step 3: Code

The python code for MCP9808 can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/MCP9...

The datasheet of MCP9808 can be found here:

http://ww1.microchip.com/downloads/en/DeviceDoc/25...

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.

# MCP9808

# This code is designed to work with the MCP9808_I2CS I2C Mini Module available from ControlEverything.com.

# https://www.controleverything.com/content/Tempera...
import smbus

import time

# Get I2C bus

bus = 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

Step 4: Applications..:

MCP9808 Digital Temperature Sensor has several industry level applications which incorporate industrial freezers and refrigerators along with various food processors. This sensor can be employed for various personal computers, servers as well as other PC peripherals.

About This Instructable

489views

0favorites

More by Dcube Tech Ventures:Home Automation with Raspberry Pi using Relay board Motion Control with Raspberry Pi and LIS3DHTR, 3-Axis Accelerometer, using Python 3-Axis Accelerometer, ADXL345 with Raspberry Pi using Python 
Add instructable to: