This is my code:
import time
import Adafruit_GPIO.I2C as Adafruit_I2C
import struct
from math import *
# Registers
OUT_X_MSB = 0x01
CTRL_REG1 = 0x2A
XYZ_DATA_CFG = 0x0E
i2c = Adafruit_I2C.Device(0x1c, 1) # Adresse accéléromètre
# Setups for calculation with configuration 2g
gPerCount = 2.0 /128
while True:
#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
print (x)
print (y)
print (z)
time.sleep(1)
And the output is this:
-1.4375
1.4375
1.0625
-1.4375
1.4375
1.0625
-1.4375
1.4375
1.0625
-1.4375
1.4375
1.0625
-1.4375
1.4375
1.0625
-1.4375
1.4375
1.0625
I Have checked the wiring and everything and for the life of me I cannot tell what the problem is.