Skip to content

Commit c098971

Browse files
sven-hmcarlescufi
authored andcommitted
sample: sensor: mpr: Add MPR sample application
The sample reads pressure data from an MPR sensor and prints it to the console. Signed-off-by: Sven Herrmann <[email protected]>
1 parent bded58c commit c098971

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

samples/sensor/mpr/CMakeLists.txt

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

samples/sensor/mpr/README.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. _mpr-sample:
2+
3+
MPR Pressure Sensor
4+
###################
5+
6+
Overview
7+
********
8+
9+
This sample application periodically (1Hz) measures atmospheric pressure in
10+
kilopascal. The result is written to the console.
11+
12+
References
13+
**********
14+
15+
- MPR: https://sensing.honeywell.com/micropressure-mpr-series
16+
17+
Wiring
18+
******
19+
20+
This sample uses an MPRLS0025PA00001A sensor controlled using the i2c
21+
interface. Connect **VIN**, **GND** and Interface: **SDA**, **SCL**.
22+
23+
Building and Running
24+
********************
25+
26+
This project outputs sensor data to the console. It requires a sensor from the
27+
MPR series.
28+
It does not work on QEMU.
29+
In the sample below the :ref:`arduino_due` board is used.
30+
31+
.. zephyr-app-commands::
32+
:zephyr-app: samples/sensor/mpr
33+
:board: arduino_due
34+
:goals: build flash
35+
36+
Sample Output
37+
*************
38+
39+
.. code-block:: console
40+
41+
pressure value: 101.976303 kPa
42+
pressure value: 101.986024 kPa
43+
pressure value: 101.989736 kPa
44+
pressure value: 101.987424 kPa
45+
pressure value: 101.992099 kPa
46+
pressure value: 101.989171 kPa
47+
pressure value: 101.984226 kPa
48+
49+
<repeats endlessly>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2020, Sven Herrmann
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&twi0 {
8+
mpr@18 {
9+
compatible = "honeywell,mpr";
10+
reg = <0x18>;
11+
label = "MPR";
12+
};
13+
};

samples/sensor/mpr/prj.conf

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

samples/sensor/mpr/sample.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sample:
2+
name: MPR Pressure Sensor
3+
tests:
4+
sample.sensor.mpr:
5+
harness: sensor
6+
tags: sensors
7+
depends_on: i2c
8+
platform_whitelist: arduino_due

samples/sensor/mpr/src/main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2020 Sven Herrmann
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <device.h>
9+
#include <drivers/sensor.h>
10+
#include <stdio.h>
11+
12+
void main(void)
13+
{
14+
const char *const devname = DT_INST_0_HONEYWELL_MPR_LABEL;
15+
struct device *dev = device_get_binding(devname);
16+
int rc;
17+
18+
if (dev == NULL) {
19+
printf("Device %s not found.\n", devname);
20+
return;
21+
}
22+
23+
while (1) {
24+
struct sensor_value pressure;
25+
26+
rc = sensor_sample_fetch(dev);
27+
if (rc != 0) {
28+
printf("sensor_sample_fetch error: %d\n", rc);
29+
break;
30+
}
31+
32+
rc = sensor_channel_get(dev, SENSOR_CHAN_PRESS, &pressure);
33+
if (rc != 0) {
34+
printf("sensor_channel_get error: %d\n", rc);
35+
break;
36+
}
37+
38+
printf("pressure: %u.%u kPa\n", pressure.val1, pressure.val2);
39+
40+
k_sleep(K_SECONDS(1));
41+
}
42+
}

0 commit comments

Comments
 (0)