samples/shields: x-nucleo-iks4a1: Add lis2dux12 accel and temp test
Add sample display for lis2duxs12 accel and temp sensors. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
e4628ac60f
commit
02fa47f70e
3 changed files with 76 additions and 1 deletions
|
|
@ -16,6 +16,7 @@ periodically reads and displays data from the shield sensors:
|
|||
- LSM6DSO16IS 6-Axis acceleration and angular velocity
|
||||
- LPS22DF ambient temperature and atmospheric pressure
|
||||
- LIS2MDL 3-Axis magnetic field intensity
|
||||
- LIS2DUXS12 3-Axis acceleration
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
|
@ -53,10 +54,14 @@ Sample Output
|
|||
LSM6DSV16X: GYro (dps): x: -0.000, y: 0.000, z: 0.005
|
||||
LPS22DF: Temperature: 25.2 C
|
||||
LPS22DF: Pressure:98.121 kpa
|
||||
LIS2DUXS12: Accel (m.s-2): x: 0.689, y: -0.306, z: 9.571
|
||||
LIS2DUXS12: Temperature: 23.9 C
|
||||
|
||||
10:: lis2mdl trig 1839
|
||||
10:: lsm6dso16is acc trig 3892
|
||||
10:: lsm6dsv16x acc trig 4412
|
||||
10:: lps22df trig 174
|
||||
10:: lis2duxs12 acc trig 3681
|
||||
|
||||
<updated endlessly every 2 seconds>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ CONFIG_SENSOR=y
|
|||
CONFIG_SENSOR_LOG_LEVEL_DBG=y
|
||||
CONFIG_LIS2MDL_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LPS2XDF_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSO16IS_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSO16IS_TRIGGER_NONE=y
|
||||
CONFIG_LSM6DSO16IS_ENABLE_TEMP=y
|
||||
CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSV16X_ENABLE_TEMP=y
|
||||
CONFIG_LIS2DUX12_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LIS2DUX12_ENABLE_TEMP=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
|
|
|
|||
|
|
@ -54,6 +54,17 @@ static void lsm6dsv16x_acc_trig_handler(const struct device *dev,
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2DUX12_TRIGGER
|
||||
static int lis2duxs12_acc_trig_cnt;
|
||||
|
||||
static void lis2duxs12_acc_trig_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lis2duxs12_acc_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lis2mdl_config(const struct device *lis2mdl)
|
||||
{
|
||||
struct sensor_value odr_attr;
|
||||
|
|
@ -214,6 +225,37 @@ static void lps22df_config(const struct device *lps22df)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void lis2duxs12_config(const struct device *lis2duxs12)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LSM6DSV16X accel sampling frequency to 200 Hz */
|
||||
odr_attr.val1 = 200;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lis2duxs12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lis2duxs12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set fs for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIS2DUX12_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lis2duxs12, &trig, lis2duxs12_acc_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct sensor_value lis2mdl_magn[3], lis2mdl_temp, lps22df_press, lps22df_temp;
|
||||
|
|
@ -225,10 +267,12 @@ int main(void)
|
|||
struct sensor_value lsm6dsv16x_temp;
|
||||
#endif
|
||||
struct sensor_value lsm6dsv16x_xl[3], lsm6dsv16x_gy[3];
|
||||
struct sensor_value lis2duxs12_xl[3], lis2duxs12_temp;
|
||||
const struct device *const lis2mdl = DEVICE_DT_GET_ONE(st_lis2mdl);
|
||||
const struct device *const lsm6dso16is = DEVICE_DT_GET_ONE(st_lsm6dso16is);
|
||||
const struct device *const lsm6dsv16x = DEVICE_DT_GET_ONE(st_lsm6dsv16x);
|
||||
const struct device *const lps22df = DEVICE_DT_GET_ONE(st_lps22df);
|
||||
const struct device *const lis2duxs12 = DEVICE_DT_GET_ONE(st_lis2duxs12);
|
||||
int cnt = 1;
|
||||
|
||||
if (!device_is_ready(lsm6dso16is)) {
|
||||
|
|
@ -247,11 +291,16 @@ int main(void)
|
|||
printk("%s: device not ready.\n", lps22df->name);
|
||||
return 0;
|
||||
}
|
||||
if (!device_is_ready(lis2duxs12)) {
|
||||
printk("%s: device not ready.\n", lis2duxs12->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lis2mdl_config(lis2mdl);
|
||||
lsm6dso16is_config(lsm6dso16is);
|
||||
lsm6dsv16x_config(lsm6dsv16x);
|
||||
lps22df_config(lps22df);
|
||||
lis2duxs12_config(lis2duxs12);
|
||||
|
||||
while (1) {
|
||||
/* Get sensor samples */
|
||||
|
|
@ -280,6 +329,12 @@ int main(void)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_LIS2DUX12_TRIGGER
|
||||
if (sensor_sample_fetch(lis2duxs12) < 0) {
|
||||
printf("LIS2DUXS12 XL Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get sensor data */
|
||||
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_XYZ, lis2mdl_magn);
|
||||
|
|
@ -298,6 +353,8 @@ int main(void)
|
|||
sensor_channel_get(lps22df, SENSOR_CHAN_PRESS, &lps22df_press);
|
||||
sensor_channel_get(lps22df, SENSOR_CHAN_AMBIENT_TEMP, &lps22df_temp);
|
||||
|
||||
sensor_channel_get(lis2duxs12, SENSOR_CHAN_ACCEL_XYZ, lis2duxs12_xl);
|
||||
sensor_channel_get(lis2duxs12, SENSOR_CHAN_DIE_TEMP, &lis2duxs12_temp);
|
||||
/* Display sensor data */
|
||||
|
||||
/* Erase previous */
|
||||
|
|
@ -349,6 +406,14 @@ int main(void)
|
|||
printf("LPS22DF: Temperature: %.1f C\n", sensor_value_to_double(&lps22df_temp));
|
||||
printf("LPS22DF: Pressure:%.3f kpa\n", sensor_value_to_double(&lps22df_press));
|
||||
|
||||
printf("LIS2DUXS12: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lis2duxs12_xl[0]),
|
||||
sensor_value_to_double(&lis2duxs12_xl[1]),
|
||||
sensor_value_to_double(&lis2duxs12_xl[2]));
|
||||
|
||||
printf("LIS2DUXS12: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lis2duxs12_temp));
|
||||
|
||||
#if defined(CONFIG_LIS2MDL_TRIGGER)
|
||||
printk("%d: lis2mdl trig %d\n", cnt, lis2mdl_trig_cnt);
|
||||
#endif
|
||||
|
|
@ -363,6 +428,9 @@ int main(void)
|
|||
#ifdef CONFIG_LPS2XDF_TRIGGER
|
||||
printk("%d: lps22df trig %d\n", cnt, lps22df_trig_cnt);
|
||||
#endif
|
||||
#ifdef CONFIG_LIS2DUX12_TRIGGER
|
||||
printk("%d:: lis2duxs12 acc trig %d\n", cnt, lis2duxs12_acc_trig_cnt);
|
||||
#endif
|
||||
|
||||
cnt++;
|
||||
k_sleep(K_MSEC(2000));
|
||||
|
|
|
|||
Loading…
Reference in a new issue