diff --git a/drivers/hts221/hts221.c b/drivers/hts221/hts221.c index 8d53bd5b06..37840af402 100644 --- a/drivers/hts221/hts221.c +++ b/drivers/hts221/hts221.c @@ -27,7 +27,7 @@ #include "periph/i2c.h" #include "xtimer.h" -#define ENABLE_DEBUG (1) +#define ENABLE_DEBUG (0) #include "debug.h" #define I2C_SPEED I2C_SPEED_FAST diff --git a/tests/driver_hts221/Makefile b/tests/driver_hts221/Makefile new file mode 100644 index 0000000000..e1e42380a4 --- /dev/null +++ b/tests/driver_hts221/Makefile @@ -0,0 +1,9 @@ +APPLICATION = driver_hts221 +include ../Makefile.tests_common + +FEATURES_REQUIRED = periph_i2c + +USEMODULE += hts221 +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_hts221/main.c b/tests/driver_hts221/main.c new file mode 100644 index 0000000000..eea93bb019 --- /dev/null +++ b/tests/driver_hts221/main.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief HTS221 humidity and temperature sensor driver test application + * + * @author Sebastian Meiling + * + * @} + */ + +#include + +#include "hts221.h" +#include "hts221_params.h" +#include "xtimer.h" + +#define SLEEP_S (2U) +static hts221_t dev; + +int main(void) +{ + printf("Init HTS221 on I2C_DEV(%i)\n", (int)hts221_params[0].i2c); + if (hts221_init(&dev, &hts221_params[0]) != HTS221_OK) { + puts("[FAILED]"); + return 1; + } + if (hts221_power_on(&dev) != HTS221_OK) { + puts("[FAILED] to set power on!"); + return 2; + } + if (hts221_set_rate(&dev, dev.p.rate) != HTS221_OK) { + puts("[FAILED] to set continuous mode!"); + return 3; + } + + while(1) { + uint16_t hum = 0; + int16_t temp = 0; + if (hts221_read_humidity(&dev, &hum) != HTS221_OK) { + puts(" -- failed to humidity!"); + } + if (hts221_read_temperature(&dev, &temp) != HTS221_OK) { + puts(" -- failed to temperature!"); + } + bool negative = (temp < 0); + if (negative) { + temp = -temp; + } + printf("H: %u.%u%%, T:%c%u.%u°C\n", (hum/10), (hum%10), + (negative ? '-' : ' '), (temp/10), (temp%10)); + xtimer_sleep(SLEEP_S); + } + return 0; +}