esp-open-rtos/examples/sht3x/sht3x.c

172 lines
5.3 KiB
C
Raw Normal View History

Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
/**
* Simple example with SHT3x sensor.
*
* It shows different user task implementations in *single shot mode* and
* *periodic mode*. In *single shot* mode either low level or high level
* functions are used.
*
* Constants SINGLE_SHOT_LOW_LEVEL and SINGLE_SHOT_HIGH_LEVEL controls which
* task implementation is used.
*
* Harware configuration:
*
* +-----------------+ +----------+
* | ESP8266 / ESP32 | | SHT3x |
* | | | |
* | GPIO 14 (SCL) ------> SCL |
* | GPIO 13 (SDA) <-----> SDA |
* +-----------------+ +----------+
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
*/
/* -- use following constants to define the example mode ----------- */
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
// #define SINGLE_SHOT_LOW_LEVEL
// #define SINGLE_SHOT_HIGH_LEVEL
/* -- includes ----------------------------------------------------- */
#include "sht3x.h"
/* -- platform dependent definitions ------------------------------- */
#ifdef ESP_PLATFORM // ESP32 (ESP-IDF)
// user task stack depth for ESP32
#define TASK_STACK_DEPTH 2048
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
#else // ESP8266 (esp-open-rtos)
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
// user task stack depth for ESP8266
#define TASK_STACK_DEPTH 256
#endif // ESP_PLATFORM
// I2C interface defintions for ESP32 and ESP8266
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
#define I2C_BUS 0
#define I2C_SCL_PIN 14
#define I2C_SDA_PIN 13
#define I2C_FREQ I2C_FREQ_100K
/* -- user tasks --------------------------------------------------- */
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
static sht3x_sensor_t* sensor; // sensor device data structure
#if defined(SINGLE_SHOT_HIGH_LEVEL)
/*
* User task that triggers a measurement every 5 seconds. Due to power
* efficiency reasons it uses *single shot* mode. In this example it uses the
* high level function *sht3x_measure* to perform one measurement in each cycle.
*/
void user_task (void *pvParameters)
{
float temperature;
float humidity;
TickType_t last_wakeup = xTaskGetTickCount();
while (1)
{
// perform one measurement and do something with the results
if (sht3x_measure (sensor, &temperature, &humidity))
printf("%.3f SHT3x Sensor: %.2f °C, %.2f %%\n",
(double)sdk_system_get_time()*1e-3, temperature, humidity);
// wait until 5 seconds are over
vTaskDelayUntil(&last_wakeup, 5000 / portTICK_PERIOD_MS);
}
}
#elif defined(SINGLE_SHOT_LOW_LEVEL)
/*
* User task that triggers a measurement every 5 seconds. Due to power
* efficiency reasons it uses *single shot* mode. In this example it starts the
* measurement, waits for the results and fetches the results using separate
* functions
*/
void user_task (void *pvParameters)
{
float temperature;
float humidity;
TickType_t last_wakeup = xTaskGetTickCount();
// get the measurement duration for high repeatability;
uint8_t duration = sht3x_get_measurement_duration(sht3x_high);
while (1)
{
// Trigger one measurement in single shot mode with high repeatability.
sht3x_start_measurement (sensor, sht3x_single_shot, sht3x_high);
// Wait until measurement is ready (constant time of at least 30 ms
// or the duration returned from *sht3x_get_measurement_duration*).
vTaskDelay (duration);
// retrieve the values and do something with them
if (sht3x_get_results (sensor, &temperature, &humidity))
printf("%.3f SHT3x Sensor: %.2f °C, %.2f %%\n",
(double)sdk_system_get_time()*1e-3, temperature, humidity);
// wait until 5 seconds are over
vTaskDelayUntil(&last_wakeup, 5000 / portTICK_PERIOD_MS);
}
}
#else // PERIODIC MODE
/*
* User task that fetches latest measurement results of sensor every 2
* seconds. It starts the SHT3x in periodic mode with 1 measurements per
* second (*sht3x_periodic_1mps*).
*/
void user_task (void *pvParameters)
{
float temperature;
float humidity;
// Start periodic measurements with 1 measurement per second.
sht3x_start_measurement (sensor, sht3x_periodic_1mps, sht3x_high);
// Wait until first measurement is ready (constant time of at least 30 ms
// or the duration returned from *sht3x_get_measurement_duration*).
vTaskDelay (sht3x_get_measurement_duration(sht3x_high));
TickType_t last_wakeup = xTaskGetTickCount();
while (1)
{
// Get the values and do something with them.
if (sht3x_get_results (sensor, &temperature, &humidity))
printf("%.3f SHT3x Sensor: %.2f °C, %.2f %%\n",
(double)sdk_system_get_time()*1e-3, temperature, humidity);
// Wait until 2 seconds (cycle time) are over.
vTaskDelayUntil(&last_wakeup, 2000 / portTICK_PERIOD_MS);
}
}
#endif
/* -- main program ------------------------------------------------- */
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
void user_init(void)
{
// Set UART Parameter.
uart_set_baud(0, 115200);
// Give the UART some time to settle
vTaskDelay(1);
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
// Init I2C bus interfaces at which SHT3x sensors are connected
// (different busses are possible).
i2c_init(I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ);
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
// Create the sensors, multiple sensors are possible.
if ((sensor = sht3x_init_sensor (I2C_BUS, SHT3x_ADDR_2)))
{
// Create a user task that uses the sensors.
xTaskCreate(user_task, "user_task", TASK_STACK_DEPTH, NULL, 2, 0);
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
}
2018-01-06 14:34:36 +00:00
else
printf("Could not initialize SHT3x sensor\n");
Driver for Sensirion SHT3x temperature and humidity sensor readded (#453) * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. * SHT3x driver changes Additional include to satisfy the Travis CI test build * SHT3x driver - small changes README.md has been shortened * SHT3x driver - small changes * SHT3x driver - small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - initialization reduced to availability check * SHT3x driver - some small changes - crc8 lookup table is now static to be held in flash memory - special handling for the timer overflow in sht3x_is_measuring removed - some whitespace removed - initialization reduced to availability check * SHT3x driver - some minor changes - lookup tables made const to be held in flash - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) * SHT3x driver - documentation changed * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor correction - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS * SHT3x driver - minor corrections * SHT3x driver - minor corrections * Driver for Sensirion SHT3x sensor added This is a driver for Sensirion SHT3x temperature and humidity sensors connected via I2C. This commit is a rebasing and contains some interface changes based on the review from @ourairquality. SHT3x driver changes - additional include to satisfy the Travis CI test build - README.md has been shortened - special handling for the timer overflow in sht3x_is_measuring removed - some whitespaces removed - crc8 computation changed to a non table lookup version - measurement duration is now given in ticks and can be used directly for vTaskDelay (documentation and examples changed accordingly) - number of ticks for measurement duration takes now into account portTICK_PERIOD_MS - clock stretching disabled on sensor to avoid blocking when data are not ready to read - calculation of maesurement duration adds now one and a half ticks to be sure that measurement duration is not too short - function sht3x_is_measuring is now private and only for internal use, user task has always to use function vTaskDelay to wait for measurement results - function sht3x_is_measuring was simplified and returns now just a boolean value - private function sht3x_reset added which is used to reset the sensor during initialization - active flag in sensor data structure not needed anymore - function sht3_get_raw_data simplified - function sht3x_start_measurement returns now only a boolean - function sht3x_start_measurement does not check anymore whether there is already a measurment running - new function sht3x_get_measurement_duration which returns the measurement duration in ticks for configured repeatability * SHT3x driver minor changes - type sht3x_values_t replaced by separate float values - additional repeatability parameter defined for function sht3x_start_measurement - parameter of function sht3x_get_measurement_duration changed from sht3x_sensort_t to sht3_repeat_t - sensor modes and repeatability levels extended by prefix sht3x_ * SHT3x driver minor changes - new high level function sht3x_measure added, it comprises all three steps to perform one measurement in only one function - example with two sensors removed * SHT3x driver small correction
2017-10-23 21:39:48 +00:00
// That's it.
}