LM92 Library for Arduino

LM92 is a 12-bit + sign temperature sensor from Texas Instruments. This sensor operates on the I2C interface and can achieve an accuracy as high as ± 0.33 °C within the typical temperature measurement range. I created a comprehensive Arduino library for this sensor (the library can be downloaded towards the end) and in this post I will explain each of the functions in detail.

Constructors

LM92(); //default constructor, A0=0, A1=0;
LM92(byte A1, byte A0); //instantiate using specific addresses

While LM92 uses Celsius as default measurement unit, the numbers returned by this library uses Fahrenheit by default as most of my readers are in the United States. To switch to Celsius, you simply set ResultInCelsius = true after the initialization of the library.

Public Functions

//returns the current temperature readings
//the unit used is dependent upon the setting of ResultInCelsius 
double readTemperature(); 

//returns the manufacturer ID
//returns 0x8001 (or 32769)
unsigned int getManufacturerID();

//read the content of the configuration register
//D7-D5: 0
//D4: Fault Queue
//D3: INT Polarity
//D2: T_CRIT_A Polarity
//D1: INT Mode
//D0: Shutdown
byte readConfigurationRegister();

//reads the temperature hysteresis setting
//On POR, the hysteresis is set to 2 degree C.
//the unit used is dependent upon the setting of ResultInCelsius 
double readHysteresis();

//reads high temperature setting of the comparator window
//the unit used is dependent upon the setting of ResultInCelsius 
double readTHigh();

//reads low temperature setting of the comparator window
//the unit used is dependent upon the setting of ResultInCelsius 
double readTLow();

//reads critical temperature setting of the sensor
//the unit used is dependent upon the setting of ResultInCelsius 
double readTCritical();
	void setHysteresis(double t);

//set the high temperature setting of the comparator window
//the unit used is dependent upon the setting of ResultInCelsius 
void setTHigh(double t);

//set the low temperature setting of the comparator window
//the unit used is dependent upon the setting of ResultInCelsius 
void setTLow(double t);

//set the critical temperature setting of the sensor
//the unit used is dependent upon the setting of ResultInCelsius 
void setTCritical(double t);

//put sensor in shutdown mode if true
//otherwise the sensor is brought out of the shutdown mode
void shutDown(bool shutdown);

//whether to enable fault queue to make results more reliable
//A fault queue of 4 faults is provided to prevent false tripping when the LM92 is
//used in noisy environments. The 4 faults must occur consecutively to set flags
//as well as INT and T_CRIT_A outputs.
//true: enable
//false: disable (default)
void enableFaultQueue(bool enable); 

//set interrupt mode
//0: Comparator interrupt mode (default)		    
//1: Event Interrupt mode
void setINTMode(byte b); 
				     
//set the output polarity when TCritical is triggered
//0: Active low (default)
//1: Active high
void setTCriticalPolarity(byte b); 

//set interrupt polarity	
//0: Active low (default)		
//1: Active high		   
void setINTPolarity(byte b); 				     

The Arduino code example below shows how to use the library in its simplest form:

#include <LM92.h>
#include <Wire.h>

LM92 lm92; //default constructor, address 0, 0   
    
void setup()
{
    Wire.begin();
    Serial.begin(9600);    
}

void loop()
{
    Serial.println(lm92.readTemperature());
    delay(500);
}

This library should be compatible with Arduino 1.0 and above.

Download

LM92.tar.gz

Be Sociable, Share!

Leave a Reply