Kyle Chuang | ME405 Mechatronics Portfolio
mcp9808.MCP9808 Class Reference

A driver object for the mcp9808 temperature sensor. More...

Public Member Functions

def __init__ (self, i2c, addr=0, Tup=0, Tlow=0, Tcrit=0, res=0x03, config=0x0000, debug=False)
 Creates a mcp9808 object. More...
 
def conv_temp (self, Temp, from_unit, to_unit)
 Converts a temperature to new units. More...
 
def temp_to_bytes (self, Temp)
 Converts a temperature in celcius to a bytearry for the MCP9808 sensor. More...
 
def get_temp (self, unit='C')
 Returns the curent ambient temperature measured by the sensor. More...
 
def upper_lim (self, Temp='GET', unit='C')
 Sets or gets the curent upper temperature alert limit of the sensor.
 
def lower_lim (self, Temp='GET', unit='C')
 Sets or gets the curent lower temperature alert limit of the sensor. More...
 
def crit_temp (self, Temp='GET', unit='C')
 Sets or gets the curent critical temperature alert of the sensor.
 
def res (self, res='GET')
 Gets or sets the device measurement resolution. More...
 
def get_mfgID (self)
 Obtains the Manufacturer ID from the MCP9808 sensor. More...
 
def get_devID (self)
 Obtains the Device ID and revision information from the MCP9808 sensor. More...
 
def config (self, act='GET', HYST=0x00, SHDN=False, CRIT_LOK=False, WIN_LOK=False, INT_CLR=False, ALERT_STAT=False, ALERT_CNT=False, ALERT_SEL=False, ALERT_POL=False, ALERT_MOD=False)
 Allows reading and writing of the MCP9808 sensor config register. More...
 
def alert (self)
 Returns the device alert state.
 
def celcius (self)
 Returns the measured temperature in degrees Celcius. More...
 
def fahrenheit (self)
 Returns the measured temperature in degrees Fahrenheit. More...
 
def check (self)
 Checks to see if the device registers the correct Manufacturer ID (0x0054) More...
 

Public Attributes

 addr
 The I2C adress of the sensor. More...
 
 read_buf
 A byte array used to recieve data from the sensor.
 
 Tupper
 The upper temperature limit for alert in Celcius.
 
 Tlower
 The lower temperature limit for alert in Celcius.
 
 Tcritical
 The critical temperature for alert in Celcius.
 
 Tambinet
 The ambient temperature in Celcius.
 
 res
 The sensor resolution. More...
 
 config
 The sensor configuration data. More...
 
 mfg_id
 The manufacturer ID for the MCP9808 sensor.
 
 dev_id
 The device ID for the MCP9808 sensor.
 
 dev_rev
 The revision information for the MCP9808 sensor.
 
 alert
 Boolean indicating if the sensor is in alert.
 
 i2c
 The I2C object bound to the bus over which the sensor will communicate.
 
 debug
 A boolean that toggles the trace output to the command line.
 

Static Public Attributes

int R1_CONFIG = 1
 Configuration register.
 
int R2_UPPER_TEMP = 2
 Alert Temperature Upper Boundary Trip register.
 
int R3_LOWER_TEMP = 3
 Alert Temperature Upper Boundary Trip register.
 
int R4_CRIT_TEMP = 4
 Critical Temperature Trip register.
 
int R5_TEMPERATURE = 5
 Temperature register.
 
int R6_MFG_ID = 6
 Manufacturer ID register.
 
int R7_DEV_ID_AND_REV = 7
 Device ID/Revision register.
 
int R8_RESOLUTION = 8
 Resolution register.
 

Detailed Description

A driver object for the mcp9808 temperature sensor.

Constructor & Destructor Documentation

◆ __init__()

def mcp9808.MCP9808.__init__ (   self,
  i2c,
  addr = 0,
  Tup = 0,
  Tlow = 0,
  Tcrit = 0,
  res = 0x03,
  config = 0x0000,
  debug = False 
)

Creates a mcp9808 object.

This function creates a mcp 9808 object. Unless specified, all parameters are set to power on defaults.

