An accelerometer is an electromechanical device used to measure acceleration forces. IoTaaP has onboard accelerometer KXTC9-2050-FR.

Onboard accelerometer is ± 2g tri-axis analog accelerometer, which means that we are using ADC to get analog readings from the accelerometer.

Onboard accelerometer is good enough for even complex acceleration measurements, but it can also work as an orientation sensor (just like in your mobile phone). In this code IoTaaP will read accelerometer data and then display X, Y, Z axis values on the OLED.

#include "IoTaaP.h"

IoTaaP iotaap;

void setup()

void loop()
  // Read accelerometer values
  accelerometer acc = iotaap.accelerometer.getRaw();
  // Display accelerometer values
  iotaap.oled.showText("X: " + String(acc.x) + "\nY: " + String(acc.y) + "\nZ: " + String(acc.z));

IoTaaP has it’s own data structure for the accelerometer data which contains values of the X, Y and Z axis.

accelerometer structure looks like this:

struct accelerometer
    uint16_t x;
    uint16_t y;
    uint16_t z;

Using the following line IoTaaP will read RAW values from the accelerometer and save them into the acc variable.

accelerometer acc = iotaap.accelerometer.getRaw();

Accessing the values of the acc variable is really simple and we are doing this in the following line:

iotaap.oled.showText("X: " + String(acc.x) + "\nY: " + String(acc.y) + "\nZ: " + String(acc.z));

Try to create a function that will convert RAW values into an appropriate angle (Radians or Degrees), post your solutions to our community page.