Our assignment this week was to build a game controller that can connect to a Wifi network and server using a TCP socket connection to play a multiplayer game that resembles pong. Once the player is connected, his/her IP address will appear within a bar that acts as a paddle to keep the ball from hitting the ground. The objective of the game is to score points by bouncing the ball back and forth between players.
This assignment reminded me of the first assignment from Tangible Interactions last semester — Lunar Lander Game Controller. Since I had a lot of fun building that game controller, I was comfortable with starting on the project and thinking about the UI/UX pretty early on. After Tom set up the server in the hallway, I was able to successfully connect and play the game after changing the IP address in Tom’s Joystick Client code and uploading to a MKR1000.
Next up is designing the user interaction and interface. This is always my favorite part of doing physical computing. I want to always challenge myself against using more conventional sensors/switches so I can learn something new. I originally liked the idea of using a hand-controlled potentiometer for LEFT/RIGHT and a foot pedal potentiometer for UP/DOWN. It’s an interface I’m very comfortable with given my experience with sewing machines. Unfortunately, when I tried wiring it up on a breadboard with a 3.5mm TRS Audio Jack Connector, I kept getting erratic readings in the serial monitor that sometimes not only printed ‘u’ or ‘d’, but random ASCII. This really concerned me and I couldn’t find related documentation online so I decided to set the foot pedal aside for a future project. In retrospect, there’s a chance I didn’t ground it properly (although I followed Adafruit’s instructions to connect one side to ground and the other side to a 10K resistor pull-up to 5V). I’m certain of it now that had I switched from jumper wires to 22-AWG hook-up wires at this prototyping stage, it would have saved me a lot of headache later on.
I ended up going with an ultrasonic sensor (HC-SR04). The clear distinction between the twisting motion mapped to left/right and hovering motion to up/down makes for an intuitive interface:
The problem was, it didn’t work together. I can’t recall how many times I rewired, altered the code, and tested the sensors individually. Koji was very patient and helped me try every combination to debug this controller. Nothing seemed to work until he suggested that we use different wires (providing his own anecdote of dealing with flimsy, unreliable wires in the past). Haley stopped by to also suggest connecting the power rails because apparently, they are not always connected in the long breadboards!
We replaced some of the wires but it still didn’t resolve this issue. It was midnight at this point, so I told Koji I was giving up and he should go home. Half asleep, I looked at my breadboard thinking I can’t let Tom see this hot mess of wires tomorrow morning, I cut and stripped new wires, trimming them all down so everything lay flat. As a last attempt, I connected the controller to the server and motherf***** it worked.
Thank you Koji and Haley for your help!