This is a library to read out sensor values from Silicon Labs' si70xx-range of relative humidity and temperature sensors.

Dependents:   MemLCD-Temperature-Humidity-Demo lab123

Information

All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.

Caution

This library targets mbed's asynchronous transfer APIs, so it can only be used in conjunction with platforms supporting these APIs.

The library is currently compatible with Si7013, Si7020 and Si7021 parts.

Usage

Include mbed low-power to use this driver

#include "mbed.h"
#include "SILABS_RHT.h"
 
I2C sensorI2C(PD6, PD7); //PD6=SDA, PD7=SCL
silabs::SILABS_RHT rhtSensor(&sensorI2C);
 
volatile bool busChecked = false;
 
void respondedCallback( void ) {
    busChecked = true;
}

int main() {
    rhtSensor.check_availability(si7021, respondedCallback);
    while(busChecked == false) sleep();
    
    busChecked = false;
    rhtSensor.measure(si7021, respondedCallback);
    while(busChecked == false) sleep();

    if(rhtSensor.get_active()) {
        printf("Temperature: %d.%03d degC\n", rhtSensor.get_Temperature()/1000, rhtSensor.get_Temperature()%1000);
    } else {
        printf("No sensor found\n");
    }

    while(1) sleep();
}

Datasheets

http://www.silabs.com/products/sensors/humidity-sensors/Pages/si7013-20-21.aspx

Revision:
1:f3c25dea392e
Parent:
0:9fd18754e0c0
Child:
2:83a8b7df827f
--- a/SILABS_RHT.h	Tue Mar 17 13:46:44 2015 -0500
+++ b/SILABS_RHT.h	Tue Apr 14 15:27:17 2015 -0400
@@ -1,6 +1,6 @@
 /***************************************************************************//**
  * @file SILABS_RHT.h
- * @brief Driver class for the Silicon Labs si70xx series I2C RHT sensors.
+ * @brief Driver class for the Silicon Labs si70xx series I2C RHT sensors
  *******************************************************************************
  * @section License
  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
@@ -53,7 +53,6 @@
 	RHT_FWREV			// In the process of reading the device's firmware revision
 } SILABS_RHT_state_t;
 
-/** Supported devices */
 typedef enum {
 	si7013,
 	si7020,
@@ -61,94 +60,48 @@
 } SILABS_RHT_device_t;
 
 namespace silabs {
-/**  A driver for the Silicon Labs si70xx series of I2C RHT sensors.
- *
- * Currently supports si7013, si7020 and si7021.
- *
- * @code
- * #include "mbed.h"
- * #include "SILABS_RHT.h"
- * 
- * I2C sensorI2C(PD6, PD7); //PD6=SDA, PD7=SCL
- * silabs::SILABS_RHT rhtSensor(&sensorI2C);
- *
- * volatile bool busChecked = false;
- *
- * void measureCallback( void ) {
- *     if(rhtSensor.get_active()) {
- *         printf("Temperature: %d.%03d degC\n", rhtSensor.get_Temperature()/1000, rhtSensor.get_Temperature()%1000);
- *     } else {
- *         printf("No sensor found\n");
- *     }
- * }
- *
- * void respondedCallback( void ) {
- *     busChecked = true;
- * }
- * 
- * int main() {
- *     rhtSensor.check_availability(si7021, respondedCallback);
- *     while(busChecked == false) sleep();
- *     
- *     rhtSensor.measure(si7021, measureCallback);
- *     while(1) sleep();
- * }
- * @endcode
- */
 class SILABS_RHT {
 
 public:
 
-    /**
-     * Constructor.
-     *
-     * @param i2c    pointer to active mbed I2C interface object.
-     */
 	SILABS_RHT(I2C * i2c);
 
-	/**
+	/*
 	 * Get last measured temperature data
-     *
-	 * @return       temperature in millidegrees centigrade
+	 * return: int32_t = temperature in millidegrees centigrade
 	 */
 	int32_t get_temperature();
 
-	/**
+	/*
 	 * Get last measured relative humidity data
-     *
-	 * @return       relative humidity value in milli-percent
+	 * return: uint32_t = relative humidity value in milli-percent
 	 */
 	uint32_t get_humidity();
 
-	/**
+	/*
 	 * Get current state of the sensor, active or inactive. Need to call check_availability first after initialization.
-     *
-	 * @return       true if the last operation (check_active or measure) was a success, false if not (device did not respond).
+	 * return: true if the last operation (check_active or measure) was a success, false if not (device did not respond).
 	 */
 	bool get_active();
 
-	/**
-	 * Perform and read back measurement.
-     *
-	 * @param deviceType   Device signature to check for.
-     * @param callback     Asynchronous callback can be provided (type void (*)(void)). If null, no callback will get called.
-	 * @return             0 if successful, else one of the defined error codes.
+	/*
+	 * Perform measurement.
+	 * Asynchronous callback can be provided (type void (*)(void)).
+	 * return: 0 if successful, else one of the defined error codes.
 	 */
 	int measure(SILABS_RHT_device_t deviceType, cbptr_t callback = NULL);
 
-	/**
+	/*
 	 * Check if the sensor is active and responding. This will update the get_active value.
-     *
-	 * @param deviceType   Device signature to check for.
-     * @param callback     Asynchronous callback can be provided (type void (*)(void)). If null, no callback will get called.
-	 * @return             0 if successful, else one of the defined error codes.
+	 * Asynchronous callback can be provided (type void (*)(void)).
+	 * return: 0 if successful, else one of the defined error codes.
 	 */
 	int check_availability(SILABS_RHT_device_t deviceType, cbptr_t callback = NULL);
 
 protected:
 	mbed::I2C *_i2c;
 
-	mbed::CallbackPointer _internalCallback;
+	event_callback_t _internalCallback;
 	SILABS_RHT_state_t _state;
 	cbptr_t  _completionCallbackPtr;
 
@@ -161,17 +114,17 @@
 
 
 
-	/*
+	/**
 	 * Callback handler for internal I2C transfers.
 	 */
 	void _cbHandler( int event );
 
-	/*
+	/**
 	 * Callback handler for internal I2C transfers triggered by timeout.
 	 */
 	void _cbHandlerTimeout( void );
 
-	/*
+	/**
 	 * Internal lookup table for I2C address by device type.
 	 */
 	uint8_t get_address(SILABS_RHT_device_t device);