Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion boards/arm/disco_l475_iot1/disco_l475_iot1_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions samples/sensor/hts221/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BOARD ?= disco_l475_iot1
CONF_FILE = prj.conf

include ${ZEPHYR_BASE}/Makefile.inc
47 changes: 47 additions & 0 deletions samples/sensor/hts221/README.rst
Original file line number Diff line number Diff line change
@@ -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%

<repeats endlessly every 2 seconds>
4 changes: 4 additions & 0 deletions samples/sensor/hts221/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_HTS221=y
1 change: 1 addition & 0 deletions samples/sensor/hts221/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += main.o
48 changes: 48 additions & 0 deletions samples/sensor/hts221/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2017 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <stdio.h>
#include <misc/util.h>

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);
}
}
4 changes: 4 additions & 0 deletions samples/sensor/hts221/testcase.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[test]
build_only = true
tags = samples sensor
platform_whitelist = disco_l475_iot1