Chris Gregg
June 2014
This is a demonstration program for the LightBlue Bean (http://punchthrough.com/bean/) to show a (somewhat convoluted) integration into a web page. Basically, the Bean's 3-axis accelerometer is used as an input device for a web page. The basic flow of information is as follows:
Bean hardware accelerometer --> Arduino sketch program --> OS X Virtual Serial port (through the LightBean Loader) --> pywebsocket (https://code.google.com/p/pywebsocket/) --> browser web page running JavaScript and websockets.
- LightBlue Bean (http://punchthrough.com/bean/)
- BeanLoader (see http://punchthrough.com/bean/getting-started/)
- Arduino IDE
- pywebsocket python integration (https://code.google.com/p/pywebsocket/)
- pyserial python module (http://pyserial.sourceforge.net)
-
Download the BeanCube software from https://github.com/tofergregg/BeanCube
-
Install the BeanLoader and Arduino IDE (following "getting started" from above).
-
Compile the beanCube sketch in the Arduino IDE, which will open the Bean Loader.
-
Connect your Bean with the Bean Loader, and program the sketch onto the Bean.
-
Turn on the Virtual Serial port through the Bean Loader.
-
Install the pyserial module: pip install pyserial
-
Install pywebsocket Follow the instructions at: https://code.google.com/p/pywebsocket/source/browse/trunk/src/README
-
Place the beanCube_wsh.py file (from the git repository) into the pywebsocket-0.7.9/src/example folder.
-
cd into the pywebsocket-0.7.9/src folder
-
run the standalone pywebsocket server on port 8880: ./mod_pywebsocket/standalone.py -p 8880 -d example
You need to click "Allow" at the following prompt: "Do you want the application “Python.app” to accept incoming network connections?"
- Open the beanCube.html web page, which will attempt to connect with the Bean through websockets and the serial port.
If all goes well, you should see "websocket opened." in a pop-up alert window.
Once connected, you can use the Bean to rotate the three cubes on the screen, demonstrating the use of the 3-axis accelerometer.
There is a demo game as well -- push "Play Game" to try it out, and follow the directions. It is harder than it looks!
How to run the demo: http://youtu.be/LxICe2TMLss
The Bean controlling the browser cubes: http://youtu.be/WI5TF9vgKIQ