loading

I've been planning to create a Guitar Hero (or Frets on Fire) controller for a long time. A few weeks ago I found a guitar toy (with buttons on the neck, whammy bar and strum bar) at the local store discounted from about 5000 Hungarian Forints (approximately 20$ (USD)) to 2000 HUF (~7$), and I thought it's time to make my own controller. Since it's a bit harder to create a console controller (both Xbox and Playstation), I made it to interact with my computer.

The components used were the following:
- an Arduino Uno
- the guitar
- wires
- a few resistors
- heat shrink tube
- a long USB cable (a few meters)

The required tools:

- basic tools (screwdriver, scissors, etc..)
- soldering iron
- hot glue
- a computer to develop for Arduino and Java (and last but not least - to play!)

Step 1: Guitar Disassembly, Plans

When I got home with the guitar after buying it, the first thing I did was getting a screwdriver and opening the thing up. Okay, I played with it for a few minutes, but it was not very exciting.

On the back, it has many screws (16 to be precise) holding the body and the neck together. It was really uncomfortable during the project to screw and unscrew all of them so many times (fix an error - create two other...).

As I opened it up, I liked what I saw. The 8 buttons on the neck are mounted on a PCB, and there are 9 wires connected to that board.I checked the wiring for each button with a multimeter, and wrote down the "pinout".

The only disappointment was the strumming. I did not expect 2 buttons for strumming up and down. It is okay for the toy, but to play a rythm game, it is not acceptable, because it's hard to strum quickly up and down. I solved it in an other way.

My expectations for the whammy bar were also too high. I expected a potentiometer or something to detect the angle of the bar, because you can rotate it around, but there is only a connect - no connect switch. Doesn't matter, I simulated an oscillation in the java code to be more "realistic" in the game.

There are 5 extra buttons on the front of the guitar. The big one is used to start the star power, and the smaller one (next to the big) is used to pause the game during a song.

The 3 buttons under the strumming mechanism, the on-off switch and the speaker are not used in the project.

Step 2: Wiring

After finding out the original wiring of the fret buttons, I soldered a wire to the pin that connects to all buttons and connected it to 5 volts. I also soldered 10k pulldown resistors to the other pins, and connected one side of the resistors together and then to ground. The other side of the resistors are connected to the Arduino. I know, it is a mess, but during the holidays I was not able to buy new stuff. It would be much more organized and clean if I have made it with own PCB-s, but I wanted to make it as soon as possible (But I made a schematic in Fritzing how it should look like - but the final connections for the arduino are not the exact same as on the picture).

The buttons for escape and star power are on a pcb, like the neck. The same wiring was needed: one pin (that connects to both of them) to 5 volts, and the two others to the Arduino and to ground (with a 10k pulldown resistor).

Since the whammy bar acts as a button, i connected it to the microcontroller as a normal button.

As I was designing the schematic, I thought it would be fun to make the star power with an accelerometer, so when you tilt the guitar, it activates (like an original GH controller), but later I only made it with a button.

The Arduino fitted nice in the guitar. I connected a long USB cable to it, and drilled a hole in the body to get it out. I glued the cable in the body, so it can't move and the Arduino also stays in position. The wire connections to the input pins are hot glued together to stay in the holes, because they could fall out easily when you rock hard. :D

The hard part was the strumming.

Step 3: Strumming

In the original guitar toy, they made the strumming with two buttons under the yellow strum bar. It has that rubber stuff that makes it return to the initial position, like in a normal keyboard. It was not good for our purpose, because it was very hard to strum quickly up and down, so I had to find an other solution.

Firstly, I glued two metal connectors to the yellow strum bar, on the top and the bottom of it, and connected it to 5 volts with a wire. On the body of the guitar, I glued two 10k resistors. One connector of the resistors gets in contact with the glued metal connectors when you strum down or up. Check the pictures, it's easier to see than to describe it. These sides of the resistors are connected to the Arduino, and the other side of the resistors are grounded. This acts like a button, so it is not as complicated as I tried to explain.

