Driver to read and control a serial (i2c) temperature sensor, The Microchip MCP9808 is the digital sensor to control, can be read it, set its resolution, shutdown and also set alarms.

Dependents:   Hotboards_temp_alarms Hotboards_temp_fahrenheit Hotboards_temp_reading_temperature LCD_Temperatura

Embed: (wiki syntax)

« Back to documentation index

Hotboards_temp Class Reference

Hotboards_temp Class Reference

Hotboards_temp class. More...

#include <Hotboards_temp.h>

Public Member Functions

 Hotboards_temp (I2C &i2c, uint8_t address, uint8_t resolution=_0p5C)
 Create Hotboards_temp instance.
bool init (void)
 Detect if the sensor is conected and also set default resolution.
float read (void)
 Get temperature from sensor in Celsius degrees.
void setAlarms (float lower, float upper)
 Set Tlower and Tupper values and also active ALERT output pin.
void disableAlarms (void)
 Disable alarma activation, the function does not clear the previus alarm values, just disable the ALERT signal.
void shutdown (bool state)
 Turn Off/On sensor (low power), after turn it on again, is necesary wait from 30ms to 250ms (depends on resoluion) to read a valid temperature.
void setResolution (uint8_t resolution)
 set a new resolution, possible values are 0.0625, 0.125, 0.25 and 0.5
float CelsiusToFarenheit (float celsius)
 Function to convert Celsius to Farenheit degrees.
float FarenheitToCelsius (float farenheit)
 Function to convert Farenheit to Celsius degrees.

Detailed Description

Hotboards_temp class.

Used to read and config Microchip MCP9808 i2c temp sensor

Example:

 #include "Hotboards_temp.h"

 Hotboards_temp sensor( Sensor_7 );

 int main( void )
 {
   Wire.begin( );
   sensor.begin( );
   while(1){
     float val = sensor.read( );
     printf( "temp. %f", val );
     wait(1);
   }
 }

Definition at line 58 of file Hotboards_temp.h.


Constructor & Destructor Documentation

Hotboards_temp ( I2C &  i2c,
uint8_t  address,
uint8_t  resolution = _0p5C 
)

Create Hotboards_temp instance.

Parameters:
i2ciic peripheral to use with the temp sensor
addresssensor address (A0,A1 and A2 values)
resolutiondefault temperature resoluion (use values from _eResolution enumeration)

Example:

   // instance temp sensor with address 7 and 0.5 resolution (default)
   Hotboards_temp sensor( Sensor_7 );

Definition at line 21 of file Hotboards_temp.cpp.


Member Function Documentation

float CelsiusToFarenheit ( float  celsius )

Function to convert Celsius to Farenheit degrees.

Parameters:
celsiustemperature in celsius degrees

Example:

   // read temperature in celsius degrees
   float tempC = sensor.read( );
   // convert to farenheit
   float tempF = sensor.CelsiusToFarenheit( tempC );

Definition at line 102 of file Hotboards_temp.cpp.

void disableAlarms ( void   )

Disable alarma activation, the function does not clear the previus alarm values, just disable the ALERT signal.

Example:

   // set lower nd upper alarm (on setup function)
   sensor.setAlarm( 0.0, 10.0 );
   // disable alarm, ALERt signal is disable
   sensor.disableAlarms( );

Definition at line 75 of file Hotboards_temp.cpp.

float FarenheitToCelsius ( float  farenheit )

Function to convert Farenheit to Celsius degrees.

Parameters:
farenheittemperature in farenheit degrees

Example:

   // convert to celsius a previus farenheit temperature
   float tempC = sensor.FarenheitToCelsius( 98.5 );

Definition at line 107 of file Hotboards_temp.cpp.

bool init ( void   )

Detect if the sensor is conected and also set default resolution.

Returns:
'1' if a sensor is connected

Example:

   // init sensor and also check if is conected
   if( sensor.begin( ) == 1 ){
     // sensor is detected, do something
   }

Definition at line 28 of file Hotboards_temp.cpp.

float read ( void   )

Get temperature from sensor in Celsius degrees.

Returns:
The current temperature

Example:

   // init temp sensor (assume sensor is connected)
   sensor.begin( );
   // read the current temperaure
   float temp = sensor.read( );

Definition at line 44 of file Hotboards_temp.cpp.

void setAlarms ( float  lower,
float  upper 
)

Set Tlower and Tupper values and also active ALERT output pin.

Parameters:
lowerlower temperaure value to set ALERT pin
upperupper temperaure value to set ALERT pin

Example:

   // set lower nd upper alarm (on setup function)
   sensor.setAlarm( 0.0, 10.0 );
   // somewhere else on loop function
   // assume we conected pin 5 (arduino) to ALERT pin (sensor)
   if( readDigital(5) == 0 ){
     // temp value under lower valur or upper value
   }

Definition at line 63 of file Hotboards_temp.cpp.

void setResolution ( uint8_t  resolution )

set a new resolution, possible values are 0.0625, 0.125, 0.25 and 0.5

Parameters:
resolutionuse values from _eResolution enumeration (_0p5C, _0p25C, _0p125C and _0p0625C)

Example:

   // lets assume sensor is initialized
   sensor.setResolution( _0p0625C );
   // read temperature with the new resolution
   float temp = sensor.read( );

Definition at line 96 of file Hotboards_temp.cpp.

void shutdown ( bool  state )

Turn Off/On sensor (low power), after turn it on again, is necesary wait from 30ms to 250ms (depends on resoluion) to read a valid temperature.

Parameters:
stateshutdown (HT_SENSOR_OFF) or turn on (HT_SENSOR_ON)

Example:

   // lets assume sensor is initialized, so shutdown
   sensor.shutdown( HT_SENSOR_OFF );
   // the we can turn it on
   sensor.shutdown( HT_SENSOR_ON );

Definition at line 82 of file Hotboards_temp.cpp.