voorloopnul

About Me

My name is Ricardo Pascal, I'm a developer and sysadmin who lives in Florianopolis/Brazil. I enjoy work with projects related to Linux, Python, Science, Web, Django and Network.

g+ "I've seen countless science fiction movies and documentaries about the future of humanity. Nothing ... | it's a fun hobby | Matéria bacana que aponta floripa como a melhor capital para se empreender no brasil. | Axado está com vaga aberta para desenvolvedor Python & Django. | | A common use of web applications has been serving files, django is capable of that, but is usually not... | A common use of web applications has been serving files, django is capable of that, but is usually not... | For the first time since I became a Ubuntu user, I'm considering not update my system to a new release... | Now try arguing with these people.... #climatechange   #climatechangeisreal   #climatechangedenial ... | | VAGA PARA DESENVOLVEDOR BACK-END PYTHON Requisitos: • Mínimo de 1 ano de experiência profissional com... | A lot of great services free of charges if you are a student! | Oportunidade para programador python  na Gymglish de Florianopolis. "We document our code, unit test... | | https://micropython.org/store/ is open and accepting pre-orders!  | Venha trabalhar na Neoprospecta como pesquisador RHAE/CNPq. A Neoprospecta ainda possui uma vaga aberta... | Faking like a pro | "Since the virtual size of the cp process was now more than 17 GB and the server only had 10 GB of RAM... | now you can edit your requirements and remove south :)  | |

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;

Considerations

  • The data is really noisy, if you put the phone on a table and play drum with your fingers, the graph will gone wild. So it's a good idea filter it to avoid trouble in a real application.

  • The "buffers" vars is a little hack to plot the data, I think it's not really necessary, but since my knowledge about maplotlib is spartan, I was not able to avoid that.


by Ricardo Pascal on Oct 25, 2012

comments powered by Disqus