Device driver for Si7020 Digital humidity and temperature sensor.

Dependents:   Si7020_example MAXWSNENV_sensors MAXWSNENV_sensors Hello-Uzuki-sensor-shield ... more

Embed: (wiki syntax)

« Back to documentation index

Si7020 Class Reference

Si7020 Class Reference

Silicon Labs Si7020 Humidity and Temperature Sensor. More...

#include <Si7020.h>

Public Types

enum  resolution_t { RH_12b_TEMP_14b = 0x0, RH_8b_TEMP_12b = 0x1, RH_10b_TEMP_13b = 0x2, RH_11b_TEMP_11b = 0x3 }
 

Measurement resolution.

More...

Public Member Functions

 Si7020 (PinName sda, PinName scl)
 Si7020 constructor.
 Si7020 (I2C *i2c)
 Si7020 constructor.
 ~Si7020 ()
 Si7020 destructor.
int reset (void)
 Reset.
int getElectronicId (char *id)
 Get Electronic ID.
int configResolution (Si7020::resolution_t resolution)
 Configure sample resolution.
int getTemperature (int16_t *tempCx10)
 Get temperature reading.
int getTemperature (float *tempC)
 Get temperature reading.
int startTemperature (void)
 Start temperature reading.
int checkTemperature (int16_t *tempCx10)
 Check temperature reading.
int checkTemperature (float *tempC)
 Check temperature reading.
int getHumidity (int16_t *humidx10)
 Get humidity reading.
int getHumidity (float *humid)
 Get humidity reading.
int startHumidity (void)
 Start humidity reading.
int checkHumidity (int16_t *humidx10)
 Check humidity reading.
int checkHumidity (float *humid)
 Check humidity reading.
int getPrevTemperature (float *tempC)
 Get temperature from humidity reading.
int getPrevTemperature (int16_t *tempCx10)
 Get temperature from humidity reading.
int getRev (char *rev)
 Get firmware revision.
int heater (bool enable)
 Control heater.

Detailed Description

Silicon Labs Si7020 Humidity and Temperature Sensor.

 #include <stdio.h>
 #include "mbed.h"
 #include "Si7020.h"
 
 I2C i2c(I2C_SDA, I2C_SCL);
 Si7020 si(&i2c);
 
 int main()
 {
     while(1) {
 
         float humid;
         if(si.getHumidity(&humid) != 0) {
             printf("Error getting humidity\n");
             humid = -1;
         }
 
         float temp;
         if(si.getTemperature(&temp) != 0) {
             printf("Error getting temperature");
             temp = -1;
         } 
         printf("Humidity = %f%% Temperature = %fC\n", humid, temp);
 
         wait(1);
     }
 }

Definition at line 72 of file Si7020.h.


Member Enumeration Documentation

Measurement resolution.

Controls the resolution of the humidity and temperarure readings.

Enumerator:
RH_12b_TEMP_14b 

12 bits for RH, 14 bits for Temp

RH_8b_TEMP_12b 

8 bits for RH, 12 bits for Temp

RH_10b_TEMP_13b 

10 bits for RH, 13 bits for Temp

RH_11b_TEMP_11b 

11 bits for RH, 11 bits for Temp

Definition at line 81 of file Si7020.h.


Constructor & Destructor Documentation

Si7020 ( PinName  sda,
PinName  scl 
)

Si7020 constructor.

Parameters:
sdambed pin to use for SDA line of I2C interface.
sclmbed pin to use for SCL line of I2C interface.

Definition at line 54 of file Si7020.cpp.

Si7020 ( I2C *  i2c )

Si7020 constructor.

Parameters:
i2cI2C object to use

Definition at line 64 of file Si7020.cpp.

~Si7020 (  )

Si7020 destructor.

Definition at line 71 of file Si7020.cpp.


Member Function Documentation

int checkHumidity ( int16_t *  humidx10 )

Check humidity reading.

Checks to see if the humidity reading has been completed. Returns humidity if reading complete.

Note:
Must call startHumidity() prior to calling this function.
Parameters:
humidCx10Pointer for humidity reading. Unit is 1/10th percent.
Returns:
0 if reading taken, -1 if reading pending.

Definition at line 291 of file Si7020.cpp.

int checkHumidity ( float *  humid )

Check humidity reading.

Checks to see if the humidity reading has been completed. Returns humidity if reading complete.

Note:
Must call startHumidity() prior to calling this function.
Parameters:
humidPointer for humidity reading. Unit is percent.
Returns:
0 if reading taken, -1 if reading pending.

Definition at line 318 of file Si7020.cpp.

int checkTemperature ( float *  tempC )

Check temperature reading.

Checks to see if the temperature reading has been completed. Returns temperature if reading complete.

