Accelerometer

Periodically read and display accelerometer sensor data on a ZentriOS terminal.

API Features Demonstrated

Platforms

This app works on:

Requirements and Prerequisites

This app requires a ZentriOS device, such as an AMW106 Moray evaluation board, connected to an ST LIS3DH three axes linear accelerometer, such as supplied with the ASG001 Zentri Backpack.

Description

Periodically read and display accelerometer sensor data on a ZentriOS terminal.

Usage Instructions

Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.

Build, download and run the app. It displays a message similar to the following on the ZentriOS terminal:

Starting Accelerometer App
Initialisation successful!
Getting data....
X: -56mG
Y: 859mG
Z: 562mG
Getting data....
X: -51mG
Y: 867mG
Z: 532mG
Getting data....
X: -54mG
Y: 863mG
Z: 555mG
Getting data....
X: -57mG
Y: 860mG
Z: 530mG

where X/Y/Z values reflect periodic sensor readings in the three-dimensional X, Y and Z-axes respectively.

Implementation

zn_app_init()

The call to sensor_init configures the sensor.

The call to zn_event_register_periodic registers the periodic event read_accel_data.

read_accel_data()

The call to sensor_has_new_data determines whether new data is ready.

If data is available, sensor_get_data reads the data. The data is formatted and logged to the ZentriOS terminal.

Source

See: