MMA7455 accelerometer and micro:bit example

The MMA7455L is a Digital Output (I2C/SPI), low power, low profile capacitive micromachined accelerometer featuring signal conditioning, a low pass filter, temperature compensation, self-test, configurable to detect 0g through interrupt pins (INT1 or INT2), and pulse detect for quick motion detection. 0g offset and sensitivity are factory set and require no external devices. The 0g offset can be customer calibrated using assigned 0g registers and g-Select which allows for command selection for 3 acceleration ranges (2g/4g/8g). The MMA7455L includes a Standby Mode that makes it ideal for handheld battery powered electronics.

 

Features
• Digital Output (I2C/SPI)
• 3mm x 5mm x 1mm LGA-14 Package
• Self-Test for Z-Axis
• Low Voltage Operation: 2.4 V – 3.6 V
• User Assigned Registers for Offset Calibration
• Programmable Threshold Interrupt Output
• Level Detection for Motion Recognition (Shock, Vibration, Freefall)
• Pulse Detection for Single or Double Pulse Recognition
• Sensitivity (64 LSB/g @ 2g and @ 8g in 10-Bit Mode)
• Selectable Sensitivity (±2g, ±4g, ±8g) for 8-bit Mode
• Robust Design, High Shocks Survivability (5,000g)
• RoHS Compliant
• Environmentally Preferred Product
• Low Cost

 

Layout

 

Code

 

// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// MMA7455
// This code is designed to work with the MMA7455_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Accelorometer?sku=MMA7455_I2CS#tabs-0-product_tabset-2
 
#include<Wire.h>
 
// MMA7455 I2C address is 0x1D(29)
#define Addr 0x1D
 
void setup()
{
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise Serial Communication, set baud rate = 9600
Serial.begin(9600);
 
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select Mode control register
Wire.write(0x16);
// Measurement mode, +/- 8g
Wire.write(0x01);
// Stop I2C Transmission
Wire.endTransmission();
delay(300);
}
 
void loop()
{
unsigned int data[6];
 
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write((byte)0x00);
// Stop I2C Transmission
Wire.endTransmission();
 
// Request 6 bytes
Wire.requestFrom(Addr, 6);
 
// Read 6 bytes of data
// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb
if(Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read(); 
data[4] = Wire.read();
data[5] = Wire.read(); 
}
 
// Convert the data to 10-bits
int xAccl = (((data[1] & 0x03) * 256) + data[0]);
if (xAccl > 511)
{ 
xAccl -= 1024;
}
 
int yAccl = (((data[2] & 0x03)* 256) + data[2]);
if (yAccl > 511)
{
yAccl -= 1024;
}
 
int zAccl = (((data[5] & 0x03) * 256) + data[4]);
if (zAccl > 511)
{ 
zAccl -= 1024;
}
 
// Output data to serial monitor
Serial.print(" Acceleration in X-Axis is : ");
Serial.println(xAccl); 
Serial.print(" Acceleration in Y-Axis is : ");
Serial.println(yAccl); 
Serial.print(" Acceleration in Z-Axis is : ");
Serial.println(zAccl); 
delay(500); 
}

 

 

Output

Open the serial monitor window

Acceleration in X-Axis is : 256
Acceleration in Y-Axis is : 164
Acceleration in Z-Axis is : 0
Acceleration in X-Axis is : 0
Acceleration in Y-Axis is : 144
Acceleration in Z-Axis is : 20
Acceleration in X-Axis is : 256
Acceleration in Y-Axis is : 204
Acceleration in Z-Axis is : -296

 

Link

Freescal MMA7455 Three Axis Digital Tilt Sensor Acceleration Module,Multi-copter

micro:bit and MMA7361 accelerometer example

The MMA7361L is a low power, low profile capacitive micromachined accelerometer featuring signal conditioning, a 1-pole low pass filter, temperature compensation, self test, 0g-Detect which detects linear freefall, and g-Select which allows for the selection between 2 sensitivities. Zero-g offset and sensitivity are factory set and require no external devices. The MMA7361L includes a Sleep Mode that makes it ideal for handheld battery powered electronics.

Features
• 3mm x 5mm x 1.0mm LGA-14 Package
• Low Current Consumption: 400 μA
• Sleep Mode: 3 μA
• Low Voltage Operation: 2.2 V – 3.6 V
• High Sensitivity (800 mV/g @ 1.5g)
• Selectable Sensitivity (±1.5g, ±6g)
• Fast Turn On Time (0.5 ms Enable Response Time)
• Self Test for Freefall Detect Diagnosis
• 0g-Detect for Freefall Protection
• Signal Conditioning with Low Pass Filter
• Robust Design, High Shocks Survivability
• RoHS Compliant
• Environmentally Preferred Product
• Low Cost

Typical Applications
• 3D Gaming: Tilt and Motion Sensing, Event Recorder
• HDD MP3 Player: Freefall Detection
• Laptop PC: Freefall Detection, Anti-Theft
• Cell Phone: Image Stability, Text Scroll, Motion Dialing, E-Compass
• Pedometer: Motion Sensing
• PDA: Text Scroll
• Navigation and Dead Reckoning: E-Compass Tilt Compensation
• Robotics: Motion Sensing

Schematic and connection

 

microbit and mma7361

microbit and mma7361

 

Code

 

void setup() 
{ 
  Serial.begin(9600); // 9600 bps
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
}
 
void loop() 
{
  int x,y,z;
  x=analogRead(0);
  y=analogRead(1);
  z=analogRead(2);
  Serial.print("x= ");
  Serial.print(x ,DEC);
  Serial.print(',');
  Serial.print("y= ");
  Serial.print(y ,DEC);
  Serial.print(',');
  Serial.print("z= ");
  Serial.println(z ,DEC);
  delay(250);
}

 

Output

Open the serial monitor and move the sensor around, you should see soemthing like this

X = 86
Y = 82
Z = 656
X = 68
Y = 80
Z = 640
X = 76
Y = 80
Z = 657
X = 422
Y = 96
Z = 653
X = 354
Y = 80
Z = 656
X = 1573
Y = 216
Z = 857

 

Links

http://www.nxp.com/files/sensors/doc/data_sheet/MMA7361L.pdf

MMA7361 Angle Sensor Inclination Accelerometer Module For Arduino

micro:bit and MMA8451 accelerometer example

The MMA8451 is a low-power accelerometer with 14 bits of resolution, with the following features:

  • Embedded functions with flexible user-programmable options, configurable to two interrupt pins
  • Embedded interrupt functions for overall power savings relieving the host processor from continuously polling data
  • Access to both low-pass filtered data as well as high-pass filtered data, which minimizes the data analysis required for jolt detection and faster transitions
  • Inertial wake-up interrupt signals from any combination of the configurable embedded functions allowing the MMA8451Q to monitor events and remain in a low-power mode during periods of inactivity

Features

  • 1.95 to 3.6-volt supply voltage
  • 1.6 to 3.6-volt interface voltage
  • ±2g/±4g/±8g dynamically selectable full-scale
  • Output data rates (ODR) from 1.56 Hz to 800 Hz
  • 99 μg/√Hz noise
  • 14-bit and 8-bit digital output
  • I²C digital output interface (operates to 2.25 MHz with 4.7 kΩ pull-up)
  • Two programmable interrupt pins for seven interrupt sources
  • Three embedded channels of motion detection
    • Freefall or motion detection: one channel
    • Pulse detection: one channel
    • Jolt detection: one channel
  • Orientation (portrait/landscape) detection with programmable hysteresis
  • Automatic ODR change for auto-wake and return to sleep
  • 32 sample FIFO
  • High pass filter data available per sample and through the FIFO
  • Self-test

Again due to the size and package of the module its easier to buy a module, here is one that I purchased. All you need to do is solder on the header and then connect using wires from your module to your Wemos Mini, wiring connections later

 

 

Connection

I used the following connection from the module above to my Wemos Mini

micro:bit Connection Module Connection
3v3 VCC_IN
Gnd Gnd
P20 SDA
P19 SCL
microbit and mma8451

microbit and mma8451

 

Code

