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 

Here is a basic usage:

<script src="/js/gyronorm.js"></script>

    var gn = new GyroNorm();
        // Process:
        //    ( deviceorientation event alpha value )
        //     ( deviceorientation event beta value )
        //    ( deviceorientation event gamma value )
        // ( deviceorientation event absolute value )

        //        ( devicemotion event acceleration x value )
        //        ( devicemotion event acceleration y value )
        //        ( devicemotion event acceleration z value )

        //       ( devicemotion event accelerationIncludingGravity x value )
        //       ( devicemotion event accelerationIncludingGravity y value )
        //       ( devicemotion event accelerationIncludingGravity z value )

        //    ( devicemotion event rotationRate alpha value )
        //     ( devicemotion event rotationRate beta value )
        //    ( devicemotion event rotationRate gamma value )

You can learn more about the methods and options on the Readme of the GitHub page.

Next Steps

I plan to add module loader support and refactor to avoid the need for globals. I will update this post and the GitHub page as the project evolves.


I have updated the GitHub project as mentioned in the next steps. You can visit the GitHub page and get the latest code. I have also updated the code sample in this post.