samples: sensor: ens210: Implement sample for ens210

Sample code for AMS (Austria Micro Systems) ENS210 temperature and
relative humidity sensor.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit is contained in:
Alexander Wachter 2018-10-08 16:27:33 +02:00 committed by Maureen Helm
commit f0090825be
6 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ens210.overlay")
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(ens210)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -0,0 +1,34 @@
.. _ens210:
ams ens210 Relative Humidity and Temperature Sensor
###################################################
Overview
********
This sample application demonstrates how to use the ams ens210 sensor to
measure the ambient temperature and relative humidity.
Building and Running
********************
This sample application uses the sensor connected to the i2c stated in the
ens210.overlay file.
Flash the binary to a board of choice with a sensor connected.
For example build for a nucleo_f446re board:
.. zephyr-app-commands::
:zephyr-app: samples/sensors/ens210
:board: nucleo_f446re
:goals: build flash
:compact:
Sample Output
=============
.. code-block:: console
device is 0x20001174, name is ENS210
Temperature: 28.28881222 C; Humidity: 25.25689737%
Temperature: 28.28912472 C; Humidity: 25.25799105%
Temperature: 28.28959347 C; Humidity: 25.25760045%

View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2018 Alexander Wachter
* SPDX-License-Identifier: Apache-2.0
*/
&arduino_i2c {
status = "ok";
clock-frequency = <I2C_BITRATE_FAST>;
ens210: ens210@43 {
compatible = "ams,ens210";
reg = <0x43>;
label = "ENS210";
};
};

View file

@ -0,0 +1,3 @@
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_ENS210=y

View file

@ -0,0 +1,8 @@
sample:
description: Demonstration of the AMS Temperature and Humidity Sensor driver
name: ENS210 sample
tests:
test:
harness: sensor
tags: samples
depends_on: i2c arduino_i2c

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018 Alexander Wachter
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <misc/printk.h>
void main(void)
{
struct device *dev;
struct sensor_value temperature, humidity;
dev = device_get_binding(DT_AMS_ENS210_0_LABEL);
if (!dev) {
printk("Failed to get device binding");
return;
}
printk("device is %p, name is %s\n", dev, dev->config->name);
while (1) {
sensor_sample_fetch(dev);
sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
printk("Temperature: %d.%06d C; Humidity: %d.%06d%%\n",
temperature.val1, temperature.val2,
humidity.val1, humidity.val2);
k_sleep(1000);
}
}