This requires the Adafruit library from https://github.com/adafruit/Adafruit_MMA8451_Library/archive/master.zip

I had to edit the Adafruit header file called Adafruit_MMA8451.h as my device was address 0x1c (28), I discovered this using an I2C scanner

#define MMA8451_DEFAULT_ADDRESS                 (0x1C)

#include <Wire.h>
#include "Adafruit_MMA8451.h"
#include <Adafruit_Sensor.h>
 
 
Adafruit_MMA8451 mma = Adafruit_MMA8451();
 
void setup(void) {
  Serial.begin(9600);
 
  Serial.println("Adafruit MMA8451 test!");
 
 
  if (! mma.begin()) {
    Serial.println("Couldnt start");
    while (1);
  }
  Serial.println("MMA8451 found!");
 
  mma.setRange(MMA8451_RANGE_2_G);
 
  Serial.print("Range = "); Serial.print(2 << mma.getRange());  
  Serial.println("G");
 
}
 
void loop() {
  // Read the 'raw' data in 14-bit counts
  mma.read();
  Serial.print("X:\t"); Serial.print(mma.x); 
  Serial.print("\tY:\t"); Serial.print(mma.y); 
  Serial.print("\tZ:\t"); Serial.print(mma.z); 
  Serial.println();
 
  /* Get a new sensor event */ 
  sensors_event_t event; 
  mma.getEvent(&event);
 
  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
  Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
  Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
  Serial.println("m/s^2 ");
 
  /* Get the orientation of the sensor */
  uint8_t o = mma.getOrientation();
 
  switch (o) {
    case MMA8451_PL_PUF: 
      Serial.println("Portrait Up Front");
      break;
    case MMA8451_PL_PUB: 
      Serial.println("Portrait Up Back");
      break;    
    case MMA8451_PL_PDF: 
      Serial.println("Portrait Down Front");
      break;
    case MMA8451_PL_PDB: 
      Serial.println("Portrait Down Back");
      break;
    case MMA8451_PL_LRF: 
      Serial.println("Landscape Right Front");
      break;
    case MMA8451_PL_LRB: 
      Serial.println("Landscape Right Back");
      break;
    case MMA8451_PL_LLF: 
      Serial.println("Landscape Left Front");
      break;
    case MMA8451_PL_LLB: 
      Serial.println("Landscape Left Back");
      break;
    }
  Serial.println();
  delay(500);
 
}

 

Output

Open the serial monitor

X: 4686 Y: 2748 Z: 684
X: 10.80 Y: 6.11 Z: 0.21 m/s^2
Landscape Right Front

X: 1314 Y: -3198 Z: 2014
X: 2.01 Y: -7.75 Z: 5.52 m/s^2
Portrait Up Front

X: 2194 Y: 2762 Z: -2530
X: 6.57 Y: 7.33 Z: -2.77 m/s^2
Portrait Down Back

X: 2294 Y: 3182 Z: -392
X: 3.49 Y: 2.23 Z: 0.13 m/s^2
Landscape Right Back

X: 224 Y: 1324 Z: -2844
X: -2.46 Y: 7.03 Z: -9.81 m/s^2
Portrait Down Back

 

Links

Here is a link to the module
GY-45 MMA8451 Module Digital Triaxial Accelerometer High-precision Inclination Module

micro:bit and ADXL345 accelerometer example

The ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface.

The ADXL345 is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (4 mg/LSB) enables measurement of inclination changes less than 1.0°.

Several special sensing functions are provided. Activity and inactivity sensing detect the presence or lack of motion and if the acceleration on any axis exceeds a user-set level. Tap sensing detects single and double taps. Free-fall sensing detects if the device is falling. These functions can be mapped to one of two interrupt output pins. An integrated, patent pending 32-level first in, first out (FIFO) buffer can be used to store data to minimize host processor intervention.

adxl345 module

adxl345 module

Connection and layout

 

I used the following connection from the module above to my Wemos Mini

micro:bit Connection Module Connection
3v3 VCC
Gnd Gnd
P20 SDA
P19 SCL

Here is a layout for reference

microbit and adxl345

microbit and adxl345

 

Code

