Game Controller V1

This is my make-through for a game controller prototype so sit tight and behold for some great stuff!

Process Map

Background

What Are We Doing Here?

In this project, we will be designing and building a basic game controller to control arcade games on a computer screen as shown.

We will first start with designing the controller on Fusion 360, then move on to the part where we build our electronic circuit on an Arduino board and finally program it to work as a game controller.

Don't worry, this project is actually pretty simple and just requires a basic understanding of programming and electronics concepts. You'll have to be familiar with a CAD tool if you would like to create your own design but that's not necessary since all the files required to get this project done are provided in each section.

So what are we waiting for? Let's get started!


Controlling Pac-Man

Components and Tools

Grab Your Tools and Let's Get to Work

You'll be needing the following components:


Some tools you might need as well:


Machines used:

  • A laser cutter


Software programs used:


Required Components

Cardboard Prototyping

Be Creative

Creativity is the heart of all designs so this is the time to let it all out. I had a potential vision in mind but I didn't have much experience when it came to creating a cardboard prototype. It was my first time doing one so all I did was sketch the outlines of each part on a cardboard and cut them out. Then, I glued the bottom and side parts together using a glue gun. I left the top part unglued to be able to access the inside easily.

Next, I mounted the Arduino board and sensors inside the box using plastics straps. I'd show you where I positioned them but unfortunately, I don't have a photo showing the inside of the prototype since it was thrown out. However, I do have a photo with the end results as shown to the right.

Note: After I was done, I realized that the design was just too big and could have been smaller which I took into consideration in the next step when designing on CAD.


Cardboard Prototype

Trial #1

Designing On Fusion 360

Let's Create our Design

This part was very time consuming for me since I was used to just creating boxes on Fusion 360 and my design this time had curves.

  • Part 1

First thing I did was create the bottom part which wasn't that difficult to do. It's simply consisted of lines. Afterwards, fillets were added for the curved edges. I made holes as well for the screws that'll hold the parts and the Arduino board.


  • Part 2

Next was the side part. I wasn't sure how to do it but after some thorough internet searching, I found out that it could be done using flanges in sheet metal and thus that's what I did. After that, I cut out the screws and bolts places and made a hole at the back for the cable.


  • Part 3

The last part left was the top part which is very similar to the bottom part except that I made holes for the buttons instead of the Arduino board.


And after assembling all parts together, this is how the game console was expected to look like.

Design on Fusion 360

Laser Cutting

Let's Turn our Design into Reality

In order to prepare the design for the laser cutter machine, I exported the top and bottom parts in DXF formats. For the side part, I had to unfold it first by creating a flat pattern. Also, I created living hinges at the curvy parts in order to make the sheet flexible and bendy.

Side Part with Living Hinges

Almost There

So I imported my DXFs to LaserWorks and set the machine's speed to 15 and power to about 75%. Before starting, I adjusted the bed level for an optimum focus.

But Good Things Take Time

So guess what? After I was done with the design and prepared it for laser cutting, I found out that one of the parts, the side part, was just too long to fit the sheet dimensions! Like honestly, I did not see that coming. The side part was one piece that was about 70 cm long. Sadly, the sheet dimensions available were 30 cm × 50 cm.

I decided to go ahead and cut the top and bottom parts to get a feel and see how the design would turn out. Initially, it seemed good enough for me and I could've just divided the side part into 2 different parts and still went with this design but I just decided to make it more compact since there was room for a much smaller design.

Top and Bottom Parts

Trial #2

Designing On Fusion 360

Let's Make it Smaller

I redid my design all over again but this time I made it much smaller. There were a few modifications over the previous design but none that were major or would be considered worth mentioning.

A Much Smaller Design on Fusion 360

Laser Cutting

Here We Go Again

It was time to cut out the design again. I was excited and worried at the same since this seems to be the part where things always go wrong.

So I imported my DXFs to LaserWorks and set the machine's speed, power and focus all same as before. The cutting process took about 10 minutes.

I actually did cut this design more than once since the side part was flimsy and kept breaking off when assembling the parts together. Therefore, I was experimenting with different spaces for the living hinges and with every design I cut, I always modified something else that I thought could be improved such as the buttons positions, the cable opening, etc.... Also, it was my first my time creating a design with screws and nuts since I was just used to attaching parts with slots and gluing anything that didn't fit well so I didn't get the screws slots right from the first time as well. However, I won't go into the details of everything since these changes didn't differ much in the overall design.

Note: Adjusting the focus actually turned out to be more important that you would think. I had to repeat my design once because the focus wasn't that good and the wooden sheet was even a bit warped so I ended up taping down the wooden sheet in the next cutting process.

You can download all the design files used by clicking on the button below.


Importing Files to LaserWorks


Adjusting the Machine's Focus
LaserCutting.mp4
Watching the Machine Work
Cutout Parts

Assembling Parts

It's Finally Happening!

Now, this is my favorite part since it is were your design finally becomes real. Yes I know, we still didn't do the circuit but I tried initially assembling the parts just to make sure everything fits right. I first attached the bottom and side parts together. Then, I added the components to where they should be and finally closed it with the top part as shown to the right.

The screws and nuts were added later on when the prototype was completely finished.


Assembling Parts

Electronics Circuit

It's Okay if You Don't Like Electronics

I think all what's left now is getting it to work. So let's start with the electronics part. Yes I know that most people don't generally enjoy this part much but don't worry, this one is easy.

Why Arduino Leonardo and not UNO?

But before we start, you might have probably wondered why are we using an Arduino Leonardo board since the UNO board is a more popular choice. The major difference between the Uno and Leonardo is that Leonardo has an ATmega32u4 which has support for the USB, whereas the UNO has ATmega328 which doesn't have the USB support onboard. Since Leonardo has USB support onboard, it doesn't require an external microcontroller for USB connection. Thus, the Arduino Leonardo is ideal for projects requiring the board to behave as a USB human interface devices which is exactly what we need. We want to use the Arduino Leonardo board as a keyboard input.

Circuit Wiring

So let's start first with the most important question which is what do we want to do? We have 6 buttons that we want to program such that each one of them performs an action when pressed. More on that in the programming part but all we need to know now is how to connect these buttons in the circuit. Next, we have two sensors that will be used to detect tilt directions. We place the sensors in opposite directions as shown in the schematic so that one of them detects the right and the other detects the left.

The circuit connections are very simple as demonstrated in the schematic. For each button, there is a ground terminal, demonstrated by the black wiring. I soldered all of the buttons' ground together and connected them to one GND pin. The other terminal is just connected to any of the Arduino's INPUT/OUTPUT pins to read the button's state. For the sensors, same thing goes for the ground. Another terminal goes into the 5V pin. Last terminal goes into an INPUT/OUTPUT pin as well to read the sensors' readings.


Electronics Schematic
Connected Circuit

Arduino Programming

Last Thing To Do

Now, we just want to program our Arduino board. I really want to say don't worry, this part was all easy-peasy as well and worked right away but sad to say that this wasn't the case.

The code implementation was very straightforward though so you are probably wondering what was the problem then? Actually, the buttons worked like a charm but for some unforeseen reason, the tilt detection sensors didn't seem to work as expected. I spent hours on it before eventually giving up. This doesn't imply though that it's a programming issue. It could just be a sensor fault.

Initially, we wanted 4 of the buttons for tactile direction controls (left, right, top and bottom). Then, there are two tilt sensors to be used as gesture direction controls (left and right). So we are left now with 2 buttons. One of them is to be programmed as a mode selector, to select between the two modes we have, tactile or sensing. The other button could be used to shoot in a game for instance.

That was the initial plan. but after failing to get the sensors to work properly, I ended up programming one button to shoot in a game, equivalent to pressing ctrl, and the other button to jump in the game, equivalent to pressing space.

So let's dive into the code. First, we'll include the Keyboard.h file to be able to send keystrokes to the computer through our Arduino. Next, I defined my buttons' and sensors' pins in order to make it easier to reference them later on. Remember that's it's always good practice to keep your code clear and clean.

In the setup function, the code there is run once. This is where you set up all the buttons' pins as INPUT_PULLUP and the sensors' pins as INPUT. If you are wondering why INPUT_PULLUP, it's just equivalent to connecting a resistor between the pin and the VCC (5V). This resistor – value estimated between 20k and 50k Ohm – will make sure the state stays HIGH. When you press the button, the states becomes LOW.

In the loop function, this is where we place our main code that runs repeatedly. We want to constantly check if a button is pressed and accordingly take an action. So all we do is place if and else conditions. If a certain button is pressed, let's say the button defined as UP_BUTTON, press the KEY_UP_ARROW, on the keyboard. Otherwise, meaning the button is not pressed, release that key. Same concept is applied to all the buttons we have.

Note: You could either write the key's equivalent decimal or hexadecimal value or use the key name provided in the functions' documentation. You can find it here.

Last thing we have left are the sensors. I mentioned earlier I couldn't get them to function properly but you might have better luck in doing so. I just felt that sometimes they seemed to work correctly but most of the time they didn't. I would tilt the sensor and it would detect the direction correctly one time but the other 10 times, it wouldn't so it seemed unreliable to use. Plus if you think about it, it'll be very challenging to play a game in the sensing mode since the sensors give readings at all times, even when the console isn't tilted which means that in order for it to work correctly, you'll have to be moving either left or right in the game. You can't have a neutral state where you aren't moving left or right because then it'll just give random values so it just all didn't make sense to me to add this mode. However, if you would like to try it out, you can simply define some sort of flag variable in the code to change between the modes. For example, if the flag is equal to 0, then we are in tactile mode. Otherwise, meaning it is equal to 1, we are in sensing mode. Whenever the button is pushed, we toggle the flag. Toggling the flag means that if it was 0, then it'll be 1 and vice versa; if it was 0, then it'll become 1. After that, we have an if condition to check what is the value of the flag and accordingly, decide whether we will be using the buttons or the sensors for directions control. You can find the Arduino code implementation for this below. There are two files included, one with the tilt sensors in case you would like to try it out and the other is without the tilt sensors which is the one I used. You'll notice from the code that I assumed that in the sensing mode that I won't be using any other buttons except the one that changes between modes but that can easily be changed by adding more conditions for the other buttons.

Note: It's very important to test each component on its own at first before integrating all of the components together since it'll be much easier to debug then when things don't work correctly.

You can find the code implementation as an Arduino file by clicking the button below.


Arduino Code

Testing

Let's Play!

I relived my childhood by testing the console on everyone's favorite childhood game, Super Mario.

P.S. I am not much of a fan when it comes to video games so don't mind my gaming skills if they don't seem so great.

SuperMario.mp4
Playing Super Mario

Conclusion

There Is Always Room For Improvement

For a first prototype, I am satisfied with the results. However there are a couple things that could be improved.

  1. The prototype height is currently 5 cm and could be shorter but I was worried about the wires spacing and didn't want to risk it.


  1. Few of the screws weren't in the best positions. Some of the living hinges in the design were too close to the screws openings making this part very fragile while handling.


  1. Much less screws could've been used in the design. Like I used way too many screws (about 26 in total) for assembling the parts together since I wasn't really sure if I'll be able to firmly attach the parts given that there were curves in the design but it turned out that the parts were assembled and attached well without even any screws so adding just a few screws to prevent parts from being snatched out of place would have sufficed.


  1. In my first design, I took into consideration the holes required for mounting the Leonardo board by importing its step file into Fusion 360. However, when I cut it out, some of the holes weren't in the right place. So I just decided to cut out the bottom parts without any holes and drill the holes myself to make sure I place the components in the right spot. Later on, my instructor told me that I could have just used a Vernier Caliper to measure the distances and it would have been as accurate, probably even better since it'll provide cleaner cuts.

Up-close View

That's it everyone. Hope everything was clear and if you have any questions, feel free to contact me at the email below.