Raspberry Pi and MMA7455 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

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
Selectable Sensitivity (±2g, ±4g, ±8g) for 8-bit Mode

The MMA7455 accelerometer is a sensor that can measure acceleration in three axes. This sensor is commonly available as a breakout board.

It requires VCC, GND , SCA and SCL to be connected.

 

Schematic/Layout

mma7455-accelerometer-sensor-module

Vcc – Raspberry Pi 3.3v
Gnd – Raspberry Pi Gnd
SDA – Raspberry Pi Pin 3 (SDA1)
SCL – Raspberry Pi Pin 5 (SCL1)

Code

Save this as MMA7455.py

import smbus
import time
 
bus = smbus.SMBus(1)
 
# MMA7455L address, 0x1D
bus.write_byte_data(0x1D, 0x16, 0x01)
 
time.sleep(0.5)
 
# Read 6 bytes data back from 0x00
data=bus.read_i2c_block_data(0x1D, 0x00, 6)
 
# Convert the data to 10-bits
xAcc = (data[1] & 0x03) * 256 + data [0]
if xAcc > 511 :
	xAcc -= 1024
yAcc = (data[3] & 0x03) * 256 + data [2]
if yAcc > 511 :
	yAcc -= 1024
zAcc = (data[5] & 0x03) * 256 + data [4]
if zAcc > 511 :
	zAcc -= 1024
 
# Output data
print "Acceleration in X-Axis : %d" %xAcc
print "Acceleration in Y-Axis : %d" %yAcc
print "Acceleration in Z-Axis : %d" %zAcc

 

Testing

Run this from the command line – sudo python MMA7455.py

mma7455-output

 

Links

 

MMA7455 Accelerometer Sensor Module