Uncategorized

Viewed 13 times

MMA845X Accelerometer outputs the same values constantly

This is my code:

``````import time
import struct
from math import *

# Registers
OUT_X_MSB = 0x01
CTRL_REG1 = 0x2A
XYZ_DATA_CFG = 0x0E

# Setups for calculation with configuration 2g
gPerCount = 2.0 /128

while True:
#Recovery of data from the accelerometer

# 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.

New contributor
• Why are you packing/unpacking x, y, and z. Could you just print status, x, y, z as received. – joan 2 hours ago
• Could this be detecting gravity? I don’t know what position you chip is. Does it give the same numbers if you turn it? – NomadMaker 1 hour ago
• Ah, let me see. (1) Your final output is always “-1.4375, 1.4375.1.0625”, to 4 decimal places. This implies the 2’s complement raw figures always the same. So there is no need to do any calculation to convert the raw 2’s complement numbers. Your code before converting raw data is in two big steps: (1) Config, (2) Read raw data. We can first look at the config/setup part, in your case is only one statement “gPerCount = 2.0 /128”. One thing is check out is to config yourself, usually in two or three steps: (a) Set g range, (b) Set interrupt config, (c) start measurement mode. / to continue, … – tlfong01 38 mins ago
• We need to read the friendly datasheet to see the config procedure: (1) MMA8451Q 3-Axis, 14-bit/8-bit Digital Accelerometer Datasheet Document Number: MMA8451Q Rev. 10.3, 02/2017- NXP/ nxp.com/docs/en/data-sheet/MMA8451Q.pdf, … / to continue, … – tlfong01 37 mins ago
• To troubleshoot, usually I start reading the application notes: penzu.com/public/f38b4cd1 – tlfong01 24 mins ago
• I think we better start with the app note written by the app enggr: App Note AN4076 Data Manipulation and Basic Settings of the MMA8451/2/3Q by: Kimberly Tuck Applications Engineer bdtic.com/download/nxp/AN4076.pdf – tlfong01 20 mins ago
• I skimmed the app note, and found the following sections useful: Sections 3, Standby and active mode (with code examples) , 7. Convert 2’complement to signed decimal, 9. Polling vs interrupt. One possible reason of your always getting the same data is BECAUSE YOU ARE IN STANDBY MODE, therefore always reading the old, never changing data.. – tlfong01 12 mins ago
• Section 3 tells you how to set the active mode: Section 3.0 … The device changes from Standby to Active Mode via bit 0 in register 0x2A, with demo code:. /* ** Set the Active bit in CTRL Reg 1 */ IIC_RegWrite(CTRL_REG1, (IIC_RegRead(CTRL_REG1) | ACTIVE_MASK)); So you might like to try your luck. Warning: I have never seen or played with your accelero module. I am just reading the friendly datasheet and app notes. No guarantee nothing won’t melt down nor blow up. Good luck and cheers! 🙂 – tlfong01 3 mins ago    Edit

Categories: Uncategorized

This site uses Akismet to reduce spam. Learn how your comment data is processed.