samples: sensor: hts221
This commit provides sample application for sensor hts221. By default, it is enabled on board disco_l475_iot1 Change-Id: I535fac8a670fa89cc1cae15ea1abe9cfe4b6c56b Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
parent
2a6f9daae4
commit
7991784297
4
samples/sensor/hts221/Makefile
Normal file
4
samples/sensor/hts221/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
BOARD ?= disco_l475_iot1
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
||||
47
samples/sensor/hts221/README.rst
Normal file
47
samples/sensor/hts221/README.rst
Normal file
@ -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
samples/sensor/hts221/prj.conf
Normal file
4
samples/sensor/hts221/prj.conf
Normal file
@ -0,0 +1,4 @@
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_HTS221=y
|
||||
1
samples/sensor/hts221/src/Makefile
Normal file
1
samples/sensor/hts221/src/Makefile
Normal file
@ -0,0 +1 @@
|
||||
obj-y += main.o
|
||||
48
samples/sensor/hts221/src/main.c
Normal file
48
samples/sensor/hts221/src/main.c
Normal file
@ -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
samples/sensor/hts221/testcase.ini
Normal file
4
samples/sensor/hts221/testcase.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[test]
|
||||
build_only = true
|
||||
tags = samples sensor
|
||||
platform_whitelist = disco_l475_iot1
|
||||
Loading…
Reference in New Issue
Block a user