diff --git a/boards/arm/disco_l475_iot1/disco_l475_iot1_defconfig b/boards/arm/disco_l475_iot1/disco_l475_iot1_defconfig index 63e0d7409836d..2863475c4324b 100644 --- a/boards/arm/disco_l475_iot1/disco_l475_iot1_defconfig +++ b/boards/arm/disco_l475_iot1/disco_l475_iot1_defconfig @@ -55,4 +55,3 @@ CONFIG_I2C_STM32LX=y #configure HTS221 sensor CONFIG_HTS221_I2C_MASTER_DEV_NAME="I2C_2" CONFIG_HTS221_TRIGGER_NONE=y -CONFIG_HTS221_I2C_ADDR=0x5F diff --git a/samples/sensor/hts221/Makefile b/samples/sensor/hts221/Makefile new file mode 100644 index 0000000000000..63cb452ce0e06 --- /dev/null +++ b/samples/sensor/hts221/Makefile @@ -0,0 +1,4 @@ +BOARD ?= disco_l475_iot1 +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/samples/sensor/hts221/README.rst b/samples/sensor/hts221/README.rst new file mode 100644 index 0000000000000..bdd91fbc51dcd --- /dev/null +++ b/samples/sensor/hts221/README.rst @@ -0,0 +1,47 @@ +.. _hts221: + +HTS221: Temperature and Humidity Monitor +######################################## + +Overview +******** +This sample periodically reads temperature and humidity from the HTS221 +Temperature & Humidity Sensor and displays it on the console + + +Requirements +************ + +This sample uses the HTS221 sensor controlled using the I2C interface. + +References +********** + + - HTS211: http://www.st.com/en/mems-and-sensors/hts221.html + +Building and Running +******************** + + This project outputs sensor data to the console. It requires an HTS221 + sensor, which is present on the disco_l475_iot1 board. + + .. code-block:: console + + $ cd samples/sensors/hts221 + $ make BOARD=disco_l475_iot1 + +Sample Output +============= + + .. code-block:: console + + Temperature:25.3 C + Relative Humidity:40% + Temperature:25.3 C + Relative Humidity:40% + Temperature:25.3 C + Relative Humidity:40% + Temperature:25.3 C + Relative Humidity:40% + + diff --git a/samples/sensor/hts221/prj.conf b/samples/sensor/hts221/prj.conf new file mode 100644 index 0000000000000..6031b70dff747 --- /dev/null +++ b/samples/sensor/hts221/prj.conf @@ -0,0 +1,4 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_I2C=y +CONFIG_SENSOR=y +CONFIG_HTS221=y diff --git a/samples/sensor/hts221/src/Makefile b/samples/sensor/hts221/src/Makefile new file mode 100644 index 0000000000000..b666967fd5706 --- /dev/null +++ b/samples/sensor/hts221/src/Makefile @@ -0,0 +1 @@ +obj-y += main.o diff --git a/samples/sensor/hts221/src/main.c b/samples/sensor/hts221/src/main.c new file mode 100644 index 0000000000000..2a5f856ad9dee --- /dev/null +++ b/samples/sensor/hts221/src/main.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +void main(void) +{ + struct sensor_value temp, hum; + struct device *dev = device_get_binding("HTS221"); + + if (dev == NULL) { + printf("Could not get HTS221 device\n"); + return; + } + + while (1) { + if (sensor_sample_fetch(dev) < 0) { + printf("Sensor sample update error\n"); + return; + } + + if (sensor_channel_get(dev, SENSOR_CHAN_TEMP, &temp) < 0) { + printf("Cannot read HTS221 temperature channel\n"); + return; + } + + if (sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &hum) < 0) { + printf("Cannot read HTS221 humidity channel\n"); + return; + } + + /* display temperature */ + printf("Temperature:%.1f C\n", sensor_value_to_double(&temp)); + + /* display humidity (converted from millipercent) */ + printf("Relative Humidity:%.0f%%\n", + sensor_value_to_double(&hum) / 1000); + + k_sleep(2000); + } +} diff --git a/samples/sensor/hts221/testcase.ini b/samples/sensor/hts221/testcase.ini new file mode 100644 index 0000000000000..7260b929f7194 --- /dev/null +++ b/samples/sensor/hts221/testcase.ini @@ -0,0 +1,4 @@ +[test] +build_only = true +tags = samples sensor +platform_whitelist = disco_l475_iot1