Detect car crash G force with accelerometer
I know how to wake on accelerometer interrupt when sleeping but is it possible to detect a car crash or hard brake while a program is running? I assume that it would have to run in a separate thread (if that is even possible).
@shaunix just compute the magnitude of the vector...
@jcaron I'd like the value so I can assess how severe the force was before deciding how to act/report. Hard brake or collision for example.
This code spits out (x,y,z):
def acceleration(self): x = self.i2c.readfrom_mem(ACC_I2CADDR , ACC_X_L_REG, 2) self.x = struct.unpack('<h', x) y = self.i2c.readfrom_mem(ACC_I2CADDR , ACC_Y_L_REG, 2) self.y = struct.unpack('<h', y) z = self.i2c.readfrom_mem(ACC_I2CADDR , ACC_Z_L_REG, 2) self.z = struct.unpack('<h', z) _mult = self.SCALES[self.full_scale] / ACC_G_DIV return (self.x * _mult, self.y * _mult, self.z * _mult)
So I think I need to use a formula to calculate the g force from these values. I think
@shaunix do you actually need to get the value, or do you just need to be sure it exceeds the given threshold?
Have you read the accelerometer’s data sheet? It’s the best source of information on the subject, though it has a few errors IIRC.
@jcaron So I managed to trigger the event but now I need to figure out how to return the G value. I'm using the LIS2HH12.py library found in the examples. acceleration() returns (x,y,z) and now I have to figure out how to get the G force. It is not clear to me how the G threshold that is passed is compared to the actual G force generated. I assume there is a calc in there somewhere but it is not obvious to me.
That makes sense. Thanks for pointing me in the right direction.
@shaunix You can probably just set up the accelerometer the same way as for wake up, and add a trigger on the pin going high.
It should be much more efficient than constantly reading from the accelerometer just to detect if it goes over a threshold.