กลับไปหน้ารวมไฟล์
usbcycle-ride-through-your-virtual-world-943cfb-en.md

USBcycle ... what is it?

Project Logo (why not?)

USBcycle is a bicycle hacked into a USB game controller. It enables you to pedal your way through open-world games of two flavours:

(A) multi-axis joystick-driven games where you control a vehicle with an accelerator, brakes, and steering (like GTA and ETS2 or maybe a flight simulator) plus additional keyboard inputs

(B) WASD FPS "walking" games like Portal, Talos Principle, Half Life, Dear Esther etc.

MINI DEMO of USBcycle, EuroBike Simulator version

(A longer video is also available). This project is more about software than hardware; I didn't do any original electronic circuit design. I just put together a pile of off-the-shelf parts and then wrote the Arduino code to turn them into a USB game controller driven by a bicycle. The only cleverness here is in the code and the physical modifications to the bike (and even those are pretty crude).

In this write up I'm using the quote format (immediately below) for asides, disclaimers, and game-specific notes rather than for quoting other people. The Project Hub doesn't offer us much flexibility in formatting, so I'm making the best of what is available.

Disclaimer: After I was almost done with editing this writeup I thought (rather belatedly) I should have a look around and check if anyone else was using the same name for a similar project. To my dismay I did find a "USB Cycle" project, and their logo was embarrassingly similar to mine -- I guess geek minds think alike, ouch -- but I couldn't figure out what it was all about because I can't read Dutch. It was based in the Netherlands and looked kind of academic, with Powerpoint presentations and so on -- and it seemed to have no Twitter activity since early 2014. So I hope that it is dormant or completed, and that the Dutch team will not feel I'm infringing on their public image or trying to steal their street cred. I just want to say for the record that I have no connection with this other project of similar name, had no prior knowledge of its existence when I was building my USBcycle, and only discovered it after I had completed and named my project. The Dutch project seems to be called USB Cycle with a space, whereas mine is called USBcycle without a space. If the USB Cycle team objects to my use of this name, or to my logo, I invite them to contact me; for courtesy's sake I'm willing to use one of the fallback names I came up with, even though these are not as good (so I'm hoping they don't contact me!)

USBcycle ... why?

The problem with coastal BC (where I live) is that the winters are really long, dark, wet... not conducive to healthy outdoor exercise. I get out of shape in the winter. I used to be a pretty avid cyclist, but the weather plus our locally bike-unfriendly terrain have reduced me to a winter couch potato. Well, computer potato really, I spend more time playing games or coding than watching TV.

No problem, right? Get an exercise bike! Low-impact indoor exercise, no rain, no mud, no traffic, what could be easier?

The problem with exercise bikes is that they are Boring. I mean, Really Boring. It's hard (for me anyway) to get motivated to do something so insanely boring for even 10 minutes, let alone an hour or more. But I can play immersive computer games for hours without getting bored. Hmmm.

The obvious solution: equip the exercise bike with a video screen and tie it to some kind of interesting game-like software. It's such an obvious solution that quite a few people are working on it at present. Their projects run the gamut from fairly slick licensed training or exercise packages to garage-based Maker efforts. I categorise them roughly into three flavours:

  • Advanced bike training simulators & stands (the kind serious professional racers use) offer race course simulations (of real-world courses that the cyclist is preparing for) complete with app-controlled resistance scaled to grade. Some high-tech trainer stands offer a flexible mount so the bike can lean a bit and feel more natural. Very nifty. But the number of courses is fairly small, the software is proprietary, and the hardware is super expensive.
  • In the world of academia and prototyping, there are some clever folks tying bikes to Google Earth; a real-time virtual ride across Canada is in progress. That's a very cool project but seems a bit daunting to replicate at home. And frankly, google street view (in my experience) is more like a slide show than animation.

Meanwhile, I have a good old MTB that I don't use much any more (getting too old to think that riding around in the rain and cold of a BC winter is fun). And I have a moderately beastly gaming computer (an i7 Hackintosh with a GTX 970, quite adequate as long as I stay in the 1080p world) and I have already paid the license fees for a really good open-world driving simulator -- one so likeable and fun that I've spent over 300 hours driving it. Sitting on my increasingly padded bum all winter driving a virtual truck all over Europe is not helping me stay in shape... but surely these three resources could be combined into a virtual biking setup, at a reasonable cost?

