printf("Waiting for triggers\n");
while (true)
{
k_sleep(K_MSEC(2000));
}
There is no magic in that. It sleeps for 2s in a endless loop. It just prevents the app from exit.
The magic for the accelerometer is in
rc = sensor_trigger_set(sensor, &trig, trigger_handler);
that registers an callback trigger_handler
, which is then called, when the LIS2DH reports an event via the IO pins and these pins are configured for that interrupt. When that callback is executed, it calls
static void trigger_handler(const struct device *dev,
const struct sensor_trigger *trig)
{
fetch_and_display(dev);
}
and that display then the values.
if (rc < 0)
{
printf("ERROR: Update failed: %d\n", rc);
}
else
{
printf("#%u @ %u ms: %sx %f , y %f , z %f\n",
count, k_uptime_get_32(), overrun,
sensor_value_to_double(&accel[0]),
sensor_value_to_double(&accel[1]),
sensor_value_to_double(&accel[2]));
}
at the end of fetch_and_display
should then print at least an error.
Otherwise, I would guess, either the interrupt isn’t configured well (e.g. nRF9160 pin 29 for data ready, but nRF9160 pin 30 wired to LIS2DH int1 which is then the default event for that “data_ready”), or some other issue with the configuration prevents the callback from being called, e.g.
CONFIG_LIS2DH_TRIGGER_NONE=y
instead of
CONFIG_LIS2DH_TRIGGER_GLOBAL_THREAD=y
A very first shot, it may work or not, would be to use exchanged pins in the overlay, e.g. instead of
iq-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>, <&gpio0 30 GPIO_ACTIVE_HIGH>;
iq-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>, <&gpio0 29 GPIO_ACTIVE_HIGH>;