Read Accelerometer Sensor


  • Accelerometer


  • Android smartphone - example does not run on the emulator

import android import time droid = android.Android() dt = 100 #100ms between sensings endTime = 3000 #sample for 3000ms timeSensed=0 droid.startSensingTimed(2,dt) while timeSensed <= endTime: print droid.sensorsReadAccelerometer().result time.sleep(dt/1000.0) timeSensed+=dt droid.stopSensing()

Code Explained


startSensingTimed(Integer sensorNumber: 1 = All, 2 = Accelerometer, 3 = Magnetometer and 4 = Light,
Integer delayTime: Minimum time between readings in milliseconds)
Starts recording sensor data to be available for polling. Generates "sensors" events.

print droid.sensorsReadAccelerometer().result

Returns the most recently received accelerometer values as a List of Floats [(acceleration on the) X axis, Y axis, Z axis].

Scan the script to your smartphone using the Test EMANT380 app or download to PC/Emulator