Matthew's Portfolio
mcp9808.mcp9808 Class Reference

Public Member Functions

def __init__ (self, debugFlag=False)
 Constructor. More...
 
def run (self)
 Main run method. More...
 
def check (self)
 Method for checking whether the MCP9808 is configured correctly. More...
 
def celsius (self)
 Method for getting the current MCP9808 temperature in degrees Celsius. More...
 
def fahrenheit (self)
 Method for getting the current MCP9808 temperature in degrees Fahrenheit. More...
 
def clearFiles (self, filesList)
 Method for deleting files. More...
 
def transitionTo (self, newState)
 Method for transitioning states. More...
 

Public Attributes

 debugFlag
 Debugging flag for detailed analysis while running.
 
 i2c
 Definition of I2C master.
 
 addr
 Address of slave (temperature sensor)
 
 adc
 ADC for MCU temperature readings.
 
 sampleNum
 Counter for writing to a csv.
 
 state
 Contains the information for which state its in.
 
 currentTime
 Current time, absolute, in milliseconds.
 
 nextTime
 Time at which to take next data point.
 
 firstDataPoint
 Boolean variable used to establish refrence time value.
 
 runMain
 Variable for starting program operation. More...
 
 proceed
 Boolean, set in the check() method. More...
 
 sampleTime
 Data collection total time in minutes.
 
 sampleRate
 Data sampling rate in seconds (time between data points)
 
 numSamples
 Total number of samples based on user inputs.
 
 timeArray
 Time data array, of unsigned integers in milliseconds.
 
 mcpArray
 MCP temperature data array, of signed floats in celsisus.
 
 nucleoArray
 Nucleo MCU temperature data array, of signed floats in celsisus.
 
 zeroTime
 Time refrence point for calculated elapsed time.
 
 elapsedTime
 Elapsed time since first data point was collected.
 
 currentTempMCP
 Current MCP temperature in celsius.
 
 currentTempF
 Current MCP temperature in fahrenheit.
 
 currentTempNucleo
 Current Nucleo MCU temperature in celsius.
 

Static Public Attributes

int S0_INIT = 0
 Initial state. More...
 
int S1_COLLECT_DATA = 1
 Data collection state. More...
 
int S2_SAVE_DATA = 2
 CSV writing state. More...
 
int S3_DONE = 3
 Exit state.
 

Constructor & Destructor Documentation

◆ __init__()

def mcp9808.mcp9808.__init__ (   self,
  debugFlag = False 
)

Constructor.

Parameters
debugFlaguser may choose True or False to control extra print statements used during code developement

Member Function Documentation

◆ celsius()

def mcp9808.mcp9808.celsius (   self)

Method for getting the current MCP9808 temperature in degrees Celsius.

This method utilizes reading from register pointer 0x05, which returns ambient ambient temperature using 12 bits. The "upper byte" consists of a few checks such as critical temperature, as well as the sign bit. The "lower byte" consists of the remainder of the data related to the temperature value, and a simple equation using bit shifting allows for conversion from analog to digital temperature.

Returns
Ta Floating point number of ambient temperature (degrees celsius)

◆ check()

def mcp9808.mcp9808.check (   self)

Method for checking whether the MCP9808 is configured correctly.

To determine whether to continue with program operation, the system is checked each time to ensure that the manufacturer ID register contains the correct information. More specifically, reading from register pointer 0x05 of the I2C should give ‘b’\00T'` if a proper connection has been setup.

◆ clearFiles()

def mcp9808.mcp9808.clearFiles (   self,
  filesList 
)

Method for deleting files.

Since the csv writer is set to append to a certain file, the file to be written to must be removed each time the PC collects new data. If it was desired, this could be replaced by a method to rename the next file to write to a new file each time. For this, the os module is used.

Parameters
filesListis a list of strings containing the various files written each time the frontEnd is run

◆ fahrenheit()

def mcp9808.mcp9808.fahrenheit (   self)

Method for getting the current MCP9808 temperature in degrees Fahrenheit.

See celsius method for details, as this method converts the value returned by the celsisus method to fahrenheit

Returns
Ta Floating point number of ambient temperature (degrees fahrenheit)

◆ run()

def mcp9808.mcp9808.run (   self)

Main run method.

Method run from a main.py script, which implements a finite state machine. The path of this particular state machine is linear in nature, going from the initial state, to data collection, to saving data, and ending with program exit (with the potential to skip to program exit if certain conditions are met).

◆ transitionTo()

def mcp9808.mcp9808.transitionTo (   self,
  newState 
)

Method for transitioning states.

The method will reassign the self.state variable when directed to transition.

Parameters
newStateControls which state is the new state for the FSM.

Member Data Documentation

◆ proceed

mcp9808.mcp9808.proceed

Boolean, set in the check() method.

If the connection to the sensor is correct, self.proceed is set to True, and the program can continue

◆ runMain

mcp9808.mcp9808.runMain

Variable for starting program operation.

In saving files to the Nucleo internal storage, the board must be reset (through unplugging and plugging the board back in) to access new data written, such as the csv file generated. However, this means the main.py script also runs automatically. To avoid data being erased on plugging the board back in, this input allows the user to decide if the program should be run.

◆ S0_INIT

int mcp9808.mcp9808.S0_INIT = 0
static

Initial state.

Connection to the sensor is checked and arrays are initialized

◆ S1_COLLECT_DATA

int mcp9808.mcp9808.S1_COLLECT_DATA = 1
static

Data collection state.

Time, MCP, and Nucleo MCU data points are taken at regular time intervals

◆ S2_SAVE_DATA

int mcp9808.mcp9808.S2_SAVE_DATA = 2
static

CSV writing state.

Data collected in state 2 is written line by line to a csv file


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