Building an Android pinball game controller with Arduino

Who doesn’t love an old-school game of pinball? Sure, most of us probably don’t have the space or cash to splash out on a genuine pinball arcade machine for the living room, so we have to make do with playing a virtual version of the game.

Credit: Pacific Pinball Museum

Now I admit, I miss the satisfying thwack of the flippers just as much as anyone else, but we pinball wizards can’t always be in a bar drinking a cold beer, listening to bad heavy metal and stale classic rock tracks.

That being said, I’d be the first one to say that playing pinball on a tablet or phone leaves something to be desired, because you don’t even get the feeling of physically connecting with the game like you would with a PC or console game controller.

Then again, you could always build your own game controller, just like the folks at FunWithDCCircuits who designed a sweet electronic mashup for their Android tablet. Components include a Bluetooth modem, arcade buttons, an NTE 74LS00 Quad2-input NAND gate, 10k 1/6W resistors and an Arduino Uno.

For the uninitiated, the Arduino Uno is a microcontroller board based on Atmel’s stalwart ATmega328. It boasts a total of 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header and a reset button.

Credit: Funwithdc.com

On the software (code) side, the owner of the blog chose not to implement a polling mode driver, as it is too easy to miss events, and the code isn’t quite as clean.

“Instead, I wired the outputs from the SR latches to pins 2 and 3 on my Arduino Uno, which are the external interrupt pins. Any change (press or release) on these pins will trigger an interrupt, and the registered interrupt service routine (ISR) will be called. In the ISR, I simply add the event to a ring buffer, and increment a counter indicating there is work to do in non-interrupt context,” the owner of FunWithDCCircuits explained.

Credit: Funwithdc.com

“Then, inside the loop() function, I check this counter and, if it is non-zero, pull an event off of the ring for processing. In this way, we can ensure that events are processed in the order in which they were received. And given how little code executes in interrupt context, we can be fairly certain that we won’t miss events. One thing to be careful of, though, is disabling interrupts when checking any variable that will be accessed by the ISR.”

Interested? Head over to the source code for a closer look at the software side and the FunWithDCCircuits blog for additional hardware info.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s