UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

MCP9808 Class

Module: mcp9808

The MCP9808 digital temperature sensor converts temperatures between -20 deg C and +100 deg C to a digital word with +/- 0.5 deg C (max.) accuracy. The MCP9808 comes with user-programmable registers that provide flexibility for temperature sensing applications. The registers allow user-selectable settings such as Shutdown or low-power modes and the specification of temperature Event and Critical output boundaries. When the temperature changes beyond the specified boundary limits, the MCP9808 outputs an Event signal. The user has the option of setting the event output signal polarity as an active-low or active-high comparator output for thermostat operation, or as temperature event interrupt output for microprocessor-based systems. The event output can also be configured as a Critical temperature output.
Tested with Adafriut MCP9808 board.
mcp9808.jpg

Methods

MCP9808

(
  • bus
  • address
)
Number

MCP9808 constructor

Parameters:

  • bus Number

    i2c bus the sensor is attached to.

  • address Number

    Device address. Default is 0x18.

Returns:

Number:

name

() String

Returns the name of the sensor

Returns:

String:

getTemp

() Number

Returns current temperature.

Returns:

Number:

shutDown

(
  • sleep
)

Will cause the devices to either sleep or wakeup.

Parameters:

  • sleep Boolean

    Bool, default true to sleep. false to wake.

setMode

(
  • celsius
)

setMode - sets temperature reporting mode.

Parameters:

  • celsius Boolean

    Default is true. If false all temps will be reported in fahrenheit.

isCelsius

() Boolean

Returns true if mode is celsius False if fahrenheit.

Returns:

Boolean:

isTcrit

() Boolean

Returns true if TCrit threshold has been crossed Reflects the state of the bit based on the most recent readTemp() operation.

Returns:

Boolean:

isTupper

() Boolean

Returns true if TUpper threshold crossed Reflects the state of the bit based on the most recent readTemp() operation.

Returns:

Boolean:

isTlower

() Boolean

Returns true if TLower threshold crossed. Reflects the state of the bit based on the most recent readTemp() operation.

Returns:

Boolean:

setMonitorReg

(
  • reg
  • value
)

Sets the value of TCrit, TUpper,TLower registers.
reg - MCP9808_REG enum UPPER_TEMP, LOWER_TEMP or CRIT_TEMP.

Parameters:

  • reg MCP9808_REG

    undefined

  • value Number
    • float value representing the set value

getMonitorReg

(
  • reg
)
Number

Returns the current value of TCrit, TUpper, TLower registers.

Parameters:

  • reg MCP9808_REG
    • MCP9808_REG enum UPPER_TEMP, LOWER_TEMP or CRIT_TEMP.

Returns:

Number:

clearInterrupt

()

Clears the interrupt when ALERT_MODE is set to interrupt output and temp threshold crossed.

setAlertMode

(
  • command
)

Sets alert mode. Can use values from MCP9808_CONFIG enum. Values can be combined.

Parameters:

  • command Number
    • a combination of options to set desired alert mode. See spcec sheet.

clearAlertMode

()

Clears Alert Mode b sets all params to default.

setHysteresis

(
  • value
)

Sets hysteresis value.

Parameters:

  • value MCP9808_CONFIG

    MCP9808_CONFIG enum value HYST_0, HYST_1_5, HYST_3_0 or HYST_6_0

getHysteresis

() Number

Returns hysteresis setting as a float value.

Returns:

Number:

setResolution

(
  • value
)

Sets resolution of temperature conversion.

Parameters:

  • value MCP9808_RESOLUTION
    • MCP9808_RESOLUTION enum value. RES_LOW = +0.5 C RES_MEDIUM = +0.25 C RES_HIGH = +0.125 C RES_PRECISION = +0.0625 C (default).

getResolution

() Number

Returns float value representing the current resolution setting.

Returns:

Number:

getManufacturer

() Number

Returns Manufacturer ID. Typically 0x0054;

Returns:

Number:

getDevicedId

() Number

Returns device ID and revision. Typically 0x0400 With ID in the High byte.

Returns:

Number:

Properties

UPPER_TEMP

Enum MCP9808_REG

LOWER_TEMP

Enum MCP9808_REG

CRIT_TEMP

Enum MCP9808_REG

RES_LOW

Enum MCP9808_RESOLUTION

RES_MEDIUM

Enum MCP9808_RESOLUTION

RES_HIGH

Enum MCP9808_RESOLUTION

RES_PRECISION

Enum MCP9808_RESOLUTION

ALERTSTAT

Enum MCP9808_CONFIG

ALERTCTRL

Enum MCP9808_CONFIG

ALERTSEL

Enum MCP9808_CONFIG

ALERTPOL

Enum MCP9808_CONFIG

ALERTMODE

Enum MCP9808_CONFIG

HYST_0

Enum MCP9808_CONFIG

HYST_1_5

Enum MCP9808_CONFIG

HYST_3_0

Enum MCP9808_CONFIG

HYST_6_0

Enum MCP9808_CONFIG