MCP9808 Temperature Sensor

The MCP9808 [1] is an I2C digital temperature sensor with a typical accuracy of ±0.25°C over the sensor's -40°C to +125°C range, and a precision of 0.0625°C. It will work from 2.7 V to 5.5 V.

It's available on a breakout board from Adafruit [2]:


It has three address inputs, allowing eight I2C addresses, and the default I2C address is 24 or #x18, which you get by tying all the address lines low. To tie one or more address lines high connect them to Vcc via a 10kΩ resistor; for some reason that I don't understand, connecting them directly to Vcc seems to stop the chip working.

Reading the temperature

The following routine reads the temperature and returns it as an integer, in 1/16ths of a degree Celsius:

(defun mcp9808-temp ()
  (with-i2c (str 24) 
    (write-byte 5 str)
    (restart-i2c str 2)
    (let* ((hi (read-byte str))
           (lo (read-byte str))
           (tmp (logior (ash hi 8) lo)))
      (- (logand tmp #x0FFF) (logand tmp #x1000)))))

To return the temperature as an integer number of degrees, or a floating-point number on a 32-bit version of uLisp, do:

(/ (mcp9808-temp) 16)

For an application based on this sensor see Temperature sensor.

  1. ^ MCP9809 Datasheet on Microchip.
  2. ^ MCP9808 High Accuracy I2C Temperature Sensor Breakout Board on Adafruit.