Raspberry Pi and LM75 temperature sensor example

The LM75 temperature sensor includes a delta-sigma analog-to-digital converter, and a digital overtemperature detector. The host can query the LM75 through its I²C interface to read temperature at any time. The open-drain overtemperature 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

 

Layout

I2C device you can power it from 3.3 or 5v – we chose 3.3v in this example

 

 

Code

This file is called lm75.py

import time
import smbus
LM75_ADDRESS = 0x48
LM75_TEMP_REGISTER = 0
LM75_CONF_REGISTER = 1
LM75_THYST_REGISTER = 2
LM75_TOS_REGISTER = 3
LM75_CONF_SHUTDOWN = 0
LM75_CONF_OS_COMP_INT = 1
LM75_CONF_OS_POL = 2
LM75_CONF_OS_F_QUE = 3
class LM75(object):
def __init__(self, mode=LM75_CONF_OS_COMP_INT, address=LM75_ADDRESS, busnum=1):
self._mode = mode
self._address = address
self._bus = smbus.SMBus(busnum)
def regdata2float (self, regdata):
return (regdata / 32.0) / 8.0
def toFah(self, temp):
return (temp * (9.0/5.0)) + 32.0
def getTemp(self):
raw = self._bus.read_word_data(self._address, LM75_TEMP_REGISTER) & 0xFFFF
raw = ((raw << 8) & 0xFF00) + (raw >> 8)
return self.toFah(self.regdata2float(raw))

This file is called lm75test.py

import lm75
sensor = lm75.LM75()
print sensor.getTemp()

 

Output

 

Links

LM75 temperature sensor high speed I2C interface high precision development board module

SHARE
Previous articleRaspberry Pi and BMP280 sensor example
Next articleRaspberry Pi and HDC1080 humidity and temperature sensor