USB Biofeedback Game Controller
by Advancer Technologies in Workshop > Science
120156 Views, 306 Favorites, 0 Comments
USB Biofeedback Game Controller
This tutorial will teach you to build a USB Biofeedback Game Controller. Use it to play any computer game (that uses keyboard inputs) using your muscles as the controller.
Check out our previous Instructable to learn how to build your own Muscle Sensor
or
Drop by our webstore to purchase muscle sensors, kits, cables and electrodes
Muscle Sensor Kit (now also on SparkFun)
Muscle Sensor Electrodes
Note: This sensor is not intended for use in the diagnosis of disease or other conditions, or in the cure, mitigation treatment, or prevention of disease, in a man or other animals.
About Advancer Technologies
Advancer Technologies is a company devoted to developing innovative game-changing biomedical and biomechanical technologies and applied sciences. Additionally, Advancer Technologies promotes all forms of interest and learning into biomedical technologies. To help cultivate and educate future great minds and concepts in the field, they frequently post informative instructions on some of their technologies. For more information, please visit www.AdvancerTechnologies.com .
Materials
1 x Arduino Uno R2 (needs the atmega8u2 USB chip which is only available on newer Arduino MCUs)
1 x Arduino Project Enclosure
1 x USB cable for your Arduino
4 x Advancer Technologies Muscle Sensor
1 x +/-5V Power Supply
1 x 12V Power Supply (Wall wart)
1 x Muscle Sensor Electrodes
Misc.
Jumper cables or solid core wire
3 x 1" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 2" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 3" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 4" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 3 position Female Receptacle
1 x 3 position Female Housing
3 x Crimps for Female Housing
Plastic board (ABS)
1 pack x 3/8" 4-40 Screws (91772A108)
2 packs x 4-40 Nuts
Tools
Soldering Iron
Scissors or Tin Snips
Crimping tool
Screw driver
Drill with 1/8" bit
Sandpaper
Dremel tool or other cutting tool
Software
Arduino
Processing
Constructing the Plastic Insert
If you're using relatively thin plastic board material, you can probably use a set of heavy duty scissors or tin snips to cut out the insert.
The dimensions (in inches) are shown in the drawing above and are approximate. You might need to do some sanding for a better fit.
After you construct the insert, try sliding it into the bottom of the enclosure and putting the top on. If it doesn't fit properly, get the sand paper out and sand down the parts that are interfering.
Downloads
Preparing the Bottom of the Project Enclosure
First, trim down the two middle supports on the bottom of the enclosure. Leave enough height so that they will still go through your Arduino mounting holes but not go past the Arduino headers. (Pic 1)
Next, place one of the muscle sensors in the bottom left of the enclosure by sliding the bottom left support through the muscle sensor's mounting hole (the one near the female headers). Straighten the sensor by rotating it around the support such that its sides are parallel with the enclosures. Gently and such that you don't jostle the sensor board, slide your plastic insert onto the enclosure and hold it above the sensor. Now, look down the rectangular cutout on your insert and verify the three male headers of your sensor are directly below. If not, remove the insert, adjust the sensor position and repeat until it is in position. Once it is in position, mark the location of the muscle sensor's second mounting pin, remove the sensor, and drill the hole.
Note: If you don't get the hole in exactly the right position, it's OK you can just widen the cutout more to compensate.
Preparing the Top of the Project Enclosure
Soldering the Power Supply Connectors
On the Power Supply board, there is a grid of through holes in a 3 col x 4 row pattern. Solder the three 3" wires to the holes in row 1, solder the three 2" wires to the holes in row 2, solder the three 1" wires to row 3, and solder the 4" wires to the holes in row 4.
Next, grab your 3 female receptacles and bend all the solder tabs so that they're at a 90 degree angle. For the 1"-3" wire sets, solder the female receptacles (with the ports facing downward) such that the wire soldered to the +5V column is soldered to the right solder tab, the GND wire is soldered to the middle solder tab, and the -5V wire is soldered to the left solder tab. For reinforcement, dab a glob of hot glue on the joints.
Using a crimping tool (you can also choose to solder instead of crimping), crimp the crimp tips to each of the 4" wires with the tabs pointing upward. Now insert each of the wires' crimp tips into the female housing, again following the +5V right, GND middle, -5V left order.
Your power supply board should be ready to go. double check each solder and crimp to make sure they'll good and solid.
Mounting the Muscle Sensors and Power Supply Board
Grab three of your sensors and the power supply board and put a screw into each mounting hole. Thread a nut on each screw but leave it slightly loose. These nuts will be used as standoffs.
Next, place each sensor's mounting screw into each corresponding mounting hole. Remember to keep the muscle sensors' female headers on the same side as the shelf's offset. Thread another nut onto each screw until they are nice and tight. Tighten more with a screw driver and a wrench, holding the second nut secure.
Next, follow this same process for the power supply board. Make sure the power jack is facing the front side of the shelf.
For the last muscle sensor, insert a screw up through the bottom of the enclosure and secure with a nut. Then slide the muscle sensor down the support column and insert the screw into the sensor's mounting hole and secure with a nut.
Check to make sure you can fit the female housing through the gap between the sensors and down into the rectangular cutout and onto the male headers of the sensor below. If the gap is too tight, remove one of the top sensors and sand one of its mounting holes on the shelf until the gap is wide enough.
For the remainder of these instructions we're going to refer to the sensors as follows:
Sensor 1 = Closest to Power Supply
Sensor 2 = Middle
Sensor 3 = End
Sensor 4 = Bottom
Connecting the Power Supply to the Muscle Sensors
First you'll want to give all your sensors power. Insert the plastic insert into the project enclosure and then connect each female receptacle and housing to the corresponding sensors. (Hint... the 1" wire goes to the sensor closest to the power supply, the 2" wire goes to the middle sensor on the insert, the 3" wire to the last sensor on the insert, and the 4" wire goes through the rectangular cutout to the sensor on bottom).
MAKE SURE THE CORRECT VOLTAGES ARE CONNECTED TO THE CORRESPONDING SENSOR PINS (+Vs = +5V, GND = GND, -Vs = -5V). IF NOT, YOU CAN POTENTIALLY BURN OUT YOUR SENSOR BOARD.
DOUBLE CHECK.... BETTER SAFE THAN SORRY!
Decide Which Muscles Are Going to Control Which Button(s)
Function buttons:
Button A --> Right forearm muscle
Button B --> Left forearm muscle
Start Button --> Not muscle controlled
Select Button --> Not muscle controlled
Directonal pad:
Right --> Right bicep muscle
Left --> Left bicep muscle
Up --> All four muscles (combo)
Down --> Left and right bicep muscles (combo)
Attaching the Electrodes to Your Muscles
Check out this video for a quick overview of how to connect the electrodes to your bicep...
Connecting the Electrodes to the Muscle Sensor(s)
Sensor 1
Dark green- M.Mid Pin
Light green - M.End Pin
Sensor 2
Dark pink- M.Mid Pin
Light pink - M.End Pin
Sensor 3
Dark red - M.Mid Pin
Light red - M.End Pin
Sensor 4
Dark blue- M.Mid Pin
Light blue - M.End Pin
Each muscle sensor needs a reference electrode to be connected to the Ref pin. For our example, we are going to place them on the back of the forearm near the elbow. The reference electrodes should be placed on electrically neutral areas of the body such as the bony area by the elbow.
Connecting the Muscle Sensor(s) to the Arduino
Now we're getting close. By this step, your muscle electrodes and power supply should be hooked up to your muscle sensors. We just have to connect the sensors to the Arduino.
Using the solid core wire/jumper wire, connect the Vout pin of each muscle sensor to the analog pins on your Arduino.
Sensor 1 Vout --> Analog pin 0
Sensor 2 Vout --> Analog pin 1
Sensor 3 Vout --> Analog pin 2
Sensor 4 Vout --> Analog pin 3
Then connect the GND pin of muscle sensor 1 to the GND pin on your Arduino and the GND pin of muscle sensor 2 to the Analog pin 3 of your Arduino. That last part will keep the remaining two analog pins from floating along with your sensor 4's output.
Upload Visualization Sketch to Your Arduino
By this point, your USB Biofeedback Game Controller should be completely assembled and hooked up. Before we go any further, we'll need to test out your muscle sensors to make sure everything is setup properly.
To test your setup, we're going to use the same visualization software as we used in our muscle sensor demo video. If you haven't already, download and install both the Arduino and Processing software.
Next, download the BarGraph example code on our GitHub repository. Open the Arduino sketch and upload it to your UNO. If you're new to Arduino, check out the information on Arduino's website to help you on this step. Once uploaded, plug in the wall adapter to the barrel jack to power up your muscle sensors.
Next, open the Processing sketch and hit the Run button in the top left. Another window will pop up with 6 colored bars on it. Flex your right forearm, left forearm, right bicep, and left bicep and watch the bars move accordingly. If while at rest, your sensors value is below or above 150 then adjust the gain of your sensor using a screwdriver and turning the poteniometer on the corresponding sensor so that they are around 150 at rest.
As you flex each muscle, the bars should move past the 300 mark. This is important since the software to follow uses the 300 mark to trigger a "button press". You can adjust the gain of your sensor and this threshold level in the code to fine tune your desired button press sensitivity.
Once everything appears to be in working order, close out Processing and you're ready to hack your Arduino into a keyboard.
Upload Keyboard Sketch to Your Arduino
Now, we'll work on turning your Arduino UNO into a HID keyboard.
First, Download the Arduino sketech from our GitHub repository, then compile and upload the sketch to your Arduino.
This is the code that, if desired, you would modify the threshold value in to adjust the "button" sensitivity.
Hack Your Ardunio to Load New Atmega8u2 Firmware
To play video games on your computer with the Arduino, we're going to turn your Arduino into a HID USB keyboard to interface with your computer; to do this you'll need to upload new firmware.
For Mac:
Follow the instructions on this very well put together blog...
Arduino Keyboard HID Part 1
Arduino Keyboard HID Part 2
Latest Hex Files for Uno and Mega 2560
For Windows:
Download the latest hex files
Then follow the instructions on how to upload the hex files to your board using free software called Flip
Upgrading the Arduino Uno 8U2 using Flip
For Linux:
Download the latest hex files
Then follow the instructions on how to upload the hex files to your board
Building Arduino Atmega8u2 firmware on Linux
Note: You'll need to reflash your Arduino with the original firmware to upload new sketches again
Once your Arduino can be connected to your computer and recognized as a HID device, it should be ready to go. Disconnect it and slide it down into your project enclosure.