Skip to content

Commit f989f2d

Browse files
Alexander WachterMaureenHelm
authored andcommitted
samples: sensor: ams_iAQcore: Implement sample for AMS iAQ-core
Sample code for AMS (Austria Micro Systems) Indoor Air Quality Sensor reading VOC and equivalent CO2 values. Signed-off-by: Alexander Wachter <[email protected]>
1 parent 3c70a38 commit f989f2d

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-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}/iaq_core.overlay")
6+
7+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
8+
project(iAQcore)
9+
10+
FILE(GLOB app_sources src/*.c)
11+
target_sources(app PRIVATE ${app_sources})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. _ams_iaqcore:
2+
3+
ams iAQcore Indoor air quality sensor
4+
#####################################
5+
6+
Overview
7+
********
8+
9+
This sample application demonstrates how to use the ams iAQcore sensor to
10+
measure CO2 equivalent and VOC. The CO2 value is a predicted value derived from
11+
VOC. The values are fetched and printed every second.
12+
13+
Building and Running
14+
********************
15+
16+
This sample application uses the sensor connected to the i2c stated in the
17+
iaq_core.overlay file.
18+
Flash the binary to a board of choice with a sensor connected.
19+
This sample can run on every board with i2c.
20+
For example build for a nucleo_f446re board:
21+
22+
.. zephyr-app-commands::
23+
:zephyr-app: samples/sensors/ams_iAQcore
24+
:board: nucleo_f446re
25+
:goals: build flash
26+
:compact:
27+
28+
Sample Output
29+
=============
30+
31+
.. code-block:: console
32+
33+
device is 0x20001a08, name is IAQ_CORE
34+
Co2: 882.000000ppm; VOC: 244.000000ppb
35+
Co2: 863.000000ppm; VOC: 239.000000ppb
36+
Co2: 836.000000ppm; VOC: 232.000000ppb
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_STANDARD>;
9+
10+
iaqcore: iaqcore@5a {
11+
compatible = "ams,iaqcore";
12+
reg = <0x5a>;
13+
label = "IAQ_CORE";
14+
};
15+
};
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_AMS_IAQ_CORE=y
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 iAQ-core Digital VOC Sensor driver
3+
name: iAQcore sample
4+
tests:
5+
test:
6+
harness: sensor
7+
tags: samples
8+
depends_on: i2c arduino_i2c
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 co2, voc;
16+
17+
dev = device_get_binding(DT_AMS_IAQCORE_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_CO2, &co2);
28+
sensor_channel_get(dev, SENSOR_CHAN_VOC, &voc);
29+
printk("Co2: %d.%06dppm; VOC: %d.%06dppb\n",
30+
co2.val1, co2.val2,
31+
voc.val1, voc.val2);
32+
33+
k_sleep(1000);
34+
}
35+
}

0 commit comments

Comments
 (0)