Beaglebone and LM75 temperature sensor example in python

0
128

The LM75 temperature sensor includes a delta-sigma analog-to-digital converter, and a digital over temperature detector. The host can query the LM75 through its I²C interface to read temperature at any time. The open-drain over temperature output (OS) sinks current when the programmable temperature limit is exceeded.

The OS output operates in either of two modes, comparator or interrupt. The host controls the temperature at which the alarm is asserted (TOS) and the hysteresis temperature below which the alarm condition is not valid (THYST). Also, the LM75’s TOS and THYST registers can be read by the host.

The address of the LM75 is set with three pins to allow multiple devices to work on the same bus. Power-up is in comparator mode, with defaults of TOS = +80°C and THYST = +75°C. The 3.0V to 5.5V supply voltage range, low supply current, and I²C interface make the LM75 ideal for many applications in thermal management and protection.

Key Features

SO (SOP) and µMAX® (µSOP) Packages
I²C Bus Interface
Separate Open-Drain OS Output Operates as Interrupt or Comparator/Thermostat Input
Register Readback Capability
Power-Up Defaults Permit Stand-Alone Operation as a Thermostat
3.0V to 5.5V Supply Voltage
Low Operating Supply Current 250µA (typ), 1mA (max)
4µA (typ) Shutdown Mode Minimizes Power Consumption
Up to Eight LM75s Can Be Connected to a Single Bus

Parts Required

NameLink
BeagleboneBeagleBone Black TI AM335x Cortex-A8 development BB-Black Rev.C
LM75LM75A temperature sensor high speed I2C interface high precision development board module
Connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Connection

BeagleboneModule
3.3v – P9.3Vcc
Gnd – P9.1Gnd
SDA – P9.20SDA
SCL – P9.19SCL

 

Code

This is based on a  controleverything code example, I changed the I2C address to 0x49.

import smbus
import time
 
# Get I2C bus
bus = smbus.SMBus(2)
 
# LM75BIMM address, 0x49(73)
# Select configuration register, 0x01(01)
#		0x00(00)	Continous conversion, Normal operation
bus.write_byte_data(0x48, 0x01, 0x00)
 
time.sleep(0.5)
 
# LM75BIMM address, 0x49(73)
# Read data back from 0x00(0), 2 bytes
# Temp MSB, Temp LSB
data = bus.read_i2c_block_data(0x48, 0x00, 2)
 
# Convert the data to 9-bits
cTemp = (data[0] * 256 + (data[1] & 0x80)) / 128
if cTemp > 255 :
	cTemp -= 512
cTemp = cTemp * 0.5
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

Output

You can see a few runs, moving the sensor below

debian@beaglebone:/var/lib/cloud9/$ python LM75.py
Temperature in Celsius is : 27.50 C
Temperature in Fahrenheit is : 81.50 F
debian@beaglebone:/var/lib/cloud9/$ python LM75.py
Temperature in Celsius is : 26.50 C
Temperature in Fahrenheit is : 79.70 F
debian@beaglebone:/var/lib/cloud9/$ python LM75.py
Temperature in Celsius is : 26.00 C
Temperature in Fahrenheit is : 78.80 F

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.