sample/shield: add support to x-nucleo-iks01a3 shield
Provide two basic example samples to test the x-nucleo-iks01a3 shield: - Standard (Mode 1) - SensorHub (Mode 2) Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
196997439b
commit
75e1f4ef1a
|
@ -297,6 +297,7 @@
|
|||
/samples/sensor/ @MaureenHelm
|
||||
/samples/net/updatehub/ @chtavares592 @otavio
|
||||
/samples/sensor/ @bogdan-davidoaia
|
||||
/samples/shields/ @avisconti
|
||||
/samples/subsys/logging/ @nordic-krch @jakub-uC
|
||||
/samples/subsys/shell/ @jakub-uC @nordic-krch
|
||||
/samples/subsys/usb/ @jfischer-phytec-iot @finikorg
|
||||
|
|
17
samples/shields/x_nucleo_iks01a3/sensorhub/CMakeLists.txt
Normal file
17
samples/shields/x_nucleo_iks01a3/sensorhub/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Copyright (c) 2019 STMicroelectronics
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
# This sample is specific to x_nucleo_iks01a3 shield. Enforce -DSHIELD option
|
||||
set(SHIELD x_nucleo_iks01a3_shub)
|
||||
|
||||
# IKS01A3 board configured in sensorhub mode
|
||||
set(CONF_FILE shub.conf)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(x_nucleo_iks01a3)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
80
samples/shields/x_nucleo_iks01a3/sensorhub/README.rst
Normal file
80
samples/shields/x_nucleo_iks01a3/sensorhub/README.rst
Normal file
|
@ -0,0 +1,80 @@
|
|||
.. _x-nucleo-iks01a3-shub-sample:
|
||||
|
||||
X-NUCLEO-IKS01A3: shield (Mode 2) sample
|
||||
########################################
|
||||
|
||||
Overview
|
||||
********
|
||||
This sample is provided as an example to test the X-NUCLEO-IKS01A3 shield
|
||||
configured in Sensor Hub mode (Mode 2).
|
||||
Please refer to :ref:`x-nucleo-iks01a3` for more info on this configuration.
|
||||
|
||||
This sample enables LIS2DW12 and LSM6DSO sensors. Since all other shield
|
||||
devices are connected to LSM6DSO, the LSM6DSO driver is configured in sensorhub
|
||||
mode (CONFIG_LSM6DSO_SENSORHUB=y) with a selection of two maximum slaves
|
||||
among LPS22HH, HTS221 and LIS2MDL (default is LIS2MDL + LPS22HH).
|
||||
|
||||
Then sensor data are displayed periodically
|
||||
|
||||
- LIS2DW12 3-Axis acceleration
|
||||
- LSM6DSO 6-Axis acceleration and angular velocity
|
||||
- LSM6DSO (from LIS2MDL) 3-Axis magnetic field intensity
|
||||
- LSM6DSO (from LPS22HH) ambient temperature and atmospheric pressure
|
||||
|
||||
Optionally HTS221 can substitute one between LIS2MDL and LPS22HH
|
||||
|
||||
- LSM6DSO (from HTS221): ambient temperature and relative humidity
|
||||
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
This sample communicates over I2C with the X-NUCLEO-IKS01A3 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). See for example the :ref:`nucleo_f401re_board` board
|
||||
source code:
|
||||
|
||||
- :file:`$ZEPHYR_BASE/boards/arm/nucleo_f401re/nucleo_f401re.dts`
|
||||
- :file:`$ZEPHYR_BASE/boards/arm/nucleo_f401re/pinmux.c`
|
||||
|
||||
Please note that this sample can't be used with boards already supporting
|
||||
one of the sensors available on the shield (such as disco_l475_iot1)
|
||||
as sensors multiple instances are not supported.
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
- X-NUCLEO-IKS01A3: http://www.st.com/en/ecosystems/x-nucleo-iks01a3.html
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample runs with X-NUCLEO-IKS01A3 stacked on any board with a matching
|
||||
Arduino connector. For this example, we use a :ref:`nucleo_f401re_board` board.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/shields/x_nucleo_iks01a3/sensorhub/
|
||||
:host-os: unix
|
||||
:board: nucleo_f401re
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
|
||||
X-NUCLEO-IKS01A3 sensor dashboard
|
||||
|
||||
LIS2DW12: Accel (m.s-2): x: -0.077, y: 0.536, z: 9.648
|
||||
LSM6DSO: Accel (m.s-2): x: -0.062, y: -0.028, z: 10.035
|
||||
LSM6DSO: GYro (dps): x: -0.003, y: -0.001, z: 0.000
|
||||
LSM6DSO: Magn (gauss): x: -0.052, y: -0.222, z: -0.059
|
||||
LSM6DSO: Temperature: 27.9 C
|
||||
LSM6DSO: Pressure:100.590 kpa
|
||||
1:: lsm6dso acc trig 208
|
||||
1:: lsm6dso gyr trig 208
|
||||
|
||||
<updated endlessly every 2 seconds>
|
9
samples/shields/x_nucleo_iks01a3/sensorhub/sample.yaml
Normal file
9
samples/shields/x_nucleo_iks01a3/sensorhub/sample.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
sample:
|
||||
name: X-NUCLEO-IKS01A3 sensor shield
|
||||
tests:
|
||||
test:
|
||||
platform_exclude: disco_l475_iot1
|
||||
harness: shield
|
||||
tags: shield
|
||||
depends_on: arduino_i2c arduino_header
|
||||
platform_exclude: disco_l475_iot1
|
16
samples/shields/x_nucleo_iks01a3/sensorhub/shub.conf
Normal file
16
samples/shields/x_nucleo_iks01a3/sensorhub/shub.conf
Normal file
|
@ -0,0 +1,16 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_STM32_INTERRUPT=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_SENSOR_LOG_LEVEL_DBG=y
|
||||
CONFIG_LIS2DW12=y
|
||||
CONFIG_LIS2DW12_TRIGGER_NONE=y
|
||||
CONFIG_LSM6DSO=y
|
||||
CONFIG_LSM6DSO_ENABLE_TEMP=n
|
||||
CONFIG_LSM6DSO_INT_PIN_1=y
|
||||
CONFIG_LSM6DSO_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSO_SENSORHUB=y
|
||||
CONFIG_LSM6DSO_EXT_LIS2MDL=y
|
||||
CONFIG_LSM6DSO_EXT_LPS22HH=y
|
||||
CONFIG_LSM6DSO_EXT_HTS221=n
|
295
samples/shields/x_nucleo_iks01a3/sensorhub/src/main.c
Normal file
295
samples/shields/x_nucleo_iks01a3/sensorhub/src/main.c
Normal file
|
@ -0,0 +1,295 @@
|
|||
/*
|
||||
* Copyright (c) 2019 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <sensor.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/util.h>
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
static int lis2dw12_trig_cnt;
|
||||
|
||||
static void lis2dw12_trigger_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
|
||||
lis2dw12_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||
static int lsm6dso_acc_trig_cnt;
|
||||
static int lsm6dso_gyr_trig_cnt;
|
||||
static int lsm6dso_temp_trig_cnt;
|
||||
|
||||
static void lsm6dso_acc_trig_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
|
||||
lsm6dso_acc_trig_cnt++;
|
||||
}
|
||||
|
||||
static void lsm6dso_gyr_trig_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
|
||||
lsm6dso_gyr_trig_cnt++;
|
||||
}
|
||||
|
||||
static void lsm6dso_temp_trig_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_DIE_TEMP);
|
||||
lsm6dso_temp_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lis2dw12_config(struct device *lis2dw12)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LIS2DW12 accel/gyro sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lis2dw12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LIS2DW12 accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lis2dw12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LIS2DW12 gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lis2dw12, &trig, lis2dw12_trigger_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lsm6dso_config(struct device *lsm6dso)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LSM6DSO accel sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set fs for LSM6DSO accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO gyro sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_degrees_to_rad(250, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set fs for LSM6DSO gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO external magn sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LIS2MDL
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_MAGN_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO ext magn\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LPS22HH
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_PRESS,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO ext pressure\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_EXT_HTS221
|
||||
odr_attr.val1 = 12;
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_HUMIDITY,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO ext humidity\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lsm6dso, &trig, lsm6dso_acc_trig_handler);
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_GYRO_XYZ;
|
||||
sensor_trigger_set(lsm6dso, &trig, lsm6dso_gyr_trig_handler);
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_DIE_TEMP;
|
||||
sensor_trigger_set(lsm6dso, &trig, lsm6dso_temp_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LPS22HH
|
||||
struct sensor_value temp2, press;
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO_EXT_HTS221
|
||||
struct sensor_value hum;
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO_ENABLE_TEMP
|
||||
struct sensor_value die_temp;
|
||||
#endif
|
||||
struct sensor_value accel1[3], accel2[3];
|
||||
struct sensor_value gyro[3];
|
||||
struct sensor_value magn[3];
|
||||
struct device *lis2dw12 = device_get_binding(DT_INST_0_ST_LIS2DW12_LABEL);
|
||||
struct device *lsm6dso = device_get_binding(DT_INST_0_ST_LSM6DSO_LABEL);
|
||||
int cnt = 1;
|
||||
|
||||
if (lis2dw12 == NULL) {
|
||||
printf("Could not get LIS2DW12 device\n");
|
||||
return;
|
||||
}
|
||||
if (lsm6dso == NULL) {
|
||||
printf("Could not get LSM6DSO device\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lis2dw12_config(lis2dw12);
|
||||
lsm6dso_config(lsm6dso);
|
||||
|
||||
while (1) {
|
||||
/* Get sensor samples */
|
||||
|
||||
#ifndef CONFIG_LIS2DW12_TRIGGER
|
||||
if (sensor_sample_fetch(lis2dw12) < 0) {
|
||||
printf("LIS2DW12 Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_LSM6DSO_TRIGGER
|
||||
if (sensor_sample_fetch(lsm6dso) < 0) {
|
||||
printf("LSM6DSO Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get sensor data */
|
||||
sensor_channel_get(lis2dw12, SENSOR_CHAN_ACCEL_XYZ, accel2);
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_XYZ, accel1);
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_XYZ, gyro);
|
||||
#ifdef CONFIG_LSM6DSO_ENABLE_TEMP
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_DIE_TEMP, &die_temp);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LIS2MDL
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_MAGN_XYZ, magn);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LPS22HH
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_AMBIENT_TEMP, &temp2);
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_PRESS, &press);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO_EXT_HTS221
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_HUMIDITY, &hum);
|
||||
#endif
|
||||
|
||||
/* Display sensor data */
|
||||
|
||||
/* Erase previous */
|
||||
printf("\0033\014");
|
||||
|
||||
printf("X-NUCLEO-IKS01A3 sensor dashboard\n\n");
|
||||
|
||||
printf("LIS2DW12: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&accel2[0]),
|
||||
sensor_value_to_double(&accel2[1]),
|
||||
sensor_value_to_double(&accel2[2]));
|
||||
|
||||
printf("LSM6DSO: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&accel1[0]),
|
||||
sensor_value_to_double(&accel1[1]),
|
||||
sensor_value_to_double(&accel1[2]));
|
||||
|
||||
printf("LSM6DSO: GYro (dps): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&gyro[0]),
|
||||
sensor_value_to_double(&gyro[1]),
|
||||
sensor_value_to_double(&gyro[2]));
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_ENABLE_TEMP
|
||||
/* temperature */
|
||||
printf("LSM6DSO: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&die_temp));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LIS2MDL
|
||||
printf("LSM6DSO: Magn (gauss): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&magn[0]),
|
||||
sensor_value_to_double(&magn[1]),
|
||||
sensor_value_to_double(&magn[2]));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_EXT_LPS22HH
|
||||
printf("LSM6DSO: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&temp2));
|
||||
|
||||
printf("LSM6DSO: Pressure:%.3f kpa\n",
|
||||
sensor_value_to_double(&press));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_EXT_HTS221
|
||||
printf("LSM6DSO: Relative Humidity: %.1f%%\n",
|
||||
sensor_value_to_double(&hum));
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
printk("%d:: lis2dw12 trig %d\n", cnt, lis2dw12_trig_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||
printk("%d:: lsm6dso acc trig %d\n", cnt, lsm6dso_acc_trig_cnt);
|
||||
printk("%d:: lsm6dso gyr trig %d\n", cnt, lsm6dso_gyr_trig_cnt);
|
||||
printk("%d:: lsm6dso temp trig %d\n", cnt,
|
||||
lsm6dso_temp_trig_cnt);
|
||||
#endif
|
||||
|
||||
cnt++;
|
||||
k_sleep(2000);
|
||||
}
|
||||
}
|
16
samples/shields/x_nucleo_iks01a3/standard/CMakeLists.txt
Normal file
16
samples/shields/x_nucleo_iks01a3/standard/CMakeLists.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Copyright (c) 2019 STMicroelectronics
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
# This sample is specific to x_nucleo_iks01a3 shield. Enforce -DSHIELD option
|
||||
set(SHIELD x_nucleo_iks01a3)
|
||||
|
||||
set(CONF_FILE prj.conf)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(x_nucleo_iks01a3)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
75
samples/shields/x_nucleo_iks01a3/standard/README.rst
Normal file
75
samples/shields/x_nucleo_iks01a3/standard/README.rst
Normal file
|
@ -0,0 +1,75 @@
|
|||
.. _x-nucleo-iks01a3-std-sample:
|
||||
|
||||
X-NUCLEO-IKS01A3: shield Standard (Mode 1) sample
|
||||
#################################################
|
||||
|
||||
Overview
|
||||
********
|
||||
This sample is provided as an example to test the X-NUCLEO-IKS01A3 shield
|
||||
configured in Standard mode (Mode 1).
|
||||
Please refer to :ref:`x-nucleo-iks01a3` for more info on this configuration.
|
||||
|
||||
This sample enables all sensors of a X-NUCLEO-IKS01A3 shield, and then
|
||||
periodically reads and displays data from the shield sensors:
|
||||
|
||||
- HTS221: ambient temperature and relative humidity
|
||||
- LPS22HH ambient temperature and atmospheric pressure
|
||||
- LIS2MDL 3-Axis magnetic field intensity
|
||||
- LIS2DW12 3-Axis acceleration
|
||||
- LSM6DSO 6-Axis acceleration and angular velocity
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
This sample communicates over I2C with the X-NUCLEO-IKS01A3 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). See for example the :ref:`nucleo_f401re_board` board
|
||||
source code:
|
||||
|
||||
- :file:`$ZEPHYR_BASE/boards/arm/nucleo_f401re/nucleo_f401re.dts`
|
||||
- :file:`$ZEPHYR_BASE/boards/arm/nucleo_f401re/pinmux.c`
|
||||
|
||||
Please note that this sample can't be used with boards already supporting
|
||||
one of the sensors available on the shield (such as disco_l475_iot1)
|
||||
as sensors multiple instances are not supported.
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
- X-NUCLEO-IKS01A3: http://www.st.com/en/ecosystems/x-nucleo-iks01a3.html
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample runs with X-NUCLEO-IKS01A3 stacked on any board with a matching
|
||||
Arduino connector. For this example, we use a :ref:`nucleo_f401re_board` board.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/shields/x_nucleo_iks01a3/standard/
|
||||
:host-os: unix
|
||||
:board: nucleo_f401re
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
|
||||
X-NUCLEO-IKS01A3 sensor dashboard
|
||||
|
||||
HTS221: Temperature: 27.5 C
|
||||
HTS221: Relative Humidity: 27.0%
|
||||
LPS22HH: Temperature: 27.3 C
|
||||
LPS22HH: Pressure:99.150 kpa
|
||||
LIS2MDL: Magn (gauss): x: -0.445, y: -0.054, z: -0.066
|
||||
LIS2DW12: Accel (m.s-2): x: -0.413, y: 0.077, z: 10.337
|
||||
LSM6DSO: Accel (m.s-2): x: 0.133, y: -0.133, z: 10.102
|
||||
LSM6DSO: GYro (dps): x: 0.000, y: -0.006, z: -0.058
|
||||
1:: lps22hh trig 200
|
||||
1:: lsm6dso acc trig 200
|
||||
1:: lsm6dso gyr trig 200
|
||||
|
||||
<updated endlessly every 2 seconds>
|
18
samples/shields/x_nucleo_iks01a3/standard/prj.conf
Normal file
18
samples/shields/x_nucleo_iks01a3/standard/prj.conf
Normal file
|
@ -0,0 +1,18 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_STM32_INTERRUPT=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_SENSOR_LOG_LEVEL_DBG=y
|
||||
CONFIG_HTS221=y
|
||||
CONFIG_HTS221_TRIGGER_NONE=y
|
||||
CONFIG_LPS22HH=y
|
||||
CONFIG_LPS22HH_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LIS2MDL=y
|
||||
CONFIG_LIS2MDL_TRIGGER_NONE=y
|
||||
CONFIG_LIS2DW12=y
|
||||
CONFIG_LIS2DW12_TRIGGER_NONE=y
|
||||
CONFIG_LSM6DSO=y
|
||||
CONFIG_LSM6DSO_ENABLE_TEMP=n
|
||||
CONFIG_LSM6DSO_INT_PIN_1=y
|
||||
CONFIG_LSM6DSO_TRIGGER_OWN_THREAD=y
|
9
samples/shields/x_nucleo_iks01a3/standard/sample.yaml
Normal file
9
samples/shields/x_nucleo_iks01a3/standard/sample.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
sample:
|
||||
name: X-NUCLEO-IKS01A3 sensor shield
|
||||
tests:
|
||||
test:
|
||||
platform_exclude: disco_l475_iot1
|
||||
harness: shield
|
||||
tags: shield
|
||||
depends_on: arduino_i2c arduino_header
|
||||
platform_exclude: disco_l475_iot1
|
327
samples/shields/x_nucleo_iks01a3/standard/src/main.c
Normal file
327
samples/shields/x_nucleo_iks01a3/standard/src/main.c
Normal file
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* Copyright (c) 2019 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <sensor.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/util.h>
|
||||
|
||||
#ifdef CONFIG_LPS22HH_TRIGGER
|
||||
static int lps22hh_trig_cnt;
|
||||
|
||||
static void lps22hh_trigger_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_PRESS);
|
||||
lps22hh_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
static int lis2dw12_trig_cnt;
|
||||
|
||||
static void lis2dw12_trigger_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
|
||||
lis2dw12_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||
static int lsm6dso_acc_trig_cnt;
|
||||
static int lsm6dso_gyr_trig_cnt;
|
||||
static int lsm6dso_temp_trig_cnt;
|
||||
|
||||
static void lsm6dso_acc_trig_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
|
||||
lsm6dso_acc_trig_cnt++;
|
||||
}
|
||||
|
||||
static void lsm6dso_gyr_trig_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
|
||||
lsm6dso_gyr_trig_cnt++;
|
||||
}
|
||||
|
||||
static void lsm6dso_temp_trig_handler(struct device *dev,
|
||||
struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_DIE_TEMP);
|
||||
lsm6dso_temp_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lps22hh_config(struct device *lps22hh)
|
||||
{
|
||||
struct sensor_value odr_attr;
|
||||
|
||||
/* set LPS22HH sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lps22hh, SENSOR_CHAN_ALL,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LPS22HH\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LPS22HH_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ALL;
|
||||
sensor_trigger_set(lps22hh, &trig, lps22hh_trigger_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lis2dw12_config(struct device *lis2dw12)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LIS2DW12 accel/gyro sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lis2dw12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LIS2DW12 accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lis2dw12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LIS2DW12 gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lis2dw12, &trig, lis2dw12_trigger_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lsm6dso_config(struct device *lsm6dso)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LSM6DSO accel sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set fs for LSM6DSO accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO gyro sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_degrees_to_rad(250, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set fs for LSM6DSO gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lsm6dso, &trig, lsm6dso_acc_trig_handler);
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_GYRO_XYZ;
|
||||
sensor_trigger_set(lsm6dso, &trig, lsm6dso_gyr_trig_handler);
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_DIE_TEMP;
|
||||
sensor_trigger_set(lsm6dso, &trig, lsm6dso_temp_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
struct sensor_value temp1, temp2, hum, press;
|
||||
#ifdef CONFIG_LSM6DSO_ENABLE_TEMP
|
||||
struct sensor_value die_temp;
|
||||
#endif
|
||||
struct sensor_value accel1[3], accel2[3];
|
||||
struct sensor_value gyro[3];
|
||||
struct sensor_value magn[3];
|
||||
struct device *hts221 = device_get_binding(DT_INST_0_ST_HTS221_LABEL);
|
||||
struct device *lps22hh = device_get_binding(DT_INST_0_ST_LPS22HH_LABEL);
|
||||
struct device *lis2mdl = device_get_binding(DT_INST_0_ST_LIS2MDL_MAGN_LABEL);
|
||||
struct device *lis2dw12 = device_get_binding(DT_INST_0_ST_LIS2DW12_LABEL);
|
||||
struct device *lsm6dso = device_get_binding(DT_INST_0_ST_LSM6DSO_LABEL);
|
||||
int cnt = 1;
|
||||
|
||||
if (hts221 == NULL) {
|
||||
printf("Could not get HTS221 device\n");
|
||||
return;
|
||||
}
|
||||
if (lps22hh == NULL) {
|
||||
printf("Could not get LPS22HH device\n");
|
||||
return;
|
||||
}
|
||||
if (lis2mdl == NULL) {
|
||||
printf("Could not get LIS2MDL Magn device\n");
|
||||
return;
|
||||
}
|
||||
if (lis2dw12 == NULL) {
|
||||
printf("Could not get LIS2DW12 device\n");
|
||||
return;
|
||||
}
|
||||
if (lsm6dso == NULL) {
|
||||
printf("Could not get LSM6DSO device\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lps22hh_config(lps22hh);
|
||||
lis2dw12_config(lis2dw12);
|
||||
lsm6dso_config(lsm6dso);
|
||||
|
||||
while (1) {
|
||||
/* Get sensor samples */
|
||||
|
||||
if (sensor_sample_fetch(hts221) < 0) {
|
||||
printf("HTS221 Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
#ifndef CONFIG_LPS22HH_TRIGGER
|
||||
if (sensor_sample_fetch(lps22hh) < 0) {
|
||||
printf("LPS22HH Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (sensor_sample_fetch(lis2mdl) < 0) {
|
||||
printf("LIS2MDL Magn Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_LIS2DW12_TRIGGER
|
||||
if (sensor_sample_fetch(lis2dw12) < 0) {
|
||||
printf("LIS2DW12 Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_LSM6DSO_TRIGGER
|
||||
if (sensor_sample_fetch(lsm6dso) < 0) {
|
||||
printf("LSM6DSO Sensor sample update error\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get sensor data */
|
||||
|
||||
sensor_channel_get(hts221, SENSOR_CHAN_AMBIENT_TEMP, &temp1);
|
||||
sensor_channel_get(hts221, SENSOR_CHAN_HUMIDITY, &hum);
|
||||
sensor_channel_get(lps22hh, SENSOR_CHAN_AMBIENT_TEMP, &temp2);
|
||||
sensor_channel_get(lps22hh, SENSOR_CHAN_PRESS, &press);
|
||||
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_XYZ, magn);
|
||||
sensor_channel_get(lis2dw12, SENSOR_CHAN_ACCEL_XYZ, accel2);
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_XYZ, accel1);
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_XYZ, gyro);
|
||||
#ifdef CONFIG_LSM6DSO_ENABLE_TEMP
|
||||
sensor_channel_get(lsm6dso, SENSOR_CHAN_DIE_TEMP, &die_temp);
|
||||
#endif
|
||||
|
||||
/* Display sensor data */
|
||||
|
||||
/* Erase previous */
|
||||
printf("\0033\014");
|
||||
|
||||
printf("X-NUCLEO-IKS01A3 sensor dashboard\n\n");
|
||||
|
||||
/* temperature */
|
||||
printf("HTS221: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&temp1));
|
||||
|
||||
/* humidity */
|
||||
printf("HTS221: Relative Humidity: %.1f%%\n",
|
||||
sensor_value_to_double(&hum));
|
||||
|
||||
/* temperature */
|
||||
printf("LPS22HH: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&temp2));
|
||||
|
||||
/* pressure */
|
||||
printf("LPS22HH: Pressure:%.3f kpa\n",
|
||||
sensor_value_to_double(&press));
|
||||
|
||||
/* lis2mdl */
|
||||
printf("LIS2MDL: Magn (gauss): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&magn[0]),
|
||||
sensor_value_to_double(&magn[1]),
|
||||
sensor_value_to_double(&magn[2]));
|
||||
|
||||
printf("LIS2DW12: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&accel2[0]),
|
||||
sensor_value_to_double(&accel2[1]),
|
||||
sensor_value_to_double(&accel2[2]));
|
||||
|
||||
printf("LSM6DSO: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&accel1[0]),
|
||||
sensor_value_to_double(&accel1[1]),
|
||||
sensor_value_to_double(&accel1[2]));
|
||||
|
||||
printf("LSM6DSO: GYro (dps): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&gyro[0]),
|
||||
sensor_value_to_double(&gyro[1]),
|
||||
sensor_value_to_double(&gyro[2]));
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_ENABLE_TEMP
|
||||
/* temperature */
|
||||
printf("LSM6DSO: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&die_temp));
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LPS22HH_TRIGGER)
|
||||
printk("%d:: lps22hh trig %d\n", cnt, lps22hh_trig_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2DW12_TRIGGER
|
||||
printk("%d:: lis2dw12 trig %d\n", cnt, lis2dw12_trig_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO_TRIGGER
|
||||
printk("%d:: lsm6dso acc trig %d\n", cnt, lsm6dso_acc_trig_cnt);
|
||||
printk("%d:: lsm6dso gyr trig %d\n", cnt, lsm6dso_gyr_trig_cnt);
|
||||
printk("%d:: lsm6dso temp trig %d\n", cnt,
|
||||
lsm6dso_temp_trig_cnt);
|
||||
#endif
|
||||
|
||||
cnt++;
|
||||
k_sleep(2000);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue