Step 5: Python Server

Google bike uses a small python server to read incoming sensor data and serve up the google bike webpage. You will need to install python (version 2.something, the script is not 3.0 compatible as far as I know), and pyserial. Installing python and pyserial should be a relatively painless process with lots of useful information found via google. The only issue I ran into on windows was that I needed to install a 32-bit version of python as I could not find a 64-bit version of pyserial.

The attached server.zip contains the python code to run google bike. It includes:

arduino.py a very simple python module with an Arduino object that receives incoming sensor data

server.py the main python script that creates an Arduino object, a small web server, and launches the google bike page (index.html)

and other supporting files

Sadly, the serial port address is hardcoded on line 17 of server.py So... once you plug in the arduino be sure to correct this line before running server.py On a windows machine the line should look something like:


on mac it will look something like:


After correcting line 17, run server.py (either from the command line, or double click, etc...) and python should launch a web browser with the address:

<p>Thank you, braingram, for easy to understand code. I was able to hook-up my elliptical trainer to your code in one week-end. I even hacked it to use two buttons for turning instead of thumb joystick. This will keep me motivated to stay fit through the winter!</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/aMexiSP5Vjc" width="500"></iframe></p>
Has anyone found a way around the Google Earth issue for Linux since this was originally posted? Looks like Goggle Maps is putting emphasis on WebGL but there are some strict hardware limitations. It would be nice to run this app on cheap Linux hardware.
I've been working on this for about a week now with limited success. The bike on the screen goes backwards and counterclockwise. It does not appear that it is responding to the joystick input. The output from the python server look good, showing a range of 0-1023 for the x/y inputs and 0/1 for the push button. The cadence output increases incrementally with each input.<br><br>Problem with the python server, maybe?
Yeah, it sounds like a problem with the javascript. I'm not quite sure what though :-/<br><br>I hooked up the press button on the joystick (press down and hear a click) to make the bike go backwards.<br><br>I also ended up only using the V component of the joystick (the H component broken on mine).<br><br>If the python server output looks ok I'd say add some alerts or something to the javascript code to see what ARDUINO_V and ARDUINO_C are doing. If they're misbehaving than it sounds like a problem between the python server and javascript code.
This is the coolest idea.&nbsp;<br> <br> Unfortunately I do not have the skill to build my own.&nbsp; For some reason there is not too many ready-made controllers out there.&nbsp; I only found a couple:<br> Cyber ExerCycle <a href="http://www.cyberbiking.com">http://www.cyberbiking.com</a><br> XR Kit <a href="http://www.xrgame kit.com">http://www.xrgame kit.com</a><br> <br> I am not sure how well they would work with Google Earth. Has anyone tried them?<br> <br>
Interesting, I'll try it.
Umm, Google earth is out for linux....
Might be interesting to hook this up to opensprints. They use an open http-based protocol to serve up the data from their arduino sensors, so multiple software frontends exist. With preset steering info, eg from a GPS trace, you could have a circuit race (up the Champs Elysee?)<br><br>Another option that I keep meaning to try (when I find my ANT+ stick...lost in a box somewhere) is to use libusb to get the cadence or speed events from Garmin sensors - again, getting the steering from a GPS trace. There's code for reading those events floating around t'internet.
Great Idea...! Some suggestions for your consideration:<br><br>- Hook it up to a projector and have the streetview projected large-scale in front of the rider.<br>- Designing a mechanism to adjust the resistance of the magnetic flywheel to match the gradient of the road - getting data from google earth height info.<br>- Design the joysick to mount to the headset with a link to the stem/handlebars so small movements in the steering to control direction - removing the need to let go of the handlebars.<br>- Put a desktop fan in front of the cyclist - the speed of the fan could be controlled by the riders speed - to mimic wind/air resistance whilst keeping the cyclist cool.<br><br>Good work.!! Really like it.!<br>
LINUX USERS!!!!<br>you can run google earth through wine and do great!<br>runs really well.<br>(also, as a cyclist i would pay for this setup in a sleeker case attached to my rear wheel. <br>patent it.<br>???<br>profit.)<br>thanks for the tips<br>-hack life<br>&gt;G
Put a patent on it and make your fortune! I think you have a winner!
very cool. i'll try it.......
I once worked at a company that provided its employees with a gym. It included several bikes that were networked together. You would play Azteca, a game based on an Aztec progenitor of soccer - you could steal the ball by riding into your opponent, and you would shoot the ball by pressing a button on the handle. Stearing was accomplished by leaning the recumbent bike like you would if it were a real bike. It was *very* fun. It'd be cool to take what you've done and basically turn your controller into a joystick controller.
this is GREAT!!! I have to have this for the winters here. I can't train outside but cycling inside is too boring, this is the best solution
Wonderful idea, I may use your idea and modify it for a treadmill. <br> <br>Paul
Nice! My dad expressed some interest in making another or modifying the current project for use on an elliptical machine for my mom. I seem to remember someone setting up a treadmill to 'run' through world of warcraft, they might have some documentation on the setup that could be useful. Good luck!
Google Earth is available in Linux. (don't know why you'd mention &quot;sorry Linux&quot;) in reference to Google Earth.
Please see my reply to skidawgs comment. The problem is that there is no google earth browser plugin for linux.
I just looked at Google Earth's site, and there is a Google Earth 6 version that can be downloaded for Linux, at least for Debian/Ubuntu and Fedora/openSUSE. It also looks like the pySerial package can also be installed from source on Linux.<br><br>Is there anything else that causes this to not be able to run on Linux? I am not seeing anything.
Google bike runs through your web browser and uses the google earth browser plugin. You are correct that you can download google earth and the necessary python stuff for linux. Sadly, the browser plugin does not exist for linux :( If you find otherwise please let me know as I'd love to get this running on linux (my os of choice). If you do find the plugin, getting google bike to run should be almost identical to the osx instructions (the serial port should be /dev/ttyUSB0 or something like that).
GENIUS!<br><br>I envy your brains!
Cool! Here's how some guys ride the Bergensbanen railroad with a bike: <a href="http://www.rullesykling.com/Bergensbanen.html">http://www.rullesykling.com/Bergensbanen.html</a><br>

About This Instructable


74 favorites


More by braingram: Wedding 'save the date' disk with hidden message rtl-sdr on Ubuntu Google Bike
Add instructable to: