Program :
#Bibliothèque
import time
from Adafruit_I2C import Adafruit_I2C
import struct
from math import *
# Registers
OUT_X_MSB = 0x01
CTRL_REG1 = 0x2A
XYZ_DATA_CFG = 0x0E
i2c = Adafruit_I2C(0x1c) # Adresse accéléromètre
# Setups for calculation with configuration 2g
gPerCount = 2.0 /128
#Recovery of data from the accelerometer
(status,x,y,z) = i2c.readList(OUT_X_MSB,4)
# Formatting for calculation
bytes = struct.pack('BBB', x, y, z)
x, y, z = struct.unpack('bbb', bytes)
# Calculation of the acceleration per axis as a function of the accelerometer parametrage
x *= gPerCount
y *= gPerCount
z *= gPerCount
while 1 :
print ‘x’
print ‘y’
print ‘z’
delay(1)
For all the wiring is correct. SDA on SDA, SCL on SCL, 3v3 on 3v3, GND on GND and SAO on GND.
I use python language.
In the datasheet, in page 13, part 5.6, for the freefall refer to datasheet AN4070.
In page 6, part 4.1.2 : Configuring the MMA8451... for freefall. I don't understand this part.
Datasheet 1 :
http://cache.nxp.com/files/sensors/doc/ ... A8451Q.pdf
Datasheet 2 :
http://cache.freescale.com/files/sensor ... AN4070.pdf