sample: board: sensortile_box_pro: extend with lis2du12 accelerometer
Extend sensor sample reading also lis2du12 accelerometer data. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
23110dcfae
commit
3fe0ffb9dc
@ -15,6 +15,7 @@ sensors:
|
||||
- HTS221: ambient temperature and relative humidity
|
||||
- LPS22DF: ambient temperature and atmospheric pressure
|
||||
- LSM6DSV16X: 6-Axis acceleration and angular velocity
|
||||
- LIS2DU12: 3-Axis acceleration
|
||||
|
||||
Requirements
|
||||
************
|
||||
@ -67,7 +68,11 @@ The sample code outputs sensors data on the SensorTile.box Pro console.
|
||||
LPS22DF: Pressure:99.694 kpa
|
||||
LSM6DSV16X: Accel (m.s-2): x: -0.158, y: 0.158, z: 9.811
|
||||
LSM6DSV16X: GYro (dps): x: 0.003, y: 0.000, z: -0.005
|
||||
LIS2DU12: Accel (m.s-2): x: -0.756, y: -0.249, z: -9.629
|
||||
1:: lps22df trig 199
|
||||
1:: lsm6dsv16x acc trig 836
|
||||
1:: lsm6dsv16x gyr trig 836
|
||||
1:: lis2mdl trig 402
|
||||
1:: lis2du12 trig 1589
|
||||
|
||||
<repeats endlessly every 2s>
|
||||
|
||||
@ -11,5 +11,6 @@ CONFIG_HTS221_TRIGGER_NONE=y
|
||||
CONFIG_LPS2XDF_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LIS2MDL_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LIS2DU12_TRIGGER_OWN_THREAD=y
|
||||
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
|
||||
@ -64,6 +64,17 @@ static void lis2mdl_trigger_handler(const struct device *dev,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2DU12_TRIGGER
|
||||
static int lis2du12_trig_cnt;
|
||||
|
||||
static void lis2du12_trigger_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lis2du12_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lps22df_config(const struct device *lps22df)
|
||||
{
|
||||
struct sensor_value odr_attr;
|
||||
@ -167,6 +178,29 @@ static void lis2mdl_config(const struct device *lis2mdl)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lis2du12_config(const struct device *lis2du12)
|
||||
{
|
||||
struct sensor_value odr_attr;
|
||||
|
||||
/* set LIS2DU12 sampling frequency to 400 Hz */
|
||||
odr_attr.val1 = 400;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lis2du12, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LIS2DU12\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIS2DU12_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lis2du12, &trig, lis2du12_trigger_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int led_pattern_out(void)
|
||||
{
|
||||
const struct gpio_dt_spec led0_gpio = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
|
||||
@ -236,6 +270,7 @@ int main(void)
|
||||
const struct device *const lps22df = DEVICE_DT_GET_ONE(st_lps22df);
|
||||
const struct device *const lsm6dsv16x = DEVICE_DT_GET_ONE(st_lsm6dsv16x);
|
||||
const struct device *const lis2mdl = DEVICE_DT_GET_ONE(st_lis2mdl);
|
||||
const struct device *const lis2du12 = DEVICE_DT_GET_ONE(st_lis2du12);
|
||||
|
||||
if (!device_is_ready(hts221)) {
|
||||
printk("%s: device not ready.\n", hts221->name);
|
||||
@ -253,7 +288,12 @@ int main(void)
|
||||
printk("%s: device not ready.\n", lis2mdl->name);
|
||||
return 0;
|
||||
}
|
||||
if (!device_is_ready(lis2du12)) {
|
||||
printk("%s: device not ready.\n", lis2du12->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lis2du12_config(lis2du12);
|
||||
lis2mdl_config(lis2mdl);
|
||||
lps22df_config(lps22df);
|
||||
lsm6dsv16x_config(lsm6dsv16x);
|
||||
@ -264,6 +304,7 @@ int main(void)
|
||||
struct sensor_value lsm6dsv16x_accel[3], lsm6dsv16x_gyro[3];
|
||||
struct sensor_value lis2mdl_magn[3];
|
||||
struct sensor_value lis2mdl_temp;
|
||||
struct sensor_value lis2du12_accel[3];
|
||||
|
||||
/* handle HTS221 sensor */
|
||||
if (sensor_sample_fetch(hts221) < 0) {
|
||||
@ -292,6 +333,13 @@ int main(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIS2DU12_TRIGGER
|
||||
if (sensor_sample_fetch(lis2du12) < 0) {
|
||||
printf("LIS2DU12 xl Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
sensor_channel_get(hts221, SENSOR_CHAN_HUMIDITY, &hts221_hum);
|
||||
sensor_channel_get(hts221, SENSOR_CHAN_AMBIENT_TEMP, &hts221_temp);
|
||||
sensor_channel_get(lps22df, SENSOR_CHAN_AMBIENT_TEMP, &lps22df_temp);
|
||||
@ -300,6 +348,7 @@ int main(void)
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ, lsm6dsv16x_gyro);
|
||||
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_XYZ, lis2mdl_magn);
|
||||
sensor_channel_get(lis2mdl, SENSOR_CHAN_DIE_TEMP, &lis2mdl_temp);
|
||||
sensor_channel_get(lis2du12, SENSOR_CHAN_ACCEL_XYZ, lis2du12_accel);
|
||||
|
||||
/* Display sensor data */
|
||||
|
||||
@ -343,6 +392,11 @@ int main(void)
|
||||
printf("LIS2MDL: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lis2mdl_temp));
|
||||
|
||||
printf("LIS2DU12: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lis2du12_accel[0]),
|
||||
sensor_value_to_double(&lis2du12_accel[1]),
|
||||
sensor_value_to_double(&lis2du12_accel[2]));
|
||||
|
||||
#ifdef CONFIG_LPS2XDF_TRIGGER
|
||||
printk("%d:: lps22df trig %d\n", cnt, lps22df_trig_cnt);
|
||||
#endif
|
||||
@ -356,6 +410,10 @@ int main(void)
|
||||
printk("%d:: lis2mdl trig %d\n", cnt, lis2mdl_trig_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2DU12_TRIGGER
|
||||
printk("%d:: lis2du12 trig %d\n", cnt, lis2du12_trig_cnt);
|
||||
#endif
|
||||
|
||||
k_sleep(K_MSEC(2000));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user