From 7ee8b7a51280a5107b1e052942b0f132dc983aff Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 9 Apr 2018 16:35:19 +0200 Subject: [PATCH] samples: Provide x-nucleo-iks01a1 shield sample This sample is made to demonstrate use of shield x-nucleo-ik01a1. It will display embedded sensor data endlessly. It requires a board with Arduino i2c as minimum configuration Signed-off-by: Erwan Gouriou --- samples/samples.rst | 1 + samples/shields/shields.rst | 10 ++ .../shields/x_nucleo_iks01a1/CMakeLists.txt | 7 ++ samples/shields/x_nucleo_iks01a1/README.rst | 55 ++++++++++ samples/shields/x_nucleo_iks01a1/prj.conf | 2 + samples/shields/x_nucleo_iks01a1/sample.yaml | 7 ++ samples/shields/x_nucleo_iks01a1/src/main.c | 103 ++++++++++++++++++ 7 files changed, 185 insertions(+) create mode 100644 samples/shields/shields.rst create mode 100644 samples/shields/x_nucleo_iks01a1/CMakeLists.txt create mode 100644 samples/shields/x_nucleo_iks01a1/README.rst create mode 100644 samples/shields/x_nucleo_iks01a1/prj.conf create mode 100644 samples/shields/x_nucleo_iks01a1/sample.yaml create mode 100644 samples/shields/x_nucleo_iks01a1/src/main.c diff --git a/samples/samples.rst b/samples/samples.rst index cd1ebfdcbbdb19..dacc0bb192922e 100644 --- a/samples/samples.rst +++ b/samples/samples.rst @@ -19,6 +19,7 @@ Samples and Demos drivers/drivers.rst application_development/* display/* + shields/* To add a new sample document, please use the template available under :file:`doc/templates/sample.tmpl` diff --git a/samples/shields/shields.rst b/samples/shields/shields.rst new file mode 100644 index 00000000000000..c41fecf91f9b09 --- /dev/null +++ b/samples/shields/shields.rst @@ -0,0 +1,10 @@ +.. shields-samples: + +Shields Samples +############### + +.. toctree:: + :maxdepth: 1 + :glob: + + **/* diff --git a/samples/shields/x_nucleo_iks01a1/CMakeLists.txt b/samples/shields/x_nucleo_iks01a1/CMakeLists.txt new file mode 100644 index 00000000000000..af818872cf355d --- /dev/null +++ b/samples/shields/x_nucleo_iks01a1/CMakeLists.txt @@ -0,0 +1,7 @@ +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}) diff --git a/samples/shields/x_nucleo_iks01a1/README.rst b/samples/shields/x_nucleo_iks01a1/README.rst new file mode 100644 index 00000000000000..8dd2f438d0fe5c --- /dev/null +++ b/samples/shields/x_nucleo_iks01a1/README.rst @@ -0,0 +1,55 @@ +.. _x-nucleo-iks01a1-sample: + +X-NUCLEO-IKS01A1: MEMS inertial and environmental multi-sensor shield +##################################################################### + +Overview +******** +This sample enables all sensors of a X-NUCLEO-IKS01A1 shield, and then +periodically reads and displays data from the shield sensors: + +- HTS221: Temperature and humidity +- LPS25HB: Atmospheric pressure +- LIS3MDL: 3-axis Magnetic field intensity +- LSM6DSL: 3-Axis Acceleration + +Requirements +************ + +This sample communicates over I2C with the X-NUCLEO-IKS01A1 shield +stacked on a board with an Arduino connector. The board's I2C must be +configured for the I2C Arduino connector (both for pin muxing +and device tree). + +References +********** + +-X-NUCLEO-IKS01A1: http://www.st.com/en/ecosystems/x-nucleo-iks01a1.html + +Building and Running +******************** + +This sample runs with X-NUCLEO-IKS01A1 stacked on any board with a matching +Arduino connector. For this example, we use a :ref:`nucleo_f429zi_board` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/shields/x_nucleo_iks01a1 + :board: nucleo_f429zi + :goals: build + :compact: + +Sample Output +============= + + .. code-block:: console + + X-NUCLEO-IKS01A1 sensor dashboard + + HTS221: Temperature:29.1 C + HTS221: Relative Humidity:46.0% + LPS25HB: Pressure:100.0 kpa + LIS3MDL: Magnetic field (gauss): x: 0.1, y: -0.4, z: 0.4 + LSM6DS0: Acceleration (m.s-2): x: -0.0, y: -0.1, z: 9.7 + + + diff --git a/samples/shields/x_nucleo_iks01a1/prj.conf b/samples/shields/x_nucleo_iks01a1/prj.conf new file mode 100644 index 00000000000000..305ffb25faae50 --- /dev/null +++ b/samples/shields/x_nucleo_iks01a1/prj.conf @@ -0,0 +1,2 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_SHIELD_X_NUCLEO_IKS01A1=y diff --git a/samples/shields/x_nucleo_iks01a1/sample.yaml b/samples/shields/x_nucleo_iks01a1/sample.yaml new file mode 100644 index 00000000000000..e49405ae9b55f6 --- /dev/null +++ b/samples/shields/x_nucleo_iks01a1/sample.yaml @@ -0,0 +1,7 @@ +sample: + name: X-NUCLEO-IKS01A1 sensor shield +tests: + test: + harness: shield + tags: samples shield + depends_on: arduino_i2c diff --git a/samples/shields/x_nucleo_iks01a1/src/main.c b/samples/shields/x_nucleo_iks01a1/src/main.c new file mode 100644 index 00000000000000..eb789627e0a874 --- /dev/null +++ b/samples/shields/x_nucleo_iks01a1/src/main.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2018 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +void main(void) +{ + struct sensor_value temp, hum, press; + struct sensor_value magn_xyz[3], accel_xyz[3]; + struct device *hts221 = device_get_binding(CONFIG_HTS221_NAME); + struct device *lis3mdl = device_get_binding(CONFIG_LIS3MDL_NAME); + struct device *lsm6ds0 = device_get_binding(CONFIG_LSM6DS0_DEV_NAME); + struct device *lps25hb = device_get_binding(CONFIG_LPS25HB_DEV_NAME); + + if (hts221 == NULL) { + printf("Could not get HTS221 device\n"); + return; + } + if (lis3mdl == NULL) { + printf("Could not get LIS3MDL device\n"); + return; + } + if (lsm6ds0 == NULL) { + printf("Could not get LSM6DS0 device\n"); + return; + } + if (lps25hb == NULL) { + printf("Could not get LPS25HB device\n"); + return; + } + + while (1) { + + /* Get sensor samples */ + + if (sensor_sample_fetch(hts221) < 0) { + printf("HTS221 Sensor sample update error\n"); + return; + } + if (sensor_sample_fetch(lps25hb) < 0) { + printf("LPS25HB Sensor sample update error\n"); + return; + } + if (sensor_sample_fetch(lis3mdl) < 0) { + printf("LIS3MDL Sensor sample update error\n"); + return; + } + if (sensor_sample_fetch(lsm6ds0) < 0) { + printf("LSM6DS0 Sensor sample update error\n"); + return; + } + + /* Get sensor data */ + + sensor_channel_get(hts221, SENSOR_CHAN_AMBIENT_TEMP, &temp); + sensor_channel_get(hts221, SENSOR_CHAN_HUMIDITY, &hum); + sensor_channel_get(lps25hb, SENSOR_CHAN_PRESS, &press); + sensor_channel_get(lis3mdl, SENSOR_CHAN_MAGN_XYZ, magn_xyz); + sensor_channel_get(lsm6ds0, SENSOR_CHAN_ACCEL_XYZ, accel_xyz); + + /* Display sensor data */ + + /* Erase previous */ + printf("\0033\014"); + + printf("X-NUCLEO-IKS01A1 sensor dashboard\n\n"); + + /* temperature */ + printf("HTS221: Temperature: %.1f C\n", + sensor_value_to_double(&temp)); + + /* humidity */ + printf("HTS221: Relative Humidity: %.1f%%\n", + sensor_value_to_double(&hum)); + + /* pressure */ + printf("LPS25HB: Pressure:%.1f kpa\n", + sensor_value_to_double(&press)); + + /* magneto data */ + printf( + "LIS3MDL: Magnetic field (gauss): x: %.1f, y: %.1f, z: %.1f\n", + sensor_value_to_double(&magn_xyz[0]), + sensor_value_to_double(&magn_xyz[1]), + sensor_value_to_double(&magn_xyz[2])); + + /* acceleration */ + printf( + "LSM6DS0: Acceleration (m.s-2): x: %.1f, y: %.1f, z: %.1f\n", + sensor_value_to_double(&accel_xyz[0]), + sensor_value_to_double(&accel_xyz[1]), + sensor_value_to_double(&accel_xyz[2])); + + k_sleep(2000); + } +}