Page 1 of 1

Free fall with accelerometer (freescale MMA845x)

Posted: Thu Mar 03, 2016 2:00 pm
by 3v3IB
Hello everyone ! I am french student an Biomedical engineering.
I currently have an electronic project. I have to detect a fall with accelerometer (MMA845x).
I can get the values of x, y and z with my programming in python.
I do not know how to detect a fall with this information?
The sensor is placed on a waistband. Then I have to differentiate a fall, a person walking, which is standing, who is sleeping etc ..

Thank you.
I'm sorry for my english.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Thu Mar 03, 2016 9:24 pm
by TheRayTracer
Great project. Are you using a RPi? I would look into Machine Learning to classify a "Fall" from a lot of training data. This topic has nothing to do with RPi.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Thu Mar 03, 2016 9:42 pm
by 3v3IB
Yes, I use a raspberry Pi in my project.
I research how to program with RPi to detect a fall with my accelerometer

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Thu Mar 03, 2016 10:21 pm
by TheRayTracer
The MMA845x device has a free fall interrupt that you can use. Look up the datasheet and "Freefall and Motion Detection" section.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Fri Mar 04, 2016 7:30 am
by 3v3IB
Yes, of course but when I read the datasheet , I do not understand! I have an acceleration of 2g, but never my values ​​are all 0.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Fri Mar 04, 2016 8:25 am
by TheRayTracer
Please post what you have attempted. Do you have a wiring diagram? What part of the datasheet do you not understand?
I can get the values of x, y and z with my programming in python.
I have an acceleration of 2g, but never my values ​​are all 0.
:roll:

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Fri Mar 04, 2016 1:00 pm
by 3v3IB
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

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Fri Mar 04, 2016 8:21 pm
by TheRayTracer
The device, like most devices, requires setup steps to get the device into the right mode. Where have you set the range?

I would suggest starting to read the device ID to ensure that everything is working and ok.

See: 0x0D: WHO_AM_I Device ID Register in the datasheet. Then slowly build up your functionality.

Also note, that this device has a strange repeated-start-condition: http://www.i2c-bus.org/repeated-start-condition/

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Sun Mar 06, 2016 9:20 pm
by TheRayTracer
Section 4 of the datasheet outlines the setup registers for free fall configuration. I would also highly recommend that you read section 5 and configure a interrupt when free fall is detected. When using an interrupt you will not need any loop logic, and you can just wait for the interrupt pin to go active.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Wed Mar 16, 2016 4:23 pm
by 3v3IB
Hello ! my program still does not work with the code provided in the documentation. Help me
thanks
#!/usr/bin/python
# -*- coding: utf-8 -*-


import time
from Adafruit_I2C import Adafruit_I2C
CTRL_REG1_Data = 0x2A

i2c = Adafruit_I2C(0x1c)
i2c.write8(0x2A, 0x20)
i2c.write8(0x15, 0xD8)
i2c.write8(0x17, 0x03)
i2c.write8(0x18, 0x06)
i2c.write8(0x2D, 0x04)
i2c.write8(0x2E, 0x00)
CTRL_REG1_Data =i2c.readS8(0x2A)
CTRL_REG1_Data = 0x01
i2c.write8(CTRL_REG1_Data,1)

while 1:
intSourceSystem=i2c.readS8(0x0c)
if ((intSourceSystem&0x04) ==0x04):
intSourceSystem == i2c.readS8(0x16)
print "CHUTE !!!!!"
time.sleep(0.1)

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Wed Mar 16, 2016 5:16 pm
by toxibunny
I don't think any preset 'free fall' detection will help in OP's case, unless the person falls out of a window, or off a bridge...

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Wed Mar 16, 2016 9:40 pm
by TheRayTracer
I would suggest starting to read the device ID to ensure that everything is working and ok.

See: 0x0D: WHO_AM_I Device ID Register in the datasheet. Then slowly build up your functionality.
Please reread this. You are just diving in and excepting it to work. What value do you receive when you read the 0x0D register?

This is the first thing you need to do before moving on.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Wed Mar 16, 2016 9:49 pm
by TheRayTracer
With an interrupt setup you don't need your loop logic.

When your interrupt pin goes active, just open your parachute. This will be much more reliable. It could be deadly if your interrupt goes active while your RPi is sleeping for 0.1 seconds inside your loop. That's about a full 1 meter of free fall time from a standing start.

Where is INT1 or INT2 connected in your wiring?

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Wed Mar 16, 2016 10:35 pm
by 3v3IB
I dont how do in python to read the interruption ! I connected to a GPIO but I do not know how to read it !
for the answer on the register 0d , I'll look
thank you

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Wed Mar 16, 2016 10:55 pm
by TheRayTracer
Let's start at the beginning. How have you wired up the device to your RPi? Device Vcc to pin 1 (3V), Device Gnd to pin 6? Device I2C to pins 3 and 5? Device INT 1 and 2 to which GPIO pins?
I dont how do in python to read the interruption
You are missing the understanding of using interrupts. Please see: https://en.wikipedia.org/wiki/Interrupt
...an interrupt is a signal to the processor emitted by hardware ... indicating an event that needs immediate attention.
I know I don't have a full understanding of your project and it's goal, plus a language barrier, but it seems like you want to trigger an action when free fall is detected, for example, open a parachute. Is this correct? If this is the case, just connect INT1 or INT2 to the firing pin to deploy the parachute. This way, you only need (Python) code to setup the device, and not to "detect" an interrupt.

Re: Free fall with accelerometer (freescale MMA845x)

Posted: Thu Mar 17, 2016 8:46 pm
by toxibunny
Op wants to be able to tell if a person wearing a device on their waist, has fallen over, or if they're sitting or lying down or whatever. 'free fall' will only ever come into it if they're pushed out of a window, or they fall off a bridge, or they go bungee jumping or whatever... Presumably this is a cameraless system for making sure elderly people can get medical help quickly in case of an accident/fall/whatever without them feeling like their privacy is being invaded.

I like the idea of attaching parachutes to old people 'just in case', though. Feel free to explore this avenue...