This tutorial shows how to use EMG data streamed through OpenBCI hardware and the OpenBCI GUI to control the actions of a Hexbug. The battle capabilities of these hexbugs can then be controlled by your own muscle input, and you will be able to engage in Hexbug fights of your own!
Helpful Background Skills:
- Knowledge of Arduino or C-based programming
- How to setup the OpenBCI Headband Kit with Cyton or Ganglion
- This will help you setup and get working with the OpenBCI Boards
- Streaming EMG Data with OpenBCI
- Some background knowledge about EMG data
- A computer that meets the GUI System Requirements
- Hexbug 2.0 Dual Pack
- EMG/ECG Foam Solid Gel Electrodes (30/pack)
- EMG/ECG Snap Electrode Cables
- OpenBCI Cyton Board ($500) or Ganglion Board ($200)
- 20 male-male jumper cables
- 10 x 10kΩ Resistors
- Arduino Genuino Uno
- Optional 5 LEDs (to connect for debugging)
Step 1: Solder Jumper Cables to Controller
1.1 Remove Lid of Controller
Pry off the clear plastic casing by wedging a flat screwdriver or another tool in the four locking tabs of the controller. Hang on to the sliding channel-switcher and the case itself. All other buttons can be discarded.
Remove the taped-on push buttons and discard. Also, de-solder the “Fire” button and discard.
1.2 Solder on Jumper Cables
Then, solder each of the male-male jumper cables to the small, inner circles where the forward, backward, left and right buttons were. Also solder connections to the removed fire cable, and the ground pin to its left.
1.3 Replace Lid of Controller
Using shears or a utility knife, cut pieces off of the clear plastic lid that would interfere with the position of your jumper cables and reinstall it onto the controller, keeping the channel switch in position.
We reuse the lid so that the sliding channel-switcher remains effectively in contact with the conductive patches on the board.
Step 2: Create Breadboard Setup and Connect Controller
Recreate setup as shown above.
2.1 Place Controller Pins in Breadboard
Each command is going to be situated in its own row. Place each pin in its own row in the inner portion of the breadboard. From top to bottom, the order of these should be Right, Left, Forwards, Fire.
2.2 Add Resistors
After inserting these pins, add a 10KΩ resistor bridging the two sides of the breadboard. This corrects the amount of current going to each pin, which allows the bug to work correctly.
2.3 Add Error Checking LEDs
For visualization purposes, at this point we can also add an LED. The anode of the LED should be in line with the control pin and resistor, and the cathode is on a separate line of the breadboard. Connect another resistor from the line of the cathode to the breadboard’s ground. Note that this step is optional, but can help to troubleshoot any errors with the circuit.
2.4 Connect setup to Arduino
Finally, add another jumper cable to connect each row to an Arduino pin. It is important that they correspond as follows:
3 - Fire
4 - Forwards
5 - Left
6 - Right
Step 3: Test With Streaming Synthetic Data
3.1 Upload Sample Code to Board
After downloading our provided code, open in Arduino. Connect your board to your laptop, and make sure to select it as the port from the Tools dropdown.
Then, upload your code to the Arduino Board.
3.2 Open Synthetic Streaming
8 Channels will work fine for this example. Click "Start System" to continue.
Once you have the GUI open, turn off channels 6-8.
3.3 Setup Networking Widget
Open and setup the Networking Widget as shown in the picture, using Serial mode. We want the data type to be "EMG".
Also, note the baud rate in our Arduino sketch is 57600, so we select 57600 from the Baud dropdown.
Make sure to select the correct port for the Arduino. It's the same port we used to upload the sketch to the Arduino. If using Mac/Linux, it should be labeled "usbmodem"—different from the OpenBCI board which will be labeled "usbserial."
Once you have confirmed that all of the information is correct, press start!
3.4 Running Tests
As synthetic data is a lot harder to control, tweak the settings in the EMG widget until the squares are volatile enough to pass the threshold value enumerated in the code. If this is not enough, it may be in your interest to alter the threshold value in the code and re-uploading to your board.
It may also help to turn off all but one channel at a time, and test each command one by one to ensure that they are all doing what they are supposed to be doing. Once you’ve confirmed that everything is working well, then you can move on to real data.
Step 4: Setup Your OpenBCI Board and Electrodes
There are two directions that this can take: one person controlling all 5 commands, or multiple people controlling different commands each. This will differentiate the way that this is done.
Option A: One Person Controlling All Five Commands
Simply follow the instructions in this EMG Setup tutorial from the OpenBCI Documentation here.
Option B: Multiple People Controlling Different Commands
Follow the EMG Setup tutorial from the OpenBCI website but with one alteration: multiple grounds must be spliced together.
To do this, cut off about 3 inches of male pin wires and the end of one female pin wire and remove an inch of rubber from the ends to expose the wires inside. Repeat this for as many male wires as necessary to give each person an individual ground. Splice these exposed ends together, and contain them within a piece of heat-shrink tubing.
Step 5: Get Connected to Real Data
Now, go back to the GUI home and choose LIVE (from Cyton) or LIVE (from Ganglion) —depending on the board you are using— as the data source.
From here, open the EMG Widget and the Networking Widget, and begin streaming exactly as we had before. Now, the data should be streaming from your live input!
Step 6: Battle!
With everything now set up, you are ready for battle. If two setups have been created, you can use the controls to battle.
Please note robots should be turned on one at a time in order to ensure that the signals are being gathered from two unique sources.
Each hexbug has three lives, and after these have all passed, simply press the power button to reset the scores.
Have fun and get battling!
Step 7: Troubleshooting — Keyboard Control Code
If you are having any problems with your board set-up and want to control it using only keyboard input, download this code to use the built-in Arduino Serial Monitor to control your circuit. This will allow you to isolate each action and determine if the problem you are experiencing is coming from the physical Arduino set-up or from the data.