Blog

I had two previous posts on accessing the accelerometer and gyroscope data on mobile devices via JavaScript. Part I mentions how to access them, and Part II is about the differences between devices.

With these learnings I put together a JavaScript file. By default it returns (almost) the same values for different devices. So you can program your logic on top of it and do not worry about these differences.

It can be found on GitHub https://github.com/dorukeker/gyronorm.js 

This is the second part of a two-part-post. Part I was about how to access the gyroscope and accelerometer data on mobile devices via JavaScript. This part will focus on the differences between devices and browsers. If you are not comfortable with the basics I suggest you take a look at Part I. To start with, here is a little video of two different devices (iPhone 5 and HTC One). You can see the first alpha value and the gravitation related values are initially different between devices. Using JavaScript you can make them return the same values in every device. This way a more uniform experience can be provided.
Please note that these JavaScript events are fairly new standards. So the implementation across devices and browsers are different. Therefore they provide different values. I can imagine in a couple of years all devices and mobile browsers will implement the standard as they should. But for now it is useful to know what to expect and how to deal with them.

This is the first part of two-part-post. Here I will discuss how we can access the gyroscope and accelerometer data on mobile devices via JavaScript. In Part II I will focus on the differences between devices/browsers and how I deal with them. If you are already familiar with the basics feel free to jump to Part II

In the modern browsers on mobile devices and laptops you can access the gyroscope and accelerometer data using JavaScript. The W3C document explains the standard very well. http://www.w3.org/TR/orientation-event/ and all through this post I am following what is mentioned in this standard.

Before you go on reading it is important to understand what are the axises of the mobile device. Below is a nice image for that.

phoneaxises