Sunday, January 30, 2011

Difference between Android's and iPhone's Accelerometer

Today I was playing with Android's accelerometer. I am in the process of closing cocos2d-x's issue 242.

Basically I finish coding my first approach but when I run it with the test case the ball went exactly to the opposite side.
I started checking if I was sending the parameters correctly and unfortunately I was doing the right thing :(.

Since the test case was done for an iphone device I checked if the iphone used the same coordinates as Android.

I found two useful links to read about both's accelerometer:
* iphone-tutorial-reading-the-accelerometer
* SensorEvent's doc

If you check the following screens you will notice what I am talking about:

Not completely sure of what was going on I downloaded a demo app to check it gave the same values as my code. We both were sending the same coordinates so there was something different between iphone's and Android's accelerometers.

I ended up download an iphone demo app to check what were the values read. You can see the different outputs with both devices placed in the same position:

Notice the difference in the z axis value.
To fix it, it was just a matter of multiplying by -1 every value from Android's accelerometer.


  1. Perdon por el Off TOpic, pero no encontre otra forma de comunicarme

    El Martes fui invitado a un evento organizado por GTUG Buenos Aires ( )en las oficinas de Google Argentina en Puerto Madero, y quiero publicar una cobertura del mismo (El 50% se hablo de Android)

    Te consulto, porque GTUG (Google Technology User Group) es otra comunidad, y quiero hacer una invitacion para Abril que se viene el primer Bootcamp Android

  2. Dale, no hay drama, mi mail es: macarse en gmal dot com.