Note:
Must call startTemperature() prior to calling this function.
Parameters:
tempCPointer for temperature reading. Unit is degree Celcius.
Returns:
0 if reading taken, -1 if reading pending.

Definition at line 241 of file Si7020.cpp.

int checkTemperature ( int16_t *  tempCx10 )

Check temperature reading.

Checks to see if the temperature reading has been completed. Returns temperature if reading complete.

Note:
Must call startTemperature() prior to calling this function.
Parameters:
tempCx10Pointer for temperature reading. Unit is 1/10th degree Celcius.
Returns:
0 if reading taken, -1 if reading pending.

Definition at line 217 of file Si7020.cpp.

int configResolution ( Si7020::resolution_t  resolution )

Configure sample resolution.

Sets the number of bits used for humidity and temperature readings.

Parameters:
resolutionEnum for the resolution setting.
Returns:
0 if no errors, -1 if error.

Definition at line 148 of file Si7020.cpp.

int getElectronicId ( char *  id )

Get Electronic ID.

Gets the Electronic ID of the connected device. Verifies the ID with an 8-bit CRC.

Parameters:
Characterbuffer to store the id. Needs to be at least 8 bytes.
Returns:
0 if no errors, -1 if error.

Definition at line 89 of file Si7020.cpp.

int getHumidity ( int16_t *  humidx10 )

Get humidity reading.

Initiates a humidity reading and blocks until reading has been calculated.

Note:
Will hold the I2C bus until reading is complete. Refer to datasheet for timing specifications.
Parameters:
humidx10Pointer for humidity reading. Unit is 1/10th percent.
Returns:
0 if no errors, -1 if error.

Definition at line 261 of file Si7020.cpp.

int getHumidity ( float *  humid )

Get humidity reading.

Initiates a humidity reading and blocks until reading has been calculated.

Note:
Will hold the I2C bus until reading is complete. Refer to datasheet for timing specifications.
Parameters:
humidPointer for humidity reading. Unit is percent.
Returns:
0 if no errors, -1 if error.

Definition at line 271 of file Si7020.cpp.

int getPrevTemperature ( int16_t *  tempCx10 )

Get temperature from humidity reading.

Gets temperature reading from previous humidity reading.

Note:
Must call startHumidity() prior to calling this function.
Parameters:
tempCx10Pointer for temperature reading. Unit is 1/10th degree Celcius.
Returns:
0 if reading taken, -1 if reading pending.

Definition at line 351 of file Si7020.cpp.

int getPrevTemperature ( float *  tempC )

Get temperature from humidity reading.

Gets temperature reading from previous humidity reading.

Note:
Must call startHumidity() prior to calling this function.
Parameters:
tempCPointer for temperature reading. Unit is degree Celcius.
Returns:
0 if reading taken, -1 if reading pending.

Definition at line 337 of file Si7020.cpp.

int getRev ( char *  rev )

Get firmware revision.

Reads the firmware revision, refer to datasheet for codes.

Parameters:
revPointer to store firmware revision.
Returns:
0 if no errors, -1 if error.

Definition at line 365 of file Si7020.cpp.

int getTemperature ( int16_t *  tempCx10 )

Get temperature reading.

Initiates a temperature reading and blocks until reading has been calculated.

Note:
Will hold the I2C bus until reading is complete. Refer to datasheet for timing specifications.
Parameters:
tempCx10Pointer for temperature reading. Unit is 1/10th degree Celcius.
Returns:
0 if no errors, -1 if error.

Definition at line 187 of file Si7020.cpp.

int getTemperature ( float *  tempC )

Get temperature reading.

Initiates a temperature reading and blocks until reading has been calculated.

Note:
Will hold the I2C bus until reading is complete. Refer to datasheet for timing specifications.
Parameters:
tempCPointer for temperature reading. Unit is degree Celcius.
Returns:
0 if no errors, -1 if error.

Definition at line 197 of file Si7020.cpp.

int heater ( bool  enable )

Control heater.

Enable or disable the heater.

Parameters:
enableTrue to enable heater, false to disable.
Returns:
0 if no errors, -1 if error.

Definition at line 379 of file Si7020.cpp.

int reset ( void   )

Reset.

Sends the rest command.

Returns:
0 if no errors, -1 if error.

Definition at line 79 of file Si7020.cpp.

int startHumidity ( void   )

Start humidity reading.

Initiates a humidity reading. Will not hold the bus or block.

Returns:
0 if no errors, -1 if error.

Definition at line 281 of file Si7020.cpp.

int startTemperature ( void   )

Start temperature reading.

Initiates a temperature reading. Will not hold the bus or block.

Returns:
0 if no errors, -1 if error.

Definition at line 207 of file Si7020.cpp.