Oct. 25, 2012, midnight

Real-time plotting of android accelerometer data

What is a accelerometer?

It's a device aimed to measure acceleration. Usually it works analyzing the gravity force against a suspended mass. Or in the case of our smartphone, it analyze what is called seismic mass. Further explanation about accelerometers can be get here and here.

What are the uses of a accelerometer?

In smartphones, the most common use is to set the screen orientation or to achieve movimentation in games. Outside the phone world, it's widely used in stabilization systems.

What I'm trying to accomplish?

The idea is to plot the accelerometer data from a smartphone(android) using python. When you run the code, you should see something like this at your computer:

Accelerometer chart

The code

The explanation

class Chart()._init_()

1) Start the count/buffers variables; 2) plt.ion() enables interactive mode, which will allow the plot to be updated in real time; 3) Create the chart figure, and define the scale of axis Y/X;

class Chart().plot()

1) Plot the data from accelerometer; 2) Draw the chart; 3) Update the buffers;

if _name_ == _main_

1) receive data from android accelerometer; 2) round to just one decimal; 3) call the plotting stuff 4) delay before the next sensing;


comments powered by Disqus