Parameters
i2cThe I2C object bound to the bus over which the sensor will communicate.
addrInterger specifying the user selectable portion of the sensor address (0-7)
TupThe upper temperature limit for alert in Celcius
TlowThe lower temperature limit for alert in Celcius
TcritThe critical temperature for alert in Celcius
resThe sensor resolution: an int from 0-3 selects from the following [+0.5, +0.25, +0.125, +0.0625]
configThe sensor configuration: config can be set quickly here, or in detail using the config method
debugA boolean that toggles the trace output on or off.

Member Function Documentation

◆ celcius()

def mcp9808.MCP9808.celcius (   self)

Returns the measured temperature in degrees Celcius.

Returns
The the measured temperature in degrees Celcius

◆ check()

def mcp9808.MCP9808.check (   self)

Checks to see if the device registers the correct Manufacturer ID (0x0054)

Returns
The status of the check True for a pass, Flase for a fail

◆ config()

def mcp9808.MCP9808.config (   self,
  act = 'GET',
  HYST = 0x00,
  SHDN = False,
  CRIT_LOK = False,
  WIN_LOK = False,
  INT_CLR = False,
  ALERT_STAT = False,
  ALERT_CNT = False,
  ALERT_SEL = False,
  ALERT_POL = False,
  ALERT_MOD = False 
)

Allows reading and writing of the MCP9808 sensor config register.

Method not complete...

◆ conv_temp()

def mcp9808.MCP9808.conv_temp (   self,
  Temp,
  from_unit,
  to_unit 
)

Converts a temperature to new units.

   @details This function accepts a numerical temperature and two strings
            specifying the old and new units. The function works for any
            combination of the following units:

Celcius 'C' Fahrenheit 'F' Kelvin 'K' Rankine 'R'

@param Temp         The temperature value to be converted.
@param from_units   A string specifying the original units.
@param to_units     A string specifying the new units.
@return The converted temperature.

◆ fahrenheit()

def mcp9808.MCP9808.fahrenheit (   self)

Returns the measured temperature in degrees Fahrenheit.

Returns
The the measured temperature in degrees Fahrenheit

◆ get_devID()

def mcp9808.MCP9808.get_devID (   self)

Obtains the Device ID and revision information from the MCP9808 sensor.

Returns
An tuple containing the Device ID and device revision information

◆ get_mfgID()

def mcp9808.MCP9808.get_mfgID (   self)

Obtains the Manufacturer ID from the MCP9808 sensor.

Returns
An interger representing the Manufacturer ID

◆ get_temp()

def mcp9808.MCP9808.get_temp (   self,
  unit = 'C' 
)

Returns the curent ambient temperature measured by the sensor.

This function returns the curent ambient temerature measurement of the MCO9808 sensor in Celcius, Fahrenheit, Kelvin, or Rankine.

Parameters
unitA single character str designating the desired units can be 'C' 'F' 'K' or 'R'
Returns
The ambient temperature in the desired units.

◆ lower_lim()

def mcp9808.MCP9808.lower_lim (   self,
  Temp = 'GET',
  unit = 'C' 
)

Sets or gets the curent lower temperature alert limit of the sensor.

TXT

◆ res()

def mcp9808.MCP9808.res (   self,
  res = 'GET' 
)

Gets or sets the device measurement resolution.

This method gets or sets the sampling resolution for the MCP9808 temperature sensor. There are four valid resolution settings as outlined by the following:

0 = +0.05 C
1 = +0.25 C
2 = +0.125 C
3 = +0.0625 C
Parameters
resThe resolution index to set, if no value is passed, the current resolution index is returned.
Returns
The current resolution.

◆ temp_to_bytes()

def mcp9808.MCP9808.temp_to_bytes (   self,
  Temp 
)

Converts a temperature in celcius to a bytearry for the MCP9808 sensor.

Parameters
TempThe celcius temperature to be converted into bytes
Returns
The bytearray representing the given celcius temperature

Member Data Documentation

◆ addr

mcp9808.MCP9808.addr

The I2C adress of the sensor.

The adress is created by combining the four bit manufacturer address with the three bit user selected address.

◆ config

mcp9808.MCP9808.config

The sensor configuration data.

See the MCP9808 datasheet for a detailed explanation of what this specifies.

◆ res

mcp9808.MCP9808.res

The sensor resolution.

The value of res indexes the following list of available resolutions [+0.5, +0.25, +0.125, +0.0625] (units in Celcius)


The documentation for this class was generated from the following file: