0

I would like to sample data from the x axis of an accelerometer using python, and once the movement has exceeded a threshold I want to activate an alarm.

The dilemma I have is the accelerometer is not always level, and I want to take this into consideration, so that if the accelerometer is angled and the readings thereafter are the same, no alarm will be raised.

can anybody point to a sample code

I have started the following code, but it is not complete maybebe someone can finish it

[x, y, z] = adxl345.getAxes() 
valAccel_x = x
current_x = x
if abs(current_x - old_x)>0.035:
    print ("threshold breached")
old_x = current_x
Ossama
  • 2,401
  • 7
  • 46
  • 83
  • Well if your accelerometer is angled then `x_floor != x_accel`. The new value is (assuming the floor is horizontal and the world is 2 dimensional) `x_floor = sqr(x_accel + y_accel)`. Now you only have to expand for z also. – RedX Apr 15 '14 at 12:41
  • How many axies are on the accelerometer? Do you have a way of knowing the orientation of the accelerometer? If you don't have a way of knowing the orientation of the accelerometer, and you don't have three axies of accelerometer data, what you want is likely impossible. If you do have three axies, you can do it, but it means tracking the global orientation of the accelerometer using only its acceleration data, which is complicated and not terribly accurate. – aruisdante Apr 15 '14 at 12:42
  • @RedX your math is forgetting about gravity. As soon as the accelerometer is not orthagonal to the ground, some of the gravity signal will be mixed into all of the axies, and you have to figure out how to compensate for it (by knowing the orientation of the device) – aruisdante Apr 15 '14 at 12:47
  • I do have a three axis accelerometer, that i am using to track sleep of infant in bed. i only need a simply way to detect movement, in my code above i plan to duplicate the code for theother 2 axis, any simply way? – Ossama Apr 16 '14 at 10:24

0 Answers0