Pinball Controller for ipad

Similar documents
Interior Purse Light. Created by Becky Stern. Last updated on :41:08 PM UTC

Arduino Lesson 6. Digital Inputs

Coffee Detonator: The TNT Plunger Grinder

Mad Science Test Tube Rack

Android GBoard Morse Code Control with Circuit Playground Express

Neon LED Signs. Created by John Park. Last updated on :11:09 PM UTC

i2c/spi LCD Backpack Created by lady ada Last updated on :11:04 PM UTC

Magical Mistletoe. Created by Leslie Birch. Last updated on :45:29 PM UTC

Interactive Gift Box. Created by codingpro. Last updated on :47:40 AM UTC

Adafruit Capacitive Touch Sensor Breakouts

Adafruit IO Basics: Digital Output

NeoPixie Dust Bag with Circuit Playground Express

Circuit Playground Digital Input

Chirping Plush Owl Toy

Bunny Ears with MakeCode

Clockwork Goggles. Created by John Park. Last updated on :03:10 PM UTC

Portable Apple Watch Charger

Feather Weather Lamp. Created by Ruiz Brothers. Last updated on :54:26 PM UTC

LED Lightbox. Created by Sam Clippinger. Last updated on :50:00 AM UTC

Crawling Baby Sea Turtle Robot

Mystery Box: Haunted Radio

Trinket-Powered Conference Room Occupancy Display

Audio Prank Gift Box. Created by Becky Stern. Last updated on :46:15 PM UTC

FLORA TV-B-Gone. Created by Becky Stern. Last updated on :32:57 PM UTC

Wind Blowing Emoji Prop

'Sup Brows. Created by Kate Hartman. Last updated on :52:04 PM UTC

Adafruit DRV2605 Haptic Controller Breakout

Adafruit PowerBoost 500 Shield

Trinket NeoPixel LED Longboard

TSL2561 Luminosity Sensor

NeoPixel Ring Bangle Bracelet

Circuit Playground Express Laser Tag

Trellis 3D Printed Enclosure

Reindeer Mask with Animated Eyes

Adafruit TPL5110 Power Timer Breakout

Toy Car Speed Timer. Created by Kirby Griese. Last updated on :13:49 PM UTC

Adafruit Color Sensors

Bluetooth Controlled NeoPixel Headphones

Adafruit VL53L0X Time of Flight Micro-LIDAR Distance Sensor Breakout

ISS Pin. Created by Leslie Birch. Last updated on :27:30 PM UTC

Monochrome OLED Breakouts

Adafruit IO Basics: Digital Input

Adafruit APDS9960 breakout

Alohamora Bottle. Created by Erin St Blaine. Last updated on :58:53 PM UTC

Adabot Operation Game

Adafruit MPRLS Ported Pressure Sensor Breakout

Mystery Box: NeoMatrix Mk I

Adafruit LED Sequins. Created by Becky Stern. Last updated on :02:00 AM UTC

Sino:bit with Arduino

Circuit Playground Yoyo

Crickit Dancing Marionette Kit Created by Dano Wall. Last updated on :03:11 PM UTC

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :42:16 PM UTC

Ping Pong Ball Launcher

Pushrod Garage. Created by John Park. Last updated on :07:30 PM UTC

Adafruit IO Basics: Analog Input

Adafruit TPL5111 Reset Enable Timer Breakout

Celebration Spectacles

NeoMatrix 8x8 Word Clock

Paper Airplane Launcher

Stumble-Bot. Created by Dano Wall. Last updated on :04:06 AM UTC

Using IFTTT with Adafruit IO to Make an IoT Door Detector

Adafruit LED Sequins. Created by Becky Stern. Last updated on :00:06 PM EST

Naughty or Nice Machine

PyPortal NeoPixel Color Picker Created by Kattni Rembor. Last updated on :42:41 PM UTC

Infinity Mirror Valentine's Candy Box

LED Eyes. Created by Ruiz Brothers. Last updated on :50:55 AM UTC

Slider Crank Mechanism -- from Cardboard and Craft Sticks

GPS Logging Dog Harness

Adafruit ATWINC1500 WiFi Breakout

Adafruit Mini TFT " 160x80

Adafruit GPIO Expander Bonnet for Raspberry Pi Created by Kattni Rembor. Last updated on :12:47 PM UTC

Circuit Playground Express Head-Tilt Ears

Prophet 600 GliGli mod

