blavery
Posts: 95
Joined: Sun Jul 01, 2012 2:57 am
Location: QLD. Australia

Pi-Gyro: reading smartphone sensors

Mon Apr 13, 2015 11:08 am

I have just posted a small "node.js" project on GitHub using a mobile phone as a Compass / Pitch / Roll sensor to my Raspberry Pi.

Communication scenario:
- Phone: Home wifi network,
- Pi: Home network,
- Internet accessability: yes

It uses an easy "node.js" implementation of a 1-page webserver on the Raspberry Pi.
The Pi can then very easily accept a stream of "orientation" data from the phone.
This includes figures for yaw (compass), pitch (front up), and roll (side up).
The phone becomes a hand-held movement controller, like a modern game controller.
DSCN6020.JPG
Smartphone browser sending orientation data to Raspberry Pi.
DSCN6020.JPG (33.61 KiB) Viewed 1609 times
SETUP:

1. Make yourself a working directory and make your project in there. Eg /home/pi/gyro/

2. NODE.JS: If you install from the Raspbian repository, you get an old version of node.js. Instead get it from
http://node-arm.herokuapp.com/
This installed node 0.12.1 for me.

3. MODULES: Use Node Package Manager (which installed as part of node):
npm install socket.io node-static ip
It doesn't seem to matter whether you load the modules locally or global.

4. THE TWO WEBSERVER FILES: server.js and index.html. Get them from github.
https://github.com/BLavery/PiGyro
The zip file lower right is easiest. unzip into your folder.

5. START WEBSERVER: On the Pi, start webserver. Run in a terminal:
- node server.js
It will tell you the Pi's IP address.

6. PHONE: Start browser. Set address to the Raspberry Pi address on your network, at "port 8080". Eg:
http://192.168.1.14:8080
Press OK to start.
That's it!
Move the phone. Changing sensor figures should print on the Pi.
gyro-pi.png
In this demo, figures simply print on Pi terminal.
UPDATE: IP address of PI is shown.
gyro-pi.png (30.17 KiB) Viewed 1609 times
Concept credit:
https://github.com/shaunuk/picar

Other ref:
http://www.w3.org/TR/orientation-event/

Return to “Automation, sensing and robotics”