Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <erwan.gouriou@linaro.org>
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. shields-samples: | ||
Shields Samples | ||
############### | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
|
||
**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<updated endlessly every 2 seconds> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_STDOUT_CONSOLE=y | ||
CONFIG_SHIELD_X_NUCLEO_IKS01A1=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sample: | ||
name: X-NUCLEO-IKS01A1 sensor shield | ||
tests: | ||
test: | ||
harness: shield | ||
tags: samples shield | ||
depends_on: arduino_i2c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2018 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr.h> | ||
#include <device.h> | ||
#include <sensor.h> | ||
#include <stdio.h> | ||
#include <misc/util.h> | ||
|
||
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); | ||
} | ||
} |