This needs the Adafruit library – https://github.com/adafruit/Adafruit_ADXL345

This is just the sensor test code from the library above

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
 
/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
 
void displaySensorDetails(void)
{
 sensor_t sensor;
 accel.getSensor(&sensor);
 Serial.println("------------------------------------");
 Serial.print ("Sensor: "); Serial.println(sensor.name);
 Serial.print ("Driver Ver: "); Serial.println(sensor.version);
 Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
 Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
 Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
 Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" m/s^2"); 
 Serial.println("------------------------------------");
 Serial.println("");
 delay(500);
}
 
void displayDataRate(void)
{
 Serial.print ("Data Rate: "); 
 
 switch(accel.getDataRate())
 {
 case ADXL345_DATARATE_3200_HZ:
 Serial.print ("3200 "); 
 break;
 case ADXL345_DATARATE_1600_HZ:
 Serial.print ("1600 "); 
 break;
 case ADXL345_DATARATE_800_HZ:
 Serial.print ("800 "); 
 break;
 case ADXL345_DATARATE_400_HZ:
 Serial.print ("400 "); 
 break;
 case ADXL345_DATARATE_200_HZ:
 Serial.print ("200 "); 
 break;
 case ADXL345_DATARATE_100_HZ:
 Serial.print ("100 "); 
 break;
 case ADXL345_DATARATE_50_HZ:
 Serial.print ("50 "); 
 break;
 case ADXL345_DATARATE_25_HZ:
 Serial.print ("25 "); 
 break;
 case ADXL345_DATARATE_12_5_HZ:
 Serial.print ("12.5 "); 
 break;
 case ADXL345_DATARATE_6_25HZ:
 Serial.print ("6.25 "); 
 break;
 case ADXL345_DATARATE_3_13_HZ:
 Serial.print ("3.13 "); 
 break;
 case ADXL345_DATARATE_1_56_HZ:
 Serial.print ("1.56 "); 
 break;
 case ADXL345_DATARATE_0_78_HZ:
 Serial.print ("0.78 "); 
 break;
 case ADXL345_DATARATE_0_39_HZ:
 Serial.print ("0.39 "); 
 break;
 case ADXL345_DATARATE_0_20_HZ:
 Serial.print ("0.20 "); 
 break;
 case ADXL345_DATARATE_0_10_HZ:
 Serial.print ("0.10 "); 
 break;
 default:
 Serial.print ("???? "); 
 break;
 } 
 Serial.println(" Hz"); 
}
 
void displayRange(void)
{
 Serial.print ("Range: +/- "); 
 
 switch(accel.getRange())
 {
 case ADXL345_RANGE_16_G:
 Serial.print ("16 "); 
 break;
 case ADXL345_RANGE_8_G:
 Serial.print ("8 "); 
 break;
 case ADXL345_RANGE_4_G:
 Serial.print ("4 "); 
 break;
 case ADXL345_RANGE_2_G:
 Serial.print ("2 "); 
 break;
 default:
 Serial.print ("?? "); 
 break;
 } 
 Serial.println(" g"); 
}
 
void setup(void) 
{
 Serial.begin(9600);
 Serial.println("Accelerometer Test"); Serial.println("");
 
 /* Initialise the sensor */
 if(!accel.begin())
 {
 /* There was a problem detecting the ADXL345 ... check your connections */
 Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
 while(1);
 }
 
 /* Set the range to whatever is appropriate for your project */
 accel.setRange(ADXL345_RANGE_16_G);
 // displaySetRange(ADXL345_RANGE_8_G);
 // displaySetRange(ADXL345_RANGE_4_G);
 // displaySetRange(ADXL345_RANGE_2_G);
 
 /* Display some basic information on this sensor */
 displaySensorDetails();
 
 /* Display additional settings (outside the scope of sensor_t) */
 displayDataRate();
 displayRange();
 Serial.println("");
}
 
void loop(void) 
{
 /* Get a new sensor event */ 
 sensors_event_t event; 
 accel.getEvent(&event);
 
 /* Display the results (acceleration is measured in m/s^2) */
 Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
 Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
 Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
 delay(500);
}

 

Output

 

 

Links