Light-Up Angler Fish Embroidery

Solar Boost Bag. Created by Becky Stern. Last updated on :44:55 PM UTC

Snake Charmer Box. Created by Dano Wall. Last updated on :07:25 PM UTC

Ring Doorbell is 4.98 x 2.43 x 0.87 inches, x 6.17 x 2.21 cm.

Crickit Carnival Bumper Bot

Tent Lantern. Created by Timothy Reese. Last updated on :17:25 AM UTC

Sword & Wand Prop Effects with Circuit Playground

Guardian Shield+ Zelda Breath of the Wild

Joy Featherwing. Created by Dean Miller. Last updated on :03:07 PM UTC

Adafruit IO Basics: Color

DIY Wireless DDR Dance Pad with Bluefruit EZ-Key

1.8" TFT Display Breakout and Shield

Crawling Animatronic Hand

3D Printed Google AIY Voice Kit

Adafruit IO Basics: ESP Arduino

Bike Wheel POV Display

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :30:55 PM EST

Raspberry Pi Selfie Bot

CircuitPython Media Dial

Lie Ren's Stormflower Gun Blade

Adafruit Mini TFT with Joystick Featherwing

3D Printed 20w Amplifier Box

Hammer Time Mini Golf Hazard with Crickit

MCP Bit DAC Tutorial

CPX Mystery Dreidel. Created by Kathy Ceceri. Last updated on :51:40 PM UTC

DIY Bluetooth Gamepad

Adafruit AMG8833 8x8 Thermal Camera Sensor

Transcription:

Pinball Controller for ipad Created by John Park Last updated on 2017-08-12 12:07:06 AM UTC

Guide Contents Guide Contents Overview icade Standard Parts Code the Teensy Keyboard Mapping Test Code Controller Code Full Code Duo Pinball Teardown Open it Up Identify the Parts Remove Old Board Prep the Wires Wire Common Ground USB Wiring Hole Teensy Transplant Be a Pinball Wizard 2 3 4 6 8 9 10 15 18 27 28 33 34 36 45 47 54 58 Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 2 of 65

Overview Playing virtual pinball on an ipad is a whole lot of fun! Pinball Arcade is my personal favorite -- it runs a huge selection of classic tables reproduced down to the finest detail, and the physics are incredibly accurate and satisfying. Not so satisfying, however is the lack of tactile feedback when tapping the screen to trigger the flippers or sliding your finger down the screen to pull and release the plunger. So how about using real arcade buttons and a spring loaded plunger instead? Originally intending to build my own from scratch, I ran across an old accessory called the Duo Pinball controller, which is available online for less than $9 new! (it retailed for $60 when launched in 2012). It was designed for a different pinball game, Pinball HD Collection, and isn't compatible with the one I prefer, but it didn't take too much effort to transplant a new brain in it and make it work! This guide will show you how to mod your own controller, or use these techniques to build your own from scratch. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 3 of 65

icade Standard The Duo Pinball controller was locked into a singel game, using a Bluetooth board to pair with the ipad and send proprietary commands. In order to free it from these shackles, we'll need to swap out the electronics for something that can use a different ios game controller standard. One such standard is the icade (http://adafru.it/xsc) protocol, made by ION Audio for their line of ipad desktop arcade cabinets and controllers. It too requires the games you play to support the standard, but in the case of icade, there are many, many such games, including my beloved Pinball Arcade! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 4 of 65

The icade standard interfaces with ios as an HID keyboard, and is typically paired over Bluetooth. However, plugging in a wired HID keyboard works just as well, which makes it very straightforward to build your own controller! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 5 of 65

Parts You'll need just a few things to mod or build an icade-compatible controller for ipad or iphone: a microcontroller that can act as a USB HID keyboard, and draws less than 200 ma of current, such as the Teensy 3.2 an adapter for the ios device to connect USB to the Lightning port, such as the Apple USB to Lightning Camera Adapter. (http://adafru.it/xsd) (If you have an older ipad or iphone you will need the 30-pin dock connector version of the camera kit) micro B to A USB cable arcade buttons and an enclosure (such as a shoebox), or the Duo Pinball controller to hack Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 6 of 65

1 x Teensy Teensy 3.2 microcontroller Add To Cart 3 x Arcade Button 30mm arcade button -- only needed if not using the Duo Pinball controller Add To Cart 1 x USB cable A/Micro B Add To Cart 1 x 4.7K resistor 4.7K resistor -- optional, for dimming the indicator LED Add To Cart Next, let's get the Teensy coded to act like an icade controller! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 7 of 65

