Controlling the Game

Teensy 3.6 in a breadboard

Every pinball machine needs a brain behind it. Something to control the lights, keep and display the score, play music and sound effects, and keep track of all the rules and game states. Older machines did this all mechanically, while more modern solid-state machines use a microprocessor. As an electrical engineer, I will, of course, be going down the path of a solid-state pinball machine by using a microcontroller.

Microchip ChipKIT Pro MX7

When I was first conceiving the idea, I wanted to use a PIC32 development board that I already own. It’s the ChipKIT Pro MX7 made by Digilent which features a 32-bit PIC processor and has several available I/O pins. I ran into two problems with this board though. The first was that it’s supposed to be compatible with Arduino, but I ran into numerous issues getting it to program properly. The Arduino IDE, or the bootloader, would fail to properly reset the board whenever a sketch was loaded. The second issue was that the MX7 family of PIC32 processors does not support the I2S audio interface standard.

PicKIT Pro MX7 Microcontroller Development Board by Digilent
PicKIT Pro MX7 Development Board by Digilent

PMods

In preparation for using this PIC32, I bought two PMod modules from Digilent for prototyping. One was an audio Digital to Analog Converter (DAC) that uses the I2S audio standard, and the other was a 128×32 pixel LCD display. PMods is a “standard” hardware interface that Digilent developed to allow their peripherals to be interfaced with the various microcontroller and FPGA development boards that they make. Unfortunately, they don’t list which boards each PMod is compatible with.

I2S Audio Pmod from Digilent
I2S Audio Pmod from Digilent

I2S

I2S stands for Inter-IC Sound, and should not be confused with I2C which is Inter-Integrated Circuit and what most people are familiar with. I2S basically just spits out serially the pulse code modulated (PCM) audio alternating between the left and right channels. This is really handy because WAV files are stored in a PCM format. This is important because you want your microprocessor spending as little time as possible processing the audio and more time keeping track of your game. If you used something like MP3 you’d have to decode that into PCM for most DACs or audio chips. Not to mention that most audio formats, including MP3, are technically licensed. Using WAV files requires no licensing. For a personal project that will never be sold it’s less important of a concern.

Teensy 3.6

So since the MX7 family doesn’t support I2S, I had to look elsewhere. Microchip does offer other families of the PIC32 that support I2S but as an Electrical Engineer, rather than software Engineer, I don’t want to spend the majority of my time writing code from scratch. This is where Arduino comes in. For a hobbyist, the Arduino is ubiquitous with numerous libraries out there to accomplish almost any task you need. The problem with Arduino itself is they’re really slow, older technology, and most have fairly limited I/O capability.

After some many hours of research into custom pinball machines and YouTube videos, I came across a video made by a guy called Ben Heck who was making a miniature pinball table using a Teensy 3.6 that caught my eye. Looking into the Teensy 3.6 it appears to support everything I need and as an added bonus it has a built-in SD card reader. Not only that, but it uses the SD card standard rather than SPI which is far faster. It’s also in a handy (wide) DIP style package making it very easy to prototype on a breadboard and eventually be embedded in a custom PCB.

Teensy 3.6 microcontroller in a breadboard
Teensy 3.6 microcontroller in a breadboard

Key Features Needed

  • I2S channel for audio
  • I2C bus for peripheral communication (bus extenders and LED drivers)
  • SPI bus to keep peripheral options open
  • SD Card
  • General Purpose IO (GPIO)
  • Pulse-Width Modulation (PWM)
  • GPIO Interrupt

The Teensy 3.6 covers all of this and runs at a very fast 180 MHz. As icing on the cake, it’s compatible with the Arduino IDE and most libraries. However, the company that makes it, PJRC, also provides many custom libraries that take advantage of the advanced features of the ARM-based processor it uses that actual Arduinos lack. For example the ability to control multiple I2C busses and SPI busses on top of the SD card and I2S interfaces. The only downside I’ve come across so far is the amount of GPIO isn’t very extensive. A few more pins are available on the underside of the board, but to use these would require a custom PCB and very accurate placement of a surface mount header.

Ladies and gentleman, we have found our microprocessor!

Leave a Reply

Your email address will not be published. Required fields are marked *