After making this logic connection, I had to make that the yellow strum bar go back to the initial position, because without that, it would sense that you are pushing down the strum bar (but it's the gravity, not you). My first thought was to glue a rubber band on the strum bar. It was acceptable, I could strum quickly, there was no unexpected connection, but the rubber band wore out and tore after a few hours (because it was rubbed to the sharp plastic edge). Secondly, I glued those rubber things (which made the buttons raise up after you push them) under the strum bar, but it was worse than the rubber band. My final idea was to return to the rubber bands, but I put electric tape between the rubber and the sharp edges, so they don't tear as quickly as earlier.

It's time to screw back the back of the guitar and write the code!

Step 4: Arduino Code

At first, I connected the wires to the Arduino like this:
- pin 2: sw1
- pin 3: sw2
- pin 4: sw3
- pin 5: sw4
- pin 6: sw5
- pin 7: sw6
- pin 8: sw7
- pin 9: strum up
- pin 10: strum down
- pin 11: whammy
- pin 12: button for the escape
- pin 13: button for the star power

(sw1 is the first fret button, sw7 is the seventh fret button - but we'll only use sw1-sw5)

(If I wanted to make the star power with the accelerometer, I would have connected the X, Y and Z pin to the analog inputs of the arduino)

Firstly, I had to initialize the Serial port, and set the pins as inputs:

void setup(){
Serial.begin(9600); //Initialize Serial class with 9600 Baud/s
for(int i=2; i<=13; i++){
pinMode(i, INPUT); //Set the pins as inputs
}
}

In the loop, I read the inputs and print them out to the Serial port:

void loop(){
while(!Serial.available());
for(int i=2; i<=13; i++){
Serial.print(digitalRead(i));
Serial.print(';');
}

Serial.print('\n');

delay(1);

The input values are sent in a line, separated with a ';'. So if you press a button, or strum down, only the value in that index turns to 1, otherwise it is 0. In Java, a buffer is filled when a '\n' new line operator is received. The while(!Serial.available()); line helps to only send the data after the program was started.

The one millisecond delay is needed to transfer the data, without that I got strange lines in the serial monitor.

Step 5: Java Programming

To receive the serial data from an Arduino in Java, you'll need the RXTX library, which is available here: http://fizzed.com/oss/rxtx-for-java - Installing instructions are in the compressed zip file.

Normally, without a controller, you would have to use your keyboard and mouse to play. In Java, there is a class called "Robot" that is made to imitate keystrokes and mouse movement.

Java API for Robot class: https://docs.oracle.com/javase/7/docs/api/java/awt...

I added the Java source code with comments, but I'll write about it here too.

Firstly, we open the serial port with the name (if it is not COM3, change it to the arduino's port) and the data (9600 baud, parity, data and stop bits..). You can download the skeleton from here: http://playground.arduino.cc/Interfacing/Java

In the SerialEvent function you can access the buffered input (the line created in the loop in arduino) with the input.ReadLine() function call.

Then, I'll pass the string to the guitar function, in which I'll make the steps to create the keystrokes.

The string is split into an integer array, because it is easier to check the values in that. The indexing is the same as in the Arduino.

If the first element of the array is one, that means that the first fret button is pressed, and we have to imitate that somebody pressed the '1' key on the keyboard. That's why we have the robot.keyPress(KeyEvent.VK_1); call.

If it was pressed, but it is released now, we have to release the key as well with the function call: robot.keyRelease(KeyEvent.VK_1);

If the second fret button is pressed, we'll call the robot.keyPress for the key '2' and so on and so forth.

I had to make it for every fret button, escape, and star power, and the strumming up and down. For the frets, the keys '1' to '5' are pressed corresponding to the index of the fret on the neck. For the strumming the UP and DOWN arrows are pressed, for the escape, it presses escape, and for star power, the key 'S'.

When the whammy is triggered, it calls the whammy function, which creates a new thread moving the mouse on the X axis, because it can be set in the game to activate the whammy with the mouse. When it moves, it oscillates, so it's not only binary 1 or 0 for the whammy. With a new thread started, you can go on pressing other keys and strumming, there won't be any problem. And also if you trigger the whammy multiple times, multiple threads are started and the mouse goes back and forth. I think it is a nice solution for the problem.

The communication is started after sending a '1' to the Arduino in the main function at the bottom.

If you try it out, when you press the fret buttons, it's the same as when you press the corresponding keys on your keyboard.

Let's set it in the game!

Step 6: Setting the Game Up

As I had the guitar connected and the Java program running, I opened the Guitar Hero 3 game. In the options, you can set the keys for the frets, strumming and star power, and for the whammy, choose the mouse X axis.

Unfortunately, I was not able to make screenshots of the game, because the image was completely black. I don't know why.

If all keys have been set, the next step is to calibrate the lag in the settings, because the arduino and java makes a lot of lag. I measured about 60 milliseconds. It is a lot, but the game can be enjoyable, it is not that much.

Later I may paint the guitar for a color that not so childish (black I think), but nowadays I have a lot of exams, so it is a plan for the future.

Let me know if you liked it or if you also made something like this! Thanks!

<p>Awesome controller. </p>
<p>Thanks!</p>

About This Instructable

2,413views

17favorites

License:

More by rglszl:Guitar Hero USB controller with Arduino and Java 
Add instructable to: