Arduino and the micro:bit onboard 3-axis accelerometer

The MMA8653FC is an intelligent, low-power, three-axis, capacitive micromachined accelerometer with 10 bits of resolution. This accelerometer is packed with embedded functions with flexible user-programmable options, configurable to two interrupt pins. Embedded interrupt functions enable overall power savings, by relieving the host processor from continuously polling data. There is access to
either low-pass or high-pass filtered data, which minimizes the data analysis required for jolt detection and faster transitions. The device can be configured to generate inertial wake-up interrupt signals from any combination of the configurable embedded functions, enabling the MMA8653FC to monitor inertial events while remaining in a low-power mode during periods of inactivity. The MMA8653FC is available in a small 10-pin DFN package (2 mm x 2 mm x 1 mm).

Features
• 1.95 V to 3.6 V supply voltage
• 1.62 V to 3.6 V digital interface voltage
• ±2 g, ±4 g, and ±8 g dynamically selectable full-scale ranges
• Output Data Rates (ODR) from 1.56 Hz to 800 Hz
• 10-bit digital output
• I2C digital output interface with programmable interrupts
• One embedded channel of configurable motion detection (Freefall)
• Orientation (Portrait/Landscape) detection with fixed hysteresis of 15°.
• Configurable automatic ODR change triggered by the Auto-Wake/Sleep state change
• Self-Test

Typical applications
• Tilt compensation in e-compass applications
• Static orientation detection (Portrait/Landscape, Up/Down, Left/Right, Back/ Front position identification)
• Notebook, tablet, e-reader, and laptop tumble and freefall detection
• Real-time orientation detection (virtual reality and gaming 3D user orientation feedback)
• Real-time activity analysis (pedometer step counting, freefall drop detection for HDD, dead-reckoning GPS backup)
• Motion detection for portable product power saving (Auto-SLEEP and Auto-WAKE for cell phone, PDA, GPS, gaming)
• Shock and vibration monitoring (mechatronic compensation, shipping and warranty usage logging)
• User interface (tilt menu scrolling)

Code

You need to the https://github.com/hidnseek/hidnseek/tree/master/arduino/libraries/MMA8653

#include "Wire.h"
#include "MMA8653.h"
 
MMA8653 accel;
 
void setup() 
{
  Serial.begin(9600);
  accel.begin(false, 2); // 8-bit mode, 2g range
}
 
 
void loop() 
{
  accel.update();
  Serial.print((float)accel.getX() * 0.0156);    
  Serial.print(" , ");
  Serial.print((float)accel.getY() * 0.0156);    
  Serial.print(", ");
  Serial.println((float)accel.getZ() * 0.0156);
  delay(250);
}

 

Output

Open the serial monitor and move the micro:bit – the values are in g’s

0.66 , -0.06, 0.69
0.22 , -0.19, 1.25
0.09 , 0.50, -0.50
-0.36 , 0.67, -0.20
0.86 , -0.17, 0.37
0.17 , 0.12, -1.03
0.23 , -0.31, -1.37
0.64 , 1.51, 1.03
0.94 , -0.39, -1.64
0.31 , 0.33, -0.27
-0.42 , 0.56, 0.28
-0.94 , 0.25, -0.45
-0.19 , 0.05, -0.83
-1.12 , -0.12, -0.14
-0.48 , 0.19, -0.59
-0.45 , 0.28, 0.23