Difference between revisions of "MansOS Humidity"

From DiLab
Jump to: navigation, search
Line 18: Line 18:
void humidityOff(); // turn off humidity sensor
void humidityOff(); // turn off humidity sensor
uint16_t readHumidity(); // read humidity value
uint16_t readHumidity(); // read humidity value

// Optional - some humidity sensors (SHT11) also provide temperature reading
uint16_t readHTemperature(); // read temperature value from humidity sensor

</pre>
</pre>



Revision as of 15:01, 29 September 2011

mos/hil/humidity.h

To use humidity sensor, make the following changes to you application:

  • enable humidity sensor by adding the following line to config file:
USE_HUMIDITY = y
  • If using generic MSP430 platforms, which use the same humidity sensor as TelosB, additional definition in config file required:
USE_TELOSB_HUMIDITY = y
  • in your code, call humidityOn() to turn the sensor on
  • in your code, call readHumidity() to get 16-bit raw humidity value


All platform-independent humidity sensor functions are described in mos/hil/humidity.h . Implementation can be found under mos/hal/platforms/...

void humidityInit();      // init humidity sensor, do not turn it on - called by kernel automatically, not needed in application cod
void humidityOn();        // turn on humidity sensor
void humidityOff();       // turn off humidity sensor
uint16_t readHumidity();  // read humidity value

// Optional - some humidity sensors (SHT11) also provide temperature reading
uint16_t readHTemperature();  // read temperature value from humidity sensor

Example application:

//----------------------------------------------------
//      Read humidity sensor, print raw value to UART
//----------------------------------------------------

#include "stdmansos.h"
#include "dprint.h"
#include "humidity.h"


//-------------------------------------------
//      Entry point for the application
//-------------------------------------------
void appMain(void)
{
    PRINT_INIT(129);
    PRINTF("Humidity test app\n");

    humidityOn();

    while (1) {
        sleep(1);
        uint16_t hum_raw = readHumidity();
        uint16_t temp_raw = readHTemperature();
        PRINTF("hum = %i\t temp = %i\n", hum_raw, temp_raw);
    }
}