samples: sensor: Added sample for MS5837 sensor
Added sample code for MS5837 pressure sensor Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
This commit is contained in:
parent
db9403def5
commit
d696a56cf4
7 changed files with 172 additions and 0 deletions
6
samples/sensor/ms5837/CMakeLists.txt
Normal file
6
samples/sensor/ms5837/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.8.2)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(NONE)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
52
samples/sensor/ms5837/README.rst
Normal file
52
samples/sensor/ms5837/README.rst
Normal file
|
@ -0,0 +1,52 @@
|
|||
.. _ms5837-sample:
|
||||
|
||||
MS5837 Sensor Sample
|
||||
####################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
This sample application retrieves the pressure and temperature from a MS5837
|
||||
sensor every 10 seconds, and prints this information to the UART console.
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
- `nRF52840 Preview development kit`_
|
||||
- MS5837 sensor
|
||||
|
||||
Wiring
|
||||
******
|
||||
|
||||
The nrf52840 Preview development kit should be connected as follows to the
|
||||
MS5837 sensor.
|
||||
|
||||
+-------------+----------+
|
||||
| | nrf52840 | | MS5837 |
|
||||
| | Pin | | Pin |
|
||||
+=============+==========+
|
||||
| P0.3 | SCL |
|
||||
+-------------+----------+
|
||||
| P0.31 | SDA |
|
||||
+-------------+----------+
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
Build this sample using the following commands:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/sensor/ms5837
|
||||
:board: nrf52840_pca10056
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
See :ref:`nrf52840_pca10056` on how to flash the build.
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
.. target-notes::
|
||||
|
||||
.. _MS5837 Sensor: http://www.te.com/usa-en/product-CAT-BLPS0017.html?q=&type=products&samples=N&q2=ms5837
|
||||
.. _nRF52840 Preview development kit: http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK
|
29
samples/sensor/ms5837/dts_fixup.h
Normal file
29
samples/sensor/ms5837/dts_fixup.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_HAS_DTS_I2C)
|
||||
|
||||
#ifdef CONFIG_I2C_NRFX
|
||||
|
||||
#ifndef CONFIG_MS5837_DEV_NAME
|
||||
|
||||
#define CONFIG_MS5837_DEV_NAME \
|
||||
NORDIC_NRF_I2C_40004000_MEAS_MS5837_76_LABEL
|
||||
#define CONFIG_MS5837_I2C_MASTER_DEV_NAME \
|
||||
NORDIC_NRF_I2C_40004000_MEAS_MS5837_76_BUS_NAME
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifndef CONFIG_MS5837_DEV_NAME
|
||||
#define CONFIG_MS5837_DEV_NAME ""
|
||||
#define CONFIG_MS5837_I2C_MASTER_DEV_NAME ""
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
15
samples/sensor/ms5837/nrf52840_pca10056.overlay
Normal file
15
samples/sensor/ms5837/nrf52840_pca10056.overlay
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&i2c1 {
|
||||
status = "ok";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
ms5837@76 {
|
||||
compatible = "meas,ms5837";
|
||||
reg = <0x76>;
|
||||
label = "MS5837";
|
||||
};
|
||||
};
|
15
samples/sensor/ms5837/prj.conf
Normal file
15
samples/sensor/ms5837/prj.conf
Normal file
|
@ -0,0 +1,15 @@
|
|||
CONFIG_STDOUT_CONSOLE=y
|
||||
|
||||
CONFIG_SYS_LOG=y
|
||||
CONFIG_SYS_LOG_SHOW_TAGS=y
|
||||
CONFIG_SYS_LOG_SHOW_COLOR=y
|
||||
CONFIG_SYS_LOG_DEFAULT_LEVEL=1
|
||||
CONFIG_SYS_LOG_OVERRIDE_LEVEL=1
|
||||
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_1=y
|
||||
CONFIG_I2C_NRFX=y
|
||||
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_MS5837=y
|
||||
|
8
samples/sensor/ms5837/sample.yaml
Normal file
8
samples/sensor/ms5837/sample.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
sample:
|
||||
description: TBD
|
||||
name: TBD
|
||||
tests:
|
||||
test:
|
||||
build_only: true
|
||||
platform_whitelist: nrf52840_pca10056
|
||||
tags: samples sensor
|
47
samples/sensor/ms5837/src/main.c
Normal file
47
samples/sensor/ms5837/src/main.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <sensor.h>
|
||||
#include <stdio.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
#define SYS_LOG_DOMAIN "main"
|
||||
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
|
||||
#include <logging/sys_log.h>
|
||||
|
||||
void main(void)
|
||||
{
|
||||
struct sensor_value oversampling_rate = { 8192, 0 };
|
||||
struct device *dev = device_get_binding(CONFIG_MS5837_DEV_NAME);
|
||||
|
||||
if (dev == NULL) {
|
||||
SYS_LOG_ERR("Could not find MS5837 device, aborting test.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sensor_attr_set(dev, SENSOR_CHAN_ALL, SENSOR_ATTR_OVERSAMPLING,
|
||||
&oversampling_rate) != 0) {
|
||||
SYS_LOG_ERR("Could not set oversampling rate of %d "
|
||||
"on MS5837 device, aborting test.",
|
||||
oversampling_rate.val1);
|
||||
return;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
struct sensor_value temp;
|
||||
struct sensor_value press;
|
||||
|
||||
sensor_sample_fetch(dev);
|
||||
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
|
||||
sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
|
||||
|
||||
printf("Temperature: %d.%06d, Pressure: %d.%06d\n", temp.val1,
|
||||
temp.val2, press.val1, press.val2);
|
||||
|
||||
k_sleep(10000);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue