Thursday, May 28, 2015

A better gamecube controller? (Part 3 of 3: The Case)

This is my final post for this project!!!
Please check out parts 1 and 2 of this project in case you missed them.:

Figure 1: Final concept for modified controller

I originally planned on covering the case in 2 parts, but realized I don't really know what I'm doing, so it's better if I just do it in one part and try figuring out what I'm doing as I go...

Also I don't have access to good tools, so if you're doing a similar project I can't advise you doing this part how I did.

Before starting on the actual box, I prepped the plastic controller so I could better plan out the box's construction. There are two parts of the original controller I want to retain for the new controller: the left hand side, and the c-stick assembly. Figure 2 shows my initial cut to separate the two sides.

Figure 2: No going back now.

I then want a flat, perpendicular cut along the left hand side so that it will interface squarely with the box.

On the c-stick I want just the c-stick housing, so a flat cut was made parallel to the left-right direction of the c-stick. When we rotate the c-stick around 180 degrees from it's original orientation and lay this part flat on the top of our fight stick, up-c will be up and down-c will be down. Figure 3 shows all the cuts I made on the controller. Figure 4 is the left hand piece, and figure 5 is the c-stick piece. Notice how I left the right handle on the c-stick enclosure, This is because it will not get in the way of our final design, and will allow the c-stick enclosure to make a flat seal all the way around when placed on the top of the box.

Figure 3: Cuts made to controller.

Figure 4: Left hand plastic enclosure.
Figure 5: C-stick plastic enclosure.
Note: In earlier posts I talked about rotating the c-stick 134 degrees instead of 180 degrees. The c-stick auto aligns itself using 2 holes on the pcb and 2 pegs on the enclosure as seen in figure 6. It will be easier to properly align the c-stick by rotating it 180 degrees and allowing these holes and pegs to do their job.
Figure 6: C-stick assembly highlighting how c-stick is aligned.

This part of the project was by far the hardest for me personally. I have VERY little woodworking experience under my belt, but when building a box I figured getting 4 walls was the place to start. Using a miter box  and handsaw I cut 4 planks of oak measuring (2 3/8)"x(3/4)"x(8)". I then glued them flush for the 4 walls as can be seen in figure 7. The walls were then sanded to smooth off the rough cut edges.
Figure 8: The first step to a box, gluing 4 sides.
A top and bottom to the box were then cut out of (1/4)" oak plywood which fit (near) perfectly inside the four walls. I then cut four posts measuring (3/4)"x(3/4)"x(1 7/8)" out. These post will be glued in each corner of the box and will provide a platform to glue the top of the box, and locations to screw on the bottom of the box.

Figure 9 shows me gluing the posts. The top was set under the posts to ensure the top would be flush to the walls once attached.
Figure 9: Gluing support posts
 Figure 10 is me gluing the top of the box onto the support posts.
Figure 10: Gluing top onto box.
Since this box is going to be handled a lot I didn't want sharp edges. A 1/2" roundover router bit was used to round the top edges, and a 1/4" roundover router bit was used on the bottom and corner edges. This was my first time using a router and I'm really happy with the results (figure 11).
Figure 11: Box with routed edges.

At this point I drew an outline of where the left hand of the controller was going to connect to the box and used this to route out a hole large enough to pass the circuit board through easily. Figure 12 shows the hole and the controller outline. It's not pretty, but you won't be able to see this once we're done.
Figure 12: Hole cut for controller pcb to pass into box.
To cut the holes for the buttons correctly I printed off a hitbox template from the Internet. (For people not into fighting games: a hitbox is like a fightstick (arcade controls) but with extra buttons to replace the joystick.) I taped this to the box and drilled my guide holes figure 13. I then drilled the holes to their full size of 23mm (15/16").
Figure 13: Button template printed from hitbox template.
Figure 14 gives you an idea of what the final box will look like. You will also notice at this point that I accidentally drilled an extra guide hole. There is also a small gap in the wood at the top of the box where the top and the wall meet. These were filled with wood filler, and then the whole box was sanded down. At this point the box feels pretty nice to rest your hand on, and the positioning of the buttons and c-stick feels pretty natural.
Figure 14: Box with button holes drilled.
The wood work at this point is ready to be finished. I used a really dark oil based stain since the controller parts are dark. This also allows some of the natural beauty of the oak to still show through. I prefer staining wood to painting wood for application that are going to be handled a lot. I find painted controllers make the user's hands sweat more where as stain allows for the wood and you hands to breath. Figure 15 shows the final coat of stain drying.
Figure 15: Final coat of stain drying.
Between each coat, I sanded down the box with progressively finer grit sandpaper/steel wool until I got an nice smooth finish.

The first thing I did was outline where the c-stick assembly would lay on the box and drilled a hole large enough to pass my wires through (I had to resolder my c-stick wires to the controller afterwards).

I did a little research into what the best adhesive is for gluing plastics (just about everything adheres to wood, so I wasn't too concerned about that). JB Weld plasticweld was highly recommended so I thought I'd try it out. It is a 2 part epoxy that comes in a single tube as a putty. You just kneed the stuff together and you have 20 minutes to work with it. I lined the edge of the c-stick assembly with the stuff and then stuck it firmly against the top of the box. Before it was cured, I used a razor blade to cut away any extra plasticweld.

About 30 minutes later the c-stick is firmly attached to the box (Figure 16)! I'm really happy with the plasticweld!
Figure 16: Box with c-stick attached.
For the left hand I removed the spring from the trigger. I figured I'd have to leave the L trigger somewhat enabled if people want to rage quit games (L+R+A+start). I then applied the plasticweld, lined up the controller with the pcb passing through the hole I made, and in 30 minutes THE CONTROLLER WAS DONE!!!!

Figure 17: The Final Controller!

 I'm really happy with how the controller turned out. I'm not going to comment too much on challenges and benefits from using the controller here since I would have to play with it more. I think Fidi is planning on doing a write up on it. All I will say is that my hand feels nowher as tense while playing. Having the buttons spread across multiple fingers seems to make somethings easier. I could consistently multishining, short hop double laser, shine-cancel grab, wavedash, JC grab, JC up-smash, etc. I found it awkward to do some simple things like l-canceling, and navigating the main menus though. I think it's just a matter of practicing and getting familiar with the controller. I guess we will just have to wait for Fidi practice with it and tell us.

The only thing I would really change with this is that I would have moved the start button and controller cord over to the box. I also would have routed out the hole on the wall the left-hand connects to before assembling the box. There is a small part of the hole that is visible because I had difficulty cutting it. Over all I'm very happy with the outcome, and I learned a lot making this thing.

One of my best friends and amazing drummer, Jay Carlson, has been spitting out a lot of amazing  music lately with his bands Megatherium Club and  Fringe Pipes.

The first of these is the Megatherium Club single Preach.

Fringe Pipes' self titled EP was recently released.

And finally both bands participated in St. Olaf's DNNR PRTY which means the release of 2 more singles (Walk Yourself Back Home - Megatherium Club and Prison Cells - Fringe Pipes)

THANKS FOR FOLLOWING THIS PROJECT! Leave me a comment if you have any questions.

Saturday, March 7, 2015

A better gamecube controller? (Part 2: Electrical Execution)

Please read part one if you missed it!

Planning out what you're going to do is fine and dandy, but this is where all the fun happens. We actually get to build and test stuff in this post!

Figure 1: Final concept for modified controller.

Cause you can't do cool electrical stuff without the right stuff.

The tools you need are:
  • TV & Gamecube with Melee
  • Multimeter
  • Sidecutters
  • Precision Tweezers
  • Soldering Iron/Station - You'll want to click this link, trust me....
  • Sand paper - fine grit (300?)
  • Heat gun or lighter
The materials you need are:
  • Gamecube controller
  • 7 24mm buttons
  • Wire - I use rainbow ribbon cable cause it's neat and automatically color codes your wiring for you
  • This and this - You could just solder wire straight to the buttons, but this makes it so that the user can freely move buttons around if they choose to.
  • 1.27 kΩ 1% resistor
  • 5.62 kΩ 1% resistor
  • heatshrink

We are going to be starting here because it can be a slightly tricky part of a pad hack. We plug our controller into the game console and start a match in training mode (characters and stage don't matter). This powers up our controller. The first thing we need to do is figure out the voltage levels for when the trigger is not pressed, the voltage when we are light shielding, and the resistance of the pot. From the back of the board we can clearly see the right trigger pot and the 3 pins on the front that correspond to it (figure 2). Using the multimeter to measure the voltage at each of its pin, we find that pin 3 is 3.44 volts (VCC), pin 2 is 0 volts (GND), and pin 1 changes as we move to pot so it is the pin that goes back to IC on the board. We also find that when we are not shielding the voltage on the pot is at ground (0 volts), and when we move it just enough to light shield the voltage on this pin reads 0.623 volts.
Figure 2: Controller pcb with potentiometer highlight and pin out marked.
We can now unplug the controller and measure the total resistance of the pot between the ground pin and the supply pin. We find it to be about 6.9 kΩ. With all the information we now know, we can use the equations from our first post to find what resistor values we need to use. 
R2 = 1.249 kΩ ≈ 1.27 

R1= 6.9-1.27
R1 = 5.63 kΩ  ≈  5.62 kΩ

In this case we need a 1.27 kΩ resistor and  5.62 kΩ resistor since those are our closest standard 1% resistor values.

We are now ready to build our circuit for the light shield button. We first need to remove the right trigger's pot. Since we don't need to save the pot, I'm just going to use a pair of sidecutters to carefully cut it off the board. I can then use the soldering iron and a pair of tweezers to remove the remaining bits of pins left in the pot's holes.

Figure 3: Schematic of light shield button design.

Now that the holes for the pot are free we can solder the resistors and 2 wires leading to a button to implement our design from part 1 (figure 3). Figures 4 and 5 shows how we need to connect the resistors to implement our design.

Figure 4: Drawing of how the resistors will connect to the pcb to implement light shield button.
Figure 5: Soldered light shield circuitry.

The all the buttons (except power shield and Z) can be seen on the pcb as black pads in figure 2. This black is a conductive material, and underneath it is copper. One side of the black pads corresponds to GND and the other side runs directly to a pin on the controller's integrated circuit. Using the multimeter we can find that the bottom half of each pad is ground and the top half is our signal the IC reads.

Since we want to solder our buttons in parallel with the existing buttons, we find a place we can solder our wires to the button's copper traces. The way to do this is simple use our sand paper to carefully sand away the black conductive materially on each button's pad. This will reveal the copper pad underneath that we can solder our wires to. NOTE: this copper is very thin, so don't over sand. Figure 6 shows the button pads after I sanded the black material away.

Figure 6: Gamecube controller with button pads sanded to copper and Z and shield buttons removed

Since all of the buttons connect directly to ground, we can solder our ground wire to just one spot marked in figure 6. Figure 7 shows the controller with all the button and light shield circuitry soldered.
Figure 7: All soldered buttons.
Since we are detaching the C-stick from the rest of the controller, we need to lengthen the wire used to connect it to the rest of the controller. We also need to further modify the C-stick circuitry to be able to rotate it 135 degrees in the original controller so that it will operate the most naturally in its new orientation on the final controller (up will be up, down will be down, etc.). This means we'll have to cut the awkward leg on the c-stick pcb (figure 8). Figure 9 shows this modification.

Figure 8: Top and bottom of unmodified C-stick pcb.
Figure 9: Top and bottom of  modified C-stick pcb.
Cutting off the leg also means we need to find a new location to solder our wires. Figure 10 shows this pin-out on both the main pcb and c-stick pcb.

Figure 10: Pin out of C-stick connections on main pcb and C-stick pcb.

TESTING IT ALL (a.k.a. "Show me your moves"):
The easiest way of testing is to start melee and make sure all our inputs are working properly.

Figure 11: Controller pcb after modifications. Non-conductive hot-glue was used on soldered wires for structural support.

Watch me stumble around with making a case! Yay for little to no woodworking experience... There's probably a good reason I'm an electrical engineer and not a mechanical engineer...

Part 3 is HERE!!

About a year ago my best friend's band released an album. I got to preview another album they plan on releasing soon, and am really excited for it. Give their last album a listen!

A better gamecube controller? (Part 1: Electrical Planning)

Recently my friend Fidi, who moved to Colorado, came back to Iowa for a visit. He has recently been suffering from hand issues. He has been playing Super Smash Bros competitive for several years now, but he had to recently cut back to not harm his hands further. We started talking about making a controller that would allow him to continue playing smash without hurting his hands. Something that would be similar to a fight stick, but still allow him to use the GCN controller's joysticks like normal. This sounded like a great project to me and I jumped on the opportunity to help him.

I plan on this project being posted in 5 parts: Electrical Planning, Electrical Execution, Case Planning, Case Execution, and a Reflection on the project as a whole once completed. I am going to try to explain things as fully as possible so people with very little electrical understanding can follow along and possibly mod their own controllers.

Figure 1 is a mock up of the end goal. The right-hand side of the gamecube controller has been replaced with a box with arcade style buttons. The buttons used will be 23mm buttons (as opposed to the normal 30mm) to allow for a slightly smaller form factor and allow the hand to rest more comfortably. The  c-stick from the gamcube controller is mounted sideways on the box to allow the users thumb to rest on the analog stick similar to how it would if you were holding a gamecube controller. The left hand side remains as a controller, but with the left-trigger (L) disabled.

Figure 1: Concept art for finished controller.

Since rolling your hand in towards the thumb is more natural than rolling out towards the pink, the button layout was chosen to allow for the most natural movement while playing. Common advanced tech are wave-dashing (X > R), waveshining(B > X > R > B > X > R >...), jump-cancel grab (Y > Z), rising arials (Y > A), etc. One thing you lose using buttons to replace the triggers is the ability to light shield where you only push the trigger in a little bit. I plan on replacing this with the (r) button.

Lucky for us, Nintendo still makes gamecube controllers. We will be dissecting one of these new gamecube controllers for this project.

Figure 2: New gamecube controller fresh out of the box.

The Unfortunate thing about Nintendo hardware is that it is a pain to get into without a tri-wing screwdriver. Luckily my friend Sam had one he could loan me. Below are what the insides of the controller.

Figure 3: What you see upon opening a gamecube controller

Look at those beautiful pcb's just ready to be analyzed and mutilated modified!!!!!!

After detaching the rumble motor and setting all the plastic bits aside, we are ready to plan out what we are going to do to the board electrically to get our end project. Figure 4 shows the front of our PCB.

Figure 4: Gamecube controller main printed circuit board (pcb).

At this point we need a basic understanding of how a controller recognizes button and trigger presses to make a good plan of how to succeed in a project like this. 

On every controller there is an integrated circuit (IC) that just reads the voltage of its pins and relays this information to the game console. Every pin on the IC corresponds to a different button on the controller. So all we have to do to have the controller recognize when we press a button it to have the button change the voltage of the pins. Figure 5 show a schematic of how we can accomplish having our buttons change the voltage on a pin.

Figure 5: Schematic of button press with equivalent circuit

Electrically the buttons are considered switches. A switch can either be open (not pressed) or closed (pressed). From Figure 5 we can see that, when our switch is open, the voltage of the IC pin is basically at our supply voltag,VCC (5 volts). However, when our button is pressed, the pin is basically connected directly to ground (0 volts). So if we want to replace the existing buttons with new buttons, all we have to do is wire our button in parallel with the existing button as seen in Figure 6.
Figure 6: How we plan to electrically attach our new buttons.
Now that we know how we're going to connect the buttons, the only other electrical modification we need to make so we can light shield by pressing a button (r). In smash you light shield by pressing on of the triggers in a very slight amount, so we need to know how the IC in the controller knows how far the trigger is pressed and how we can emulate this with a button press instead.

Since triggers can take a range of values, the voltage sent to the IC of the controller needs to also be able to take a range of values. This is accomplished with what is known as a potentiometer (pot). Think of a pot as a resistor with a movable tap in the middle of it. As the middle tap moves, the resistance on both sides of the tap move. This forms what's known as a voltage divider seen as the equivalent circuit in Figure 7. The voltage at our IC pin can be expressed as (R2/(R1+R2))*VCC. The resistance of R1 and R2 is the same as the total value of the pot (R1+R2=R) and the value of R2 changes linearly with the change in position of our pot's center tap (R2=position*R where position is between 0 and 1). Plugging those 2 formulas into our voltage divider formula we have that the voltage at our IC pin is position*VCC.

Figure 7: Schematic of gamecube controller's trigger circuit.

So when the trigger is not pressed at all, the pot position is either 0 or 1 and the pin voltage is either 0Vs or 5Vs. We can use a multimeter to measure this voltage to see which one it is, we are going to assume it is pulled to ground (0Vs) when not pressed (I'll change this post if I find it to be the other way). When we are light shielding, the pin voltage is some value between 0 and 5 volts. Figure 8 shows us a circuit that will let us use a button to light shield. 

Figure 8: Desired schematic for light shield button. 

When the button is not pressed no current is flowing, so our IC pin is essentially at 0Vs. When our switch is closed, we essentially have the equivalent circuit for our pot as seen in Figure 7. R2 and R1 are chosen so that their sum is close to the value of the pot (which we can find with a multimeter) and that they give us our desired voltage for light shielding (also found with the multimeter). Notice how the pot doesn't appear in our desired schematic. This means we're going to have to remove it from the PCB.

In the next post we'll take a closer look at the gamecube controller's printed circuit board (pcb), decided where we need to solder our buttons, and then actually execute and test our changes. There will be plenty of pictures, and possibly video!!!!

Part 2: HERE

My friend Ben from back home recently released an EP. It's awesome!!!! You can hear it here:

Thursday, February 27, 2014

Arduino Micro (Leonardo): Detecting if you are still plugged into USB

   I'm a fan of the Arduino Micro's direct USB interface. It's so simple you just plug in your baud rate and you're ready to send and receive serial data from your computer using Serial commands.

|Name: Example of detecting USB Serial              |
|Programmer: Michael James Salino-Hugg              |
|Date: February 27,2014                             |
|Description: Turns on pin 13 LED when USB Serial   |
|             is connected and prints out "Serial   |
|             is connected" every second.           | 
|             Turns pin 13 LED off when there is no |
|             USB Serial connection.                |
void setup(){
   USBCON|=(1<<OTGPADE); //enables VBUS pad

void loop(){
   if(Serial){  //checks state of VBUS
      Serial.println("Serial is connected");
   else {

   However, I have run into one problem with this USB connection. It is as follows. You have your Arduino setup to run one algorithm when it is connected to a computer through USB serial connection and another algorithm when it is not connected to the serial connection. You currently have it connected to the USB and what to disconnect and return to the other algorithm. There are 3 possible scenarios for disconnecting the Arduino from the computer.

  1. The user uses the Serial.end() command the Arduino to terminate the connection. It recognizes that connection is no longer set up using an returns to the correct algorithm.
  2. The user uses their terminal emulator (or terminal) to disconnect the connection. The Arduino recognizes that the connection has been terminated and returns to the correct algorithm.
  3. The user just pulls out the USB cable from either the computer or the Arduino. The Arduino never gets the notice that the connection is being terminated and just keeps running the algorithm it runs when it is connected to the computer despite the fact that it's not.
I would have to say that scenario 3 (the only one with the problem) is the most likely for an average user. I even end up doing this one all the time, and I know very well that I shouldn't. How can you prevent this? You can test this third scenario with the code above. When you unplug the Arduino Micro's USB cable after having a USB Serial connection the pin 13 light will stay on.

   One possible solution is very simple but only if you know your way around the ATMega32U4 (the microprocessor on Arduino Micro) datasheet and Arduino Micro circuit schematic. 

   Looking at the schematic for the Micro, we see that the 5V line from the USB (VUSB) connects directly to the microprocessor at a pin labeled VBUS. Time to pull up the datasheet!

On page 262-263, section 21.11 we see that VBUS can be used to detect if that line is above 1.4 volts This is exactly what we need. We can detect whether we're plugged into a USB port since this pin will be provided 5Vs if it is connected.

To use this we must first enable the VBUS Pad. From section 21.12 of the datasheet we see that OTGPADE (bit 4) of register USBCON. Then we can check VBUS (bit 0) in register USBSTA to see if this line is high or low.

The following code turns on the LED on the top of the Arduino when connected to a USB port, and off when only powered through its VIN or 5V pins:
|Name: Detecting VBUS                               |
|Programmer: Michael James Salino-Hugg              |
|Date: February 27,2014                             |
|Description: Turns on pin 13 LED, establishes a    |
|             serial connection, and prints "Serial |
|             is connected" every second when VBUS  |
|             is high. It also ends the serial      |
|             connection and turns off the pin 13   |
|             LED when VBUS is low.                 |

void setup(){
   USBCON|=(1<<OTGPADE); //enables VBUS pad

void loop(){
   if(USBSTA&(1<<VBUS)){  //checks state of VBUS
      Serial.println("Serial is connected");
   else {

Test this code out the same way. It will always recognize that it's no longer connected to the USB port and end its USB Serial communication.

Tuesday, August 13, 2013

Dead Bug Soldering

The other day at work (I'm doing research at my university), I had some down time and decided that I wanted to see how small I could make the analog section of a circuit I'm working on given the parts we had on hand. I was concerned with the size of the circuit at the time, and doing this actually let me see a better way of laying out the PCB and reducing the size.

The following pictures are my first attempt at dead bug soldering:

If you were wondering the device is a lock-in detector for detecting light at a specific phase and frequency.

I'd say, for a first attempt, it's not bad. The layout is pretty neat and if I had surface mount versions of the large red capacitor and the ICs, the size could still be reduced further, but (most importantly) it was tested and worked!

Saturday, June 29, 2013

Embedded Systems Final Project: Programmable IIR/FIR Digital Filter

For my final project in Embedded Systems I designed a reprogrammable  infinite impulse response (IIR) / finite impulse response (FIR) filter.

This project used a ATmega88pa (a little bit overkill, but it was readily available to us) with a 8 MHz clock, and an 8-bit DAC (AD557JN).  An anti-aliasing lowpass filter before the microcontroller's ADC and an analog reconstruction lowpass filter after the DAC to remove the "stair step" output of the DAC were planned to be implemented.

The program was designed to follow the flow graph shown below. The signal coming in is added to scaled versions of values stored in a circular buffer. This feedback from the buffer creates the IIR part of filter. This value is then stored as the head of the circular buffer. Scaled versions of all the saved values in the buffer are then added together and sent to the DAC as output.

Different filters could be programmed into the filter by simply changing the scaling coefficients stored in the program. These coefficients were determined using MATLAB. We were able to implement the all main types filters (highpass, lowpass, bandpass, notch) with this design.

To ensure that the program would be fast enough to process meaningful signals, the entire project was programmed in assembly. Counting the cycles of the main loop of the program the minimum clock cycles needed for a first order filter was 108 each cycle. With an 8 MHz crystal the theoretical fastest sampling rate was about 37 kHz. That's really good considering that I was hoping to filter signals in the 60-120 Hz range and you can accurately reproduce audio with a sampling rate greater than about 40 kHz.

Unfortunately, I left the anti-aliasing and reconstruction filter design to my partner for this project. They never actually worked. However, using a function generator to create a fairly clean signal we were able to not worry about aliasing for testing purposes, and we were able to use the averaging function on the oscilloscope as an FIR low-pass reconstruction filter. The following oscilloscope screen captures are of a 60 Hz notch filter with a sampling rate of  400 samples per second.

The top plot is the input composed of signals at 42 Hz and 60Hz.
The bottom plot is the 42 Hz output from the 60 Hz notch filter.

The top plot is the input to the filter composed of 130 Hz and 60Hz Signals.
The bottom plot is the output of the 60Hz notch filter.

With a 60 Hz bandpass filter, we measured a bandwidth of about 3 Hz. This corresponds with a Q of about 20 which is really pretty good. We were running short on time and did not get around to monitoring the systems power consumption.

Overall, the programming and idea of the filter worked out great. Here is a picture of the system. It's not pretty. The DAC was soldered to the underside of the board (where all the yellow wires are running to). You will notice we didn't remove the unused USART section from our development board. Ideally the system would be a subsystem of a larger system, and won't need it's own power supply either.

Finished Prototype

The main change I would make to this project would be using 16-bit or 32-bit values rather than 8-bit values throughout the entire project. The inaccuracy in the values made it hard to design for a specific frequency and bandwidth at higher sampling rates. A wider range of frequencies the system can process results in each bit representing an wider range of frequencies. Also it would have been nice to have had the anti-aliasing and reconstruction filters working, and measured the power consumption of the system.