Code the Teensy Let's look a bit closer at the icade standard. If you head to the icade page on ION Audio's site (http://adafru.it/xse) you'll see a link to the spec (http://adafru.it/xsf). In this.pdf it states: The ION Arcade family of products communicates through Bluetooth wireless technology, using a specific key map and protocol to talk with the applications. For each button pressed, the ION Arcade hardware device sends a Key Down character (when button is pressed or joystick is moved directionally) and a Key Up character (when the button is released, or the joystick is moved from its location). The application being made to work with the ION Arcade hardware device will need to be able to interpret these commands, as Key Up and Key Down characters are necessary for successful Application Submissions. Note, they say that it is a Bluetooth connected protocol, but in reality, a hard wired keyboard device works just as well. So, instead of dealing with the complexities, pairing, and power consumption of a Bluetooth device, we can instead program a Teensy to press the keys for us over a USB cable! The Teensy is going to act as a USB HID keyboard so that it can "type" the keystrokes that the icade standard uses. Here's what the button mapping looks like for the standard icade: Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 8 of 65

Keyboard Mapping The first test I performed was to figure out the key mappings needed. I did so by pairing a Bluetooth keyboard to the ipad, launching Pinball Arcade, and setting the controller type to icade in the game's settings. Then, I typed the key pairs seen in the diagram above until I knew which key combos did what. The mapping for pinball looks like this: Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 9 of 65

There are also additional key mappings for a few table tilt directions, so you could probably implement those with physical tilt or vibration sensors! Test Code The next test I did was to have the Teensy press the flipper buttons by telling it to "type" the "LVHR" combo over and over. Here's how you can make the Teensy type the keystrokes. First, make sure you've followed these basic guide to setting up the Arduino IDE (http://adafru.it/jdq), and installing (http://adafru.it/xsa) and using the Teensy board (http://adafru.it/xsb). Once you've successfully uploaded the basic Blink sketch to your Teensy, move on to the next step. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 10 of 65

Load the Simple.ino sketch found in the Arduino IDE under File > Examples > Teensy > USB_Keyboard > Simple Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 11 of 65

Make sure your Arduino IDE board settings are set up for the Teensy as seen here, including the USB type as Keyboard, plug in the Teensy over USB, launch the Teensy loader application, and then upload the sketch. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 12 of 65

Once the program is uploaded, place your cursor in a text field and you'll see that the Teensy will type the words "Hello World" followed by in incrementing number. Let's adjust this program so that it types the keystrokes for the pinball flippers. Remember, in the icade standard it is a keystroke to press a button and a second, different keystroke to release the button. "hr" controls the left flipper, and "lv controls the right flipper. Despite the chart from the icade spec showing upper case letters, it actually recognizes lower case instead. //Pinball Arcade Controller Test //Uses Teensy 3.2 to act as icade interface to The Pinball Arcade on ipad //John Park for Adafruit /* Simple USB Keyboard Example Teensy becomes a USB keyboard and types characters You must select Keyboard from the "Tools > USB Type" menu Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 13 of 65

*/ void setup() { Serial.begin(9600); delay(1000); } void loop() { // Your computer will receive these characters from a USB keyboard. Keyboard.print("h"); delay(100); Keyboard.print("l"); delay(100); Keyboard.print("r"); delay(100); Keyboard.print("v"); } Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 14 of 65

OK, time to test it on the ipad or iphone! Open your notepad app on the ios device, and then plug the Teensy into it with a USB micro B/A cable and the USB to Lighting "camera adapter". It will start typing those letters furiously! rvhlrvhlrvhlrvhlrvhlrvhlrvhlrvhlrvhlrvhlrvhlrvhlrvh Unplug the Teensy before you proceed. Next, let's see it flip those flippers. Install The Pinball Arcade (http://adafru.it/xsc) from the App Store, and then launch it. In the settings (gear icon on the main screen) tap the icade button so that it reads icade: ipad Now, launch a table, and press START. Before you pull the plunger, plug in the Teensy. After a moment you'll see the flippers start to go! Launch the ball and watch as the random flipper spamming manages to play a fairly decent game of pinball! Controller Code Now, let's program the Teensy to use the real button presses to send the keystrokes. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 15 of 65

//Pinball Arcade Controller Test //Uses Teensy 3.2 to act as icade interface to The Pinball Arcade on ipad //John Park for Adafruit /* USB Keyboard button state example Teensy becomes a USB keyboard and types characters You must select Keyboard from the "Tools > USB Type" menu */ #define LED_PIN 13 #define RIGHTFLIPPER_PIN 12 int buttonstate = 0; //variable to store current state of button int laststate = 1; //variable to store state of last button press void setup() { pinmode(led_pin, OUTPUT); digitalwrite(led_pin, HIGH); //turn on LED so we know it's on pinmode(rightflipper_pin, INPUT_PULLUP); } void loop() { buttonstate = digitalread(rightflipper_pin); if(buttonstate==low && buttonstate!= laststate){ //it's been pressed Serial.println("Flipped "); Keyboard.print("l"); delay(100); digitalwrite(led_pin, LOW); //blink off the LED laststate=0; } else if(buttonstate==high && buttonstate!= laststate){ //it's been released Serial.println(" Not flipped"); Keyboard.print("v"); delay(100); digitalwrite(led_pin, HIGH); //turn back on the LED laststate=1; } } Copy and upload this to your Teensy, then use a jumper wire to short pin 12 to ground and release it. Each time you do, the LED will blink and it will send an "l" and a "v". Plug this in to your ipad and try it out as the right flipper button. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 16 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 17 of 65

Full Code In researching the icade standard I came across an excellent project by Allen C. Huffman (http://adafru.it/xsd) that uses a Teensy as an icade gamepad controller. You can use that code and the pin mappings for this project, too! I made some small adjustments to the code, and included keyboard mapping comments in line. Copy the code seen here, and upload it to your Teensy. Here are the mappings: Plunger on pin 1 Left flipper on pin 8 Right flipper on pin 12 LED on pin 13 /*----------------------------------------------------------------------------- Teensy icade Input by Allen C. Huffman (alsplace@pobox.com) http://subethasoftware.com/2013/01/04/teensy-2-0-icade-source-code/ Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 18 of 65

Monitor digital inputs, then emit a USB keyboard character mapped to an icade button depending on the pin status. The character will be the "hold" character for pin connected (N.O. button push) and "release" character for pin disconnected (N.O. button released). Pin 13 is used for lighting the onboard LED as a "we are alive" indicator. This software was written to allow a Teensy 2.0/3.2 to interface between arcade buttons and an ipad via USB and Camera Connector Kit. 2012-12-04 0.0 allenh - Initial version, based on my ArduinoAIDI code. minor adjustments by john park, July 2017 for Pinball Arcade */ #define VERSION "0.0" #define LED_OFF //#include <eeprom.h> //#include <avr/wdt.h> /* icade keyboard mappings. See developer doc at: http://www.ionaudio.com/products/details/icade WE YT UF IM OG AQ< -->DC XZ HR JN KP LV Atari joystick port, looking at the male DB9 on the Atari. See: http://old.pinouts.ru/inputs/joystickatari2600_pinout.shtml 1 2 3 4 5/ Up Dn Lt Rt PA 6 7 8 9/ Bt +5 Gd PB */ /* The following I/O pins will be used as digital inputs for each specific icade function. */ #define UP_PIN 0 #define DOWN_PIN 1 //icade plunger #define LEFT_PIN 2 #define RIGHT_PIN 3 #define BTN1_PIN 4 #define BTN2_PIN 5 #define BTN3_PIN 6 #define BTN4_PIN 7 #define BTN5_PIN 8 // icade left flipper #define BTN6_PIN 9 #define BTN7_PIN 10 #define BTN8_PIN 12 // icade right flipper /* Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 19 of 65

The following keys are the icade sequence (hold, release) for each function. Send "W" to indicate UP, and "E" when UP is released. */ #define UP_KEYS "we" #define DOWN_KEYS "xz" //icade plunger original key order "xz" //#define DOWN_KEYS "zx" //icade plunger flipped order for NC switch wiring #define LEFT_KEYS "aq" #define RIGHT_KEYS "dc" #define BTN1_KEYS "yt" #define BTN2_KEYS "uf" #define BTN3_KEYS "im" #define BTN4_KEYS "og" #define BTN5_KEYS "hr" // icade left flipper #define BTN6_KEYS "jn" #define BTN7_KEYS "kp" #define BTN8_KEYS "lv" // icade right flipper #define DI_PIN_COUNT 12 // 12 pins used. #define DI_PIN_START 1 // First I/O pin. #define DI_PIN_END 20 // Last I/O pin. byte mypins[di_pin_count] = {UP_PIN, DOWN_PIN, LEFT_PIN, RIGHT_PIN, BTN1_PIN, BTN2_PIN, BTN3_PIN, BTN4_PIN, BTN5_PIN, BTN6_PIN, BTN7_PIN, BTN8_PIN}; char icadekeymap[][di_pin_count] = {UP_KEYS, DOWN_KEYS, LEFT_KEYS, RIGHT_KEYS, BTN1_KEYS, BTN2_KEYS, BTN3_KEYS, BTN4_KEYS, BTN5_KEYS, BTN6_KEYS, BTN7_KEYS, BTN8_KEYS}; char icadedesc[][di_pin_count] = {"Up", "Down", "Left", "Right", "Btn1", "Btn2", "Btn3", "Btn4", "Btn5", "Btn6", "Btn7", "Btn8"}; /* We want a very short debounce delay for an arcade controller. */ #define DI_DEBOUNCE_MS 10 // 100ms (1/10th second) #define LED_PIN 11 #define POWER_LED 13 //to show power on #define LEDBLINK_MS 1000 /*---------------------------------------------------------------------------*/ /* For I/O pin status and debounce. */ unsigned int digitalstatus[di_pin_count]; // Last set PIN mode. unsigned long digitaldebouncetime[di_pin_count]; // Debounce time. //unsigned long digitalcounter[di_pin_count]; // Times button pressed. unsigned int digitaldebouncerate = DI_DEBOUNCE_MS; // Debounce rate. /* For the blinking LED (heartbeat). */ unsigned int ledstatus = LOW; // Last set LED mode. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 20 of 65

unsigned long ledblinktime = 0; // LED blink time. unsigned int ledblinkrate = LEDBLINK_MS; // LED blink rate. unsigned int pinson = 0; /*---------------------------------------------------------------------------*/ void setup() { // Just in case it was left on... //wdt_disable(); // Initialize the serial port. Serial.begin(9600); // Docs say this isn't necessary for Uno. //while(!serial) { } showheader(); // Initialize watchdog timer for 2 seconds. //wdt_enable(wdto_4s); // LOW POWER MODE! // Pins default to INPUT mode. To save power, turn them all to OUTPUT // initially, so only those being used will be turn on. See: // http://www.pjrc.com/teensy/low_power.html for (int thispin=0; thispin < DI_PIN_COUNT; thispin++ ) { pinmode(thispin, OUTPUT); } // Disable Unused Peripherals // ADCSRA = 0; // Initialize the pins and digitalpin array. for (int thispin=0; thispin < DI_PIN_COUNT; thispin++ ) { // Set pin to be digital input using pullup resistor. pinmode(mypins[thispin], INPUT_PULLUP); // Set the current initial pin status. digitalstatus[thispin] = HIGH; //digitalread(thispin+di_pin_start); // Clear debounce time. digitaldebouncetime[thispin] = 0; //digitalcounter[thispin] = 0; } // Set LED pin to output, since it has an LED we can use. pinmode(led_pin, OUTPUT); pinmode(power_led, OUTPUT); digitalwrite(power_led, HIGH); Serial.println("Ready."); Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 21 of 65

} /*---------------------------------------------------------------------------*/ void loop() { // Tell the watchdog timer we are still alive. //wdt_reset(); #ifndef LED_OFF // LED blinking heartbeat. Yes, we are alive. if ( (long)(millis()-ledblinktime) >= 0 ) { // Toggle LED. if (ledstatus==low) // If LED is LOW... { ledstatus = HIGH; //...make it HIGH. } else { ledstatus = LOW; //...else, make it LOW. } // Set LED pin status. if (pinson==0) digitalwrite(led_pin, ledstatus); // Reset "next time to toggle" time. ledblinktime = millis()+ledblinkrate; } #endif // Check for serial data. if (Serial.available() > 0) { // If data ready, read a byte. int incomingbyte = Serial.read(); // Parse the byte we read. switch(incomingbyte) { case '?': showstatus(); break; default: break; } } /*-------------------------------------------------------------------------*/ // Loop through each Digital Input pin. for (int thispin=0; thispin < DI_PIN_COUNT; thispin++ ) { // Read the pin's current status. unsigned int status = digitalread(mypins[thispin]); // In pin status has changed from our last toggle... if (status!= digitalstatus[thispin]) { Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 22 of 65

// Remember when it changed, starting debounce mode. // If not currently in debounce mode, if (digitaldebouncetime[thispin]==0) { // Set when we can accept this as valid (debounce is considered // done if the time gets to this point with the status still the same). digitaldebouncetime[thispin] = millis()+digitaldebouncerate; } // Check to see if we are in debounce detect mode. if (digitaldebouncetime[thispin]>0) { // Yes we are. Have we delayed long enough yet? if ( (long)(millis()-digitaldebouncetime[thispin]) >= 0 ) { // Yes, so consider it switched. // If pin is Active LOW, if (status==low) { // Emit BUTTON PRESSED string. Serial.print(iCadeDesc[thisPin]); Serial.print(" pressed (sending "); Serial.print(iCadeKeymap[thisPin][0]); Serial.println(" to icade)."); Keyboard.print(iCadeKeymap[thisPin][0]); //digitalcounter[thispin]++; pinson++; #ifndef LED_OFF digitalwrite(led_pin, HIGH); #endif } else { // Emit BUTTON RELEASED string. Serial.print(iCadeDesc[thisPin]); Serial.print(" released (sending "); Serial.print(iCadeKeymap[thisPin][1]); Serial.println(" to icade)."); Keyboard.print(iCadeKeymap[thisPin][1]); if (pinson>0) pinson--; if (pinson==0) digitalwrite(led_pin, LOW); } // Remember current (last set) status for this pin. digitalstatus[thispin] = status; // Reset debounce time (disable, not looking any more). digitaldebouncetime[thispin] = 0; } // End of if ( (long)(millis()-digitaldebouncetime[thispin]) >= 0 ) } // End of if (digitaldebouncetime[thispin]>0) } else // No change? Flag no change. { // If we were debouncing, we are no longer debouncing. digitaldebouncetime[thispin] = 0; } } // End of (int thispin=0; thispin < DI_PIN_COUNT; thispin++ ) Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 23 of 65

} /*---------------------------------------------------------------------------*/ void showheader() { int i; // Emit some startup stuff to the serial port. Serial.print("iCadeTeensy "); Serial.print(VERSION); Serial.println(" by Allen C. Huffman (alsplace@pobox.com)"); Serial.print(DI_PIN_COUNT); Serial.print(" DI Pins ("); for (i=0; i<di_pin_count; i++) { Serial.print(myPins[i]); Serial.print("="); Serial.print(iCadeDesc[i]); Serial.print(" "); } Serial.print("), "); Serial.print(digitalDebounceRate); Serial.println("ms Debounce."); } /*---------------------------------------------------------------------------*/ void showstatus() { showdigitalinputstatus(); } /*---------------------------------------------------------------------------*/ void showdigitalinputstatus() { Serial.print("DI: "); for (int thispin=0; thispin < DI_PIN_COUNT; thispin++ ) { // Read the pin's current status. Serial.print(iCadeDesc[thisPin]); Serial.print("="); Serial.print(digitalRead(myPins[thisPin])); Serial.print(" "); //Serial.print(" ("); //Serial.print(digitalCounter[thisPin]); //Serial.print(") "); } Serial.println(""); } /*---------------------------------------------------------------------------*/ Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 24 of 65

// End of file. If you don't have the Duo Pinball controller you can skip to the last page of the guide (http://adafru.it/xse) and wire up three arcade buttons instead, put them in a cardboard enclosure, and you'll be ready to play! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 25 of 65

To modify the Duo Pinball controller and transplant the Teensy into it, move on to the next page. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 26 of 65

Duo Pinball Teardown Let's take apart the Duo Pinball controller and have a look inside. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 27 of 65

Open it Up Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 28 of 65

Using a #1 Philips screwdriver, remove the seven screws that hold together the case. Note, two of the screws are hiding under the rubber feet, so go ahead and peel them off and save them for later. Now, pry open the case using a spudger or slotted screwdriver. Be careful not to pull to hard on the wire that connects the LED to the board -- you can remove the piece of tape that holds it in Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 29 of 65

place so you can lay both halves side by side. Now, pry open the case using a spudger or slotted screwdriver. Be careful not to pull to hard on the wire that connects the LED to the board -- you can remove the piece of tape that holds it in place so you can lay both halves side by side. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 30 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 31 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 32 of 65

Identify the Parts Inside you'll see a few key elements: Controller board Left flipper button momentary switch Right flipper button momentary switch Plunger momentary switch and IR sensor Plunger/spring assembly Battery box Indicator LED Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 33 of 65

Remove Old Board Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 34 of 65

You can unplug each of the cables from the main board now, and then unscrew it. We won't be using it, so you can set it aside in your old electronic junk pile. One curiosity is the reset button on the back. Mysterious! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 35 of 65

Prep the Wires To prep the wires, first remove the battery box wires, we won't use them. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 36 of 65

Next, snip the connectors off of the remaining wires running from both buttons, the plunger sensor, and the LED indicator. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 37 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 38 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 39 of 65

The plunger sensor board is pretty darned nifty! It's got a momentary snap action switch on it to detect the plunger "closed/opened" state, as well as an IR distance sensor to determine the position of the plunger! We'll only use the switch, since the icade standard doesn't have a way to express the analog value of plunger position to the game. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 40 of 65

You can test the button wiring with the continuity testing mode on your multimeter -- the plunger switch actually has two modes you can use depending on which wires you connect. The white wire, labeled SIN on the board, is a constant, so connect your first lead to it. If you connect the other lead to the red VCC wire the switch is normally closed (NC) as seen here. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 41 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 42 of 65

Instead, if you connect the second lead to the black GND wire, it is is normally open (NO). Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 43 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 44 of 65

You could pick either one and then make an adaptation in software (I chose red originally when I built one on the video live stream and then reversed the key commands in the Arduino sketch to make it work) but let's look at the way the plunger works to decide the best method. The plunger resting position keeps the switch pushed down. So, when the software checks it, we don't want it to react to the resting state. By choosing the black wire, we can have the software see that switch as open (what we'd colloquially call "unpressed" even though it is physically pushed in). Then, when the plunger is pulled back it will register the switch as closed (what we'd called "pressed" again, even though the button is now no longer pushed in), and send the keystroke to the game. So, the black wire is the one we'll go with when it's time so solder! Wire Common Ground Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 45 of 65

To simplify the wiring runs back to the board later, we can solder all of the black ground wires to each other, and then make a single connection to the Teensy board. This is good if you want to keep things small, since the Teensy 3.2 only has a single GND pin exposed, and this allows us to avoid adding perf board with an extra ground rail. Cut and strip a short length of black wire to add to the bundle. Twist and solder them all together, or use a wire Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 46 of 65

splice tap to connect them, leaving the free end of the added wire to solder to the Teensy later. You can add a bit of heat shrink tubing to insulate the connection. USB Wiring Hole Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 47 of 65

One other bit of prep to do here is to create a hole in the case for the USB cable. I made mine in the back of the battery box using a 5/8" Forstner bit in a power drill, but you can use a Dremel, saw, hand drill, or any other method you like so long as you can fit the small end of the cable through. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 48 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 49 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 50 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 51 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 52 of 65

Now it's time to transplant the Teensy! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 53 of 65

Teensy Transplant Your controller is now ready for its new brain! You'll wire and solder these connections: Switch common ground black wires to Teensy GND Plunger white wire to Teensy pin 1 Left flipper red wire to Teensy pin 8 Right flipper red wire toteensy pin 12 LED anode red wire (or blue if you prefer the blue glow) to Teensy pin 13 LED cathode black wire to a 4.7K resistor and then to common GND The resistor isn't strictly required -- the LED is just very bright without it! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 54 of 65

When you solder the resistor in line with the LED, you can add heat shrink tubing over the resistor to insulate it. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 55 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 56 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 57 of 65

After you've soldered the wires, test it out to make sure everything works as planned. Be a Pinball Wizard You're just about ready to play! Carefully close up the controller case, being careful not to pinch any of the wires. You can use some hot glue or tape to keep the USB wire in place. Then, screw in the case screws and reapply the rubber feet. If the original adhesive isn't enough to keep them in place, you can use some double stick tape. Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 58 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 59 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 60 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 61 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 62 of 65

Now, turn on your ipad or iphone, launch the game, and plug in the controller USB cable to the Lightning connector and into the ipad. The LED will light up, and you're all set. Have fun playing virtual pinball with physical controls! Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 63 of 65

Adafruit Industries https://learn.adafruit.com/pinball-controll-ipad Page 64 of 65

Adafruit Industries Last Updated: 2017-08-12 12:07:05 AM UTC Page 65 of 65