Skip to content

Commit f009082

Browse files
Alexander WachterMaureenHelm
authored andcommitted
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 <[email protected]>
1 parent f29ec12 commit f009082

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ens210.overlay")
6+
7+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
8+
project(ens210)
9+
10+
FILE(GLOB app_sources src/*.c)
11+
target_sources(app PRIVATE ${app_sources})

samples/sensor/ens210/README.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _ens210:
2+
3+
ams ens210 Relative Humidity and Temperature Sensor
4+
###################################################
5+
6+
Overview
7+
********
8+
9+
This sample application demonstrates how to use the ams ens210 sensor to
10+
measure the ambient temperature and relative humidity.
11+
12+
Building and Running
13+
********************
14+
15+
This sample application uses the sensor connected to the i2c stated in the
16+
ens210.overlay file.
17+
Flash the binary to a board of choice with a sensor connected.
18+
For example build for a nucleo_f446re board:
19+
20+
.. zephyr-app-commands::
21+
:zephyr-app: samples/sensors/ens210
22+
:board: nucleo_f446re
23+
:goals: build flash
24+
:compact:
25+
26+
Sample Output
27+
=============
28+
29+
.. code-block:: console
30+
31+
device is 0x20001174, name is ENS210
32+
Temperature: 28.28881222 C; Humidity: 25.25689737%
33+
Temperature: 28.28912472 C; Humidity: 25.25799105%
34+
Temperature: 28.28959347 C; Humidity: 25.25760045%
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2018 Alexander Wachter
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
&arduino_i2c {
7+
status = "ok";
8+
clock-frequency = <I2C_BITRATE_FAST>;
9+
10+
ens210: ens210@43 {
11+
compatible = "ams,ens210";
12+
reg = <0x43>;
13+
label = "ENS210";
14+
};
15+
};

samples/sensor/ens210/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_I2C=y
2+
CONFIG_SENSOR=y
3+
CONFIG_ENS210=y

samples/sensor/ens210/sample.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sample:
2+
description: Demonstration of the AMS Temperature and Humidity Sensor driver
3+
name: ENS210 sample
4+
tests:
5+
test:
6+
harness: sensor
7+
tags: samples
8+
depends_on: i2c arduino_i2c

samples/sensor/ens210/src/main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2018 Alexander Wachter
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <device.h>
9+
#include <sensor.h>
10+
#include <misc/printk.h>
11+
12+
void main(void)
13+
{
14+
struct device *dev;
15+
struct sensor_value temperature, humidity;
16+
17+
dev = device_get_binding(DT_AMS_ENS210_0_LABEL);
18+
if (!dev) {
19+
printk("Failed to get device binding");
20+
return;
21+
}
22+
23+
printk("device is %p, name is %s\n", dev, dev->config->name);
24+
25+
while (1) {
26+
sensor_sample_fetch(dev);
27+
sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
28+
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
29+
printk("Temperature: %d.%06d C; Humidity: %d.%06d%%\n",
30+
temperature.val1, temperature.val2,
31+
humidity.val1, humidity.val2);
32+
33+
k_sleep(1000);
34+
}
35+
}

0 commit comments

Comments
 (0)