So, early in 2017, I decided to see if I could turn an ordinary off-the-shelf bike into a USB game controller that would enable me to cycle, rather than drive, through the over 45,000 (virtual) km of European roadways in my favourite open-world sim. It took about 4 months because I was really starting from scratch (had never built any homegrown electronics before, other than assembling computers from components, had only the vaguest idea of what an Arduino is), but in the end I succeeded -- and hope that others may decide to do likewise based on my experience.

The end result: a generic bike-to-joystick controller (USBcycle), with a user control panel mounted on the handlebars. The user control panel includes a generous array of buttons (36 at last count!); I have customised my controller by mapping the buttons to commands specific to ETS2, and the final result is a virtual bike touring experience that I really enjoy, which should motivate me to exercise more regularly during the long BC winter.... and I call it...

Two Wheels Good!

Euro Bike Simulator: Ingredients and Recipe

Complete Ingredients List

An Open World to Ride Through:

  • 1 copy of SCS' driving simulator, Euro Truck Simulator 2 (or American Truck Simulator). This sim is available for OSX, SteamOS and Linux as well as Windows. It is available through Steam. The core game only costs $22 CDN but you will want the DLCs; the "whole enchilada" from SCS is more like $60, and you can expand your open world for free with various community map mods.
  • plus: a simple mod to make the player's POV more like a cyclist's view of the road. I can provide this mod for you.

Hardware to Run the Open World and Ride Through It:

  • 1 gaming computer capable of running ETS2 or ATS at a graphic quality that makes you happy
  • 1 Bike or Exercise Gizmo: 1 standard road bike, MTB, recumbent or whatever you've got lying around that has at least one drive wheel, a steering device, and a brake actuator. If your bike gizmo is a real bike then you'll need a training stand (doesn't have to be fancy, I got a cheapie off Ebay). You could use a roller stand, but I think you'd lose the ability to steer using the bike handlebars -- I think twisting the bars when on a roller stand results in falling over, though I haven't verified this personally.
  • 1 Controller to make the Bike into a USBcycle:

The USBcycle Controller:

  • 2 Arduino Leos
  • some hacked-together hardware to mount the sensors appropriately on the bike; not having a 3d printer I like to build stuff out of foamcore, doorskin, 1/4" ply, scrap wood, hot glue, closed-cell packing foam, velcro, electrician's tape, etc.
  • various long USB cables, long HDMI cable, long audio cable etc, to carry signals between computer and bike. You can use powered devices to extend these lengths to over 100 feet if need be. I just kept the bike near the computer :-)
  • a few specialised (and more expensive) electronic components: one ams 5601 Hall rotary encoder on an I2C breakout board, Adafruit Trellis keypads (I2C again), Adafruit 7 segment display I2C backpack, WiiChuck (this is also I2C) for WASD version.
  • a bin of small generic (cheap) electronic components -- resistors, LEDs, capacitors, 7 seg displays, a linear pot, a knob, slide switches, reed switches, a Hall linear encoder (proximity sensor), pushbuttons, solderless prototyping breadboards, small prototyping PCBs, jumper wires, RJ45 connectors and cable, etc.
  • a project box with a user control panel, to be mounted on the bike handlebars. fab one up or repurpose a jewellery box or some other box -- about the size of 2 stacked hardback books was comfortable for me, but I'm sure you could make it more compact.
  • the usual basic hand tools of the electronics trade, antistat mat, etc. Mostly, they don't have to be super expensive; but I do recommend you buy or borrow a decent soldering iron for the final assembly (and for building kit components such as Adafruit backpacks). A good iron can make all the difference between frustration (and possibly component damage) and success.
  • possibly the most important resource for your project: the terrific Arduino community. The forum, the free libraries for almost every breakout board and device under the sun, the zillions of documented projects, the official online doco and tutorials: all this enabled me to go from "what's an Arduino" to a working, fairly complex, project in under 6 months. Admittedly I have a background in both coding and electronics, but I think even an absolute n00b can succeed with Arduino because of the very high quality of support (both official and community).

I guesstimate the total electronics cost to be under $250. I didn't really keep track because I was gearing up for Arduino hacking generally and bought way more parts than ever went into the USBcycle project.

Lastly, when putting it all together for actual use, you need a screen in front of the bike to watch the world go by (at first I just stole the TV from the living room), and it's nice to hear the ambient sound effects if there are any, so:

The Video and Audio Output

  • 1 large screen 1080p display to put in front of the bike
  • (luxury item) stereo speakers to enjoy game SFX while riding; or you could wear headphones.

------------------------------------------------------------------

The objectives:

First milestone: build a simple WASD controller in which pedalling action determines speed and fwd/reverse. Steer by using a real mouse or emulating mouse movement. Use a portable stepper device as the pedal unit. This was Phase One: a feasibility study and prototype. If this worked out well, I planned to proceed to...

Second milestone: Use a real bike instead of a stepper. Instead of simple WASD keystrokes, emulate the accelerator/brake/steering control axes by instrumenting the bike. Steer using the handlebars, brake with the R-hand brake lever, and accelerate with pedalling speed. Make it feel (sorta) like riding a bike.

Note that as of this version of USBcycle, I have not yet succeeded in getting any telemetry out of the game, so this is a zero-feedback system. The controller cannot know (any more than my Driving Force GT controller knows) the truck speed or position. So it is a fairly dumb system at present. If I were a faster/better C coder, or could find a collaborator, telemetry would open up all kinds of possibilities (like a fan speed controller that would blow air on your face proportionate to your speed, maybe app-controlled resistance so hills are more realistic, etc). That would all be very nifty and is on my list of future projects.

The Development Kit: Arduino

I was starting from zero here, never having done any microcontroller hobby stuff. I decided to use Arduino technology because it seemed popular, well-supported and user-friendly. So I would be using Arduino to build a device that emulates 2 USB HIDs : a keyboard and mouse device, and a joystick with 3 axes. This actually requires 2 'duinos because each one can only emulate one HID.

UPDATE Dec 2017: I don't know why I was so sure of this HID limitation when I started the project. It turns

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x OSX EL Capitan"
author: "Tazling"
category: "Gaming & Entertainment"
components:
  - "4x Protoboards"
  - "1x Rotary potentiometer (generic)"
  - "1x Linear Hall Effect Sensor"
  - "2x Arduino Leonardo"
  - "1x Adafruit 7 segment i2c backpack"
  - "20x Resistor 221 ohm"
  - "50x LED (generic)"
  - "1x Soldering iron (generic)"
  - "2x Adafruit Trellis Keypad"
  - "1x Hot glue gun (generic)"
  - "1x AS5601 breakout by ams"
  - "1x SparkFun 7-Segment Serial Display - Red"
description: "Immersive VR kinematics! Rip raw rotational inertia telemetry off an exercise bike and leverage an ATmega32U4 processor to violently translate physical RPMs natively into USB HID keyboard strokes, forcing explicit forward momentum in AAA Gaming engines."
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles:
  - "https://github.com/RootlessAgrarian/EuroBikeSimulator"
encryptedPayload: "U2FsdGVkX192ayFqf+aSBiK15v8InEACx7BSx7HDoB5KTgLoV8f6pOM2Kj5vWrgVGmlw2IsDkQVFkuU8JyfZo4Sy8Enc2TGZ/hVM4sxjP9s="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/usbcycle-ride-through-your-virtual-world-943cfb_cover.JPG"
lang: "en"
likes: 18
passwordHash: "8e5c1eab8c4bd61eb07087a3bc8ff850792e0000f9d06a40bc26fb32ee6fd684"
price: 1499
seoDescription: "Turn your bicycle into a game controller using 2 Leonardos to emulate keyboard, mouse, and joystick inputs for virtual cycling."
tags:
  - "health"
  - "games"
title: "USBcycle: Ride Through Your Virtual World!"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/DD83fo_yYNA"
  - "https://www.youtube.com/embed/7RE_ueXC48c"
  - "https://www.youtube.com/embed/5Q9Ofx5YHwk"
views: 31183