ControlBlock: Power Switch, Game Controllers, and I/O for the Raspberry Pi

ControlBlockThe RetroPie Project has motivated many people to build their own gaming stations. Two issues regularly came up in discussions about these projects:

First: What is a simple solution for turning the Raspberry Pi on and off with a power switch in a smarter way than cutting the power supply and risk data loss?

Second: What is a simple way for connecting arbitrary arcade controllers to the RPi?

Arcade Controllers

There exist individual solutions for both use cases: You can get power switch solutions for the Raspberry Pi as well as input accessories that can be connected to the RPi via USB. However, I wanted to have a more compact and neatly integrated solution – something that provides a whole bunch of general purpose input and output pins together with a reliable and intuitive power switch solution.

Introduction

The ControlBlock is an add-on board for the Raspberry Pi (version 1, 2, and 3) models A+ and B+. It provides a microcontroller-based power-switch functionality as well as two General Purpose Input/Output (GPIO) Expanders with overall 32 pins so that you are able to connect quite anything you like to it.

Besides the hardware itself, a driver software is presented here, that allows for an easy installation and configuration of the ControlBlock functionalities, especially the connection of game controllers. Currently, the driver supports these game pad types:

  • Arcade Controllers
    Connect any controllers that are based on microswitches and the driver will map these either to two distinct game pads or to keyboard presses with MAME layout, which can be seen as the de facto standard in this field.
  • SNES Controllers
    The driver also supports the polling scheme of Super Nintendo Entertainment (SNES) controllers. Currently, the driver supports up to two SNES controllers that can be attached to the ControlBlock.
  • NES Controllers
    Since Nintendo Entertainment System (NES) controllers and SNES controllers are so similar in their hardware, the driver also supports up to two NES controllers.

The sources of the driver are publicly available at Github and can be further enhanced to support additional controllers in the future.

In the following, details are given for the individual features that are mentioned above. Functionalities, dimensions, and hardware interfaces are described first. Then, the assembly is described in more details. After that, the configuration and a demonstration video is presented. A conclusion is given at the end of this article.

Functionalities

The ControlBlock provides two main functionalities that can be used independently from each other:

  1. Power Switch
    The Raspberry Pi comes without a power switch. As soon as you plug the micro USB cable into the RPi, it turns on. If you want to shutdown the RPi, you need to call a shutdown command to to bring the system into a state in which you can safely remove the USB cable again.
    The ControlBlock provides a connector for a toggle switch to control the power supply of the RPi. Furthermore, it provides a connector for an LED to indicate whether the RPi is off, booting, running, or shutting down. The power supply is controlled by a tiny microcontroller that monitors the button state as well as the state of the RPi and switches a MOSFET accordingly. This means that there is no need anymore to plug and unplug the USB cable from the RPi if you want to completely turn your RPi off.

  2. General Purpose Input/Output and Game Controllers
    The 2×40 pins header of the Raspberry Pi already comes with a bunch of GPIO pins that can be used for all kinds of things to control and sense. However, these pins go directly into the main controller of the RPi and there is no further circuitry protection. Also, if you want to attach a set of arcade controllers, this task can become quite troublesome. The ControlBlock comes with two GPIO expanders MCP23017: Overall, you have 32 additional GPIO pins that can be controlled via the I2C interface of the RPi. The GPIOs can be accessed with terminal blocks that also provide cable protection. And if you accidentally create a short circuit you do not have to fear to fry your whole Raspberry with that then.

Also, if you want to connect your RPi to any kind of game controllers, you have to decide which GPIO pins to use and you must adapt your driver software such that exactly these pins are controlled. The ControlBlock makes the task of connecting game controllers to the Raspberry Pi very easy: The ControlBlock PCB is clearly marked with pin outs for players 1 and 2 and the provides driver software for the ControlBlock can easily be configured for different controller types.

Dimensions and Interfaces

Dimensions

The dimensions of the ControlBlock PCB are chosen such that it exactly matches the mounting holes of the Raspberry Pi models A+ and B+. The ControlBlock PCB comes with the same round corners as the Raspberry itself. Of course, these round corners provide no further functionalities, but give the whole setup a neat look. Regarding the GPIO usage the ControlBlock is attached to the first 2×6 pins of the Raspberry Pi GPIO header.

The ControlBlock does not fit the Raspberry Pi models A and B. The reasons for this are the composite out connector and the missing mounting holes of the Raspberry Pi models A and B.

Hardware Interfaces

Here is a top-view of the ControlBlock PCB:
Top-view of the ControlBlock

The hardware interfaces of the ControlBlock are described in the following:

  • 2×6 pin female header as connector to the Raspberry Pi
    The ControlBlock PCB is attached to the Raspberry with a 2×6 pin female header. This header makes use of pins 1 to 12 of the J8 header. This header is used for connecting the voltage and ground pins as well as the I2C pins between the RPi and the ControlBlock. The PCB is prepared for breaking out all other pins of that header so that you can easily access all other pins that are not used by the ControlBlock.

  • Micro or B-Type: USB Connectors for the power supply
    The first version of the ControlBlock had a USB mini connector. Because so many people asked for it the ControlBlock got a USB Micro connector now. That means you can simply use your existing USB Micro cable. The USB Micro connector comes by default with the ControlBlock. If you would like to use a bigger USB connector, you can optionally solder a USB-B socket to the ControlBlock! This should give you the flexibility that you need for your project.

  • Pin Outs for 5V Supply Voltage and Ground
    If you do not want to use USB connector, GND and the 5V supply voltage can also be accessed via two pins so that you could use batteries or whatever you like.

  • Pin Out for a Toggle Switch
    To control the power state of the Raspberry Pi the ControlBlock provides an interface for attaching a toggle switch. The on-board microcontroller monitors the state of that switch as well as the one of the Raspberry.

  • Pin Out for Status LED
    The current power state can be indicated with a 5V status LED that can be attached to the two pins that are provided by the ControlBlock. These states can be “off”, “booting”, “on”, and “shutdown”. The different state are indicated with easy-to-distinguish static and pulsing patterns.

  • 2×16 GPIO pins
    Overall, the two GPIO expanders provide 32 GPIO pins for arbitrary usage. With revision 2.X of the Raspberry Pi, these pins can be accessed via the SPI interface of the Raspberry Pi. With revision 1.X of the ConterolBlock, these pins can be accessed via the I2C interface with the I2C addresses 0x20 and 0x27.
    Alternatively, to manually access the pins you can use the provided ControlBlock driver software to easily connect and poll various game controllers. For this, the top silkscreen of the ControlBlock PCB is marked with pin outs for players 1 and 2.

  • In-Service Programmer (ISP) pin-out for ATTiny
    The Power Switch logic is realized with the help of an Atmel ATtiny85 microcontroller. If you want to you have the possibility to access the microcontroller with the ISP header. In this way you could reprogram the microcontroller with whatever functionality you like.

  • GPIO pins used by the ControlBlock
    The ControlBlock revision 2.X uses these GPIO pins of the 40-pin header of the Raspberry Pi: 3.3V (pin 1), 5V (pin 2), GPIO 17 (pin 11), GPIO 18 (pin 12), MOSI (pin 19), MISO (pin 21), SCLK (pin 23), CE0 (pin 24).

Assembly of the ControlBlock

The ControlBlock consists of SMD as well as of THT components. The THT components consist of these parts:

  • 1x 2-pin female terminal block
  • 2x 2-pin male header
  • 1x 2×6-pin female connector
  • 4x 8-pin female terminal block

These parts are shown in the following image:
IMG_0012_Snapseed1024

The assembly of the THT components is done in a few steps, which are described in detail in the following:

  1. Solder the 2-pin female terminal block on the top side (i.e., the side with the white marking print) of the ControlBlock. Take care for the correct orientation of the terminal block!

2. Solder the two 2-pin male headers for the button and the status LED. Note that you might to adapt this step according to the button and/or the LED that you want to use with the ControlBlock.

3. Solder the 2×6 female pin header on the bottom side of the ControlBlock (i.e., the side without the white marking print)

4. Solder the first 8-pin terminal block on the top side of the ControlBlock. Take care for the correct orientation of the terminal block! First, solder a single pin and check the resulting alignment of the terminal block. If the terminal block is placed well, continue with the other seven pins.

5. Solder the other three 8-pin terminal blocks in the same way as you did with the first 8-pin terminal block.

The fully assembled ControlBlock should look like this:

IMG_0033_Snapseed1024

Attaching a Power Button

To turn the Raspberry Pi on and off with the ControlBlock you need to attach a toggle switch to the two button pins on the ControlBlock. Technically speaking, the microcontroller on the ControlBlock looks, if the two button pins are connected or not. If they are connected, a GPIO pin of the microcontroller on the ControlBlock is pulled to GND and interpreted accordingly.

  • It is important that you use a toggle switch and not a momentary button with the ControlBlock. Otherwise the Raspberry Pi will be turned off again right after booting.
  • If you do not want to use the power switch functionality you can disable this in the configuration file /etc/controlblockconfig.cfg by setting “powerswitch”: false.
  • The power switch circuitry of the ControlBlock leads to a tiny voltage drop and we made the experience that a good quality power supply and a good quality USB cable are mandatory for a working setup. If unsure, we can recommend the official Raspberry Pi Power Supply.

Attaching a Status LED

The ControlBlock has pin outs for an optional status LED that indicates the power state of the Raspberry Pi. You can directly attach an LED to the pins that are marked with “LED”. You need to pay attention to the polarity of the LED: The LED pins are marked with “+” and “-” for that.

The LED will blink in four different patterns that depend on the power state of the Raspberry Pi:

  1. Off: The LED is simply off.
  2. Booting: The LED slowly fades in and out.
  3. On: The LED constantly stays on.
  4. Shutting down: The LED fades in and out twice as fast as during boot up.

How to attach Arcade Buttons, Joysticks, Gamepads

The cables from the arcade buttons, joysticks, as well as from the (S)NES gamepads are connected to the ControlBlock via the screw terminal blocks. You need a slotted screwdriver with a maximum width of 2.5 mm for that. Detailed instructions for the individual controller types are given further below.

Software Setup and Configuration

The GPIO ports of the ControlBlock can be accessed via the I2C interface of the Raspberry Pi. The addresses of the two GPIO expanders are 0x20 and 0x27.

The power switch functionality of the ControlBlock is controlled with the GPIO pins 17 and 18 of the Raspberry Pi:

  • Pin 17 can be used to indicate the power state of the Raspberry Pi. This pin is read by the ControlBlock”s microcontroller to control the on-board power switch.
  • Pin 18 can be read by the Raspberry Pi to get status of the button that is attached to the ControlBlock.

The ControlBlockService is an open-source driver for the ControlBlock. It provides a service for interacting with the power button signals as well as for mapping attached game controllers to corresponding game pad devices on the Raspberry Pi. The installation only takes a few steps and can either be done completely from command line or half-automatically with the help of the RetroPie-Setup Script. In the following, these two methods are described in more detail.

Command-Line Installation

Before you start with the installation of the ControlBlock driver, make sure that the SPI-interface (in case of ControlBlock rev. 2.X) or the I2C-interface (in case of ControlBlock rev. 1.X) is enabled. You can do this via the tool raspi-config in the “Advanced Options” menu. Enable the interface and let the kernel module be loaded by default. Reboot your system to let the changes take effect.

The command-line installation consists of these steps:

  1. Installing required packages
  2. Fetching the latest version of the ControlBlock driver and service from the public repository.
  3. Compiling the driver binary.
  4. Installing the driver binary.
  5. Installing the service.

Here is a step-by-step guide:

  1. Eventually: Download and copy the RetroPie SD card image version 3.5 to the sd card
  2. Do not connect any other (USB) controller to the Raspberry for now to avoid any unnecessary interference
  3. Connect the power supply and the switch with the ControlBlock and switch on the Raspberry
  4. When EmulationStation has loaded and shows the controller configuration, press F4 to get to the command prompt.
  5. Alternatively: Connect to the Raspberry Pi via SSH to get to the command prompt
  6. Run „sudo raspi-config“, select „Advanced Options“, select „SPI“ and enable the SPI interface and the SPI kernel module on boot by default by selecting „Yes“ in the following two screens.
  7. Exit raspi-config by selecting finish and select „reboot“ when asked for it.
  8. Again, press F4 in EmulationStation to get to the command prompt or connect to your RPi via ssh
  9. Update the apt package cache: sudo apt-get update
  10. Install any APT updates: sudo apt-get upgrade -y
  11. Reboot (IMPORTANT, otherwise we might get a modprobe error) via “sudo reboot”
  12. Install necessary packages: sudo apt-get install -y cmake g++-4.9
  13. Clone the ControlBlock driver repository: “git clone git://github.com/petrockblog/ControlBlockService2.git”. If you have revision 1.X of the ControlBlock use the command “git clone git://github.com/petrockblog/ControlBlockService.git”
  14. Change into the driver folder: “cd ControlBlockService2” (or “cd ControlBlockService” for rev. 1.X)
  15. Compile the driver: make
  16. Install the driver: sudo make install
  17. Install the service so that the driver is loaded on boot: sudo make installservice

DONE

  • You can now configure the ControlBlock service by editing its configuration file via „sudo nano /etc/controlblockconfig.cfg“.
  • After changing the configuration, you can reload the service via „sudo service controlblockservice restart”
  • You can test your attached controller(s) with the tool jstest, e.g., with „jstest /dev/input/js0“ (Exit with Ctrl-C)

This video demonstrates the above steps:

Using Arcade Controllers with the ControlBlock

The ControlBlock comes with silkscreen indicators that describe a default pin out for arcade controllers: You can connect two joysticks and 12 buttons for each of the two players:

ControlBlockLayoutArcade

The ControlBlock service can be configured in two different ways when using arcade controls:

As one option it can be configured such that it provides two game pad devices in the system, one for each player. To do so, the configuration in the file /etc/controlblockconfig.cfg must set “gamepadtype” to “arcade”:

    "input" : {
        "gamepadtype" : "arcade"
    },

As another option the ControlBlock service can be configured such that it provides a virtual keyboard with the de-facto MAME standard. To do so, the configuration in the file /etc/controlblockconfig.cfg must set “gamepadtype” to “mame”:

    "input" : {
        "gamepadtype" : "mame"
    },

The button mapping is shown in the following diagram:

ControlBlockLayoutMAME

Using (S)NES Controllers with the ControlBlock

The ControlBlock can also be used to poll NES and SNES controllers. Here is a diagram that describes the pin out for using NES and SNES controllers with the ControlBlock:

ControlBlockLayoutSNESNES

Here is a pin out diagram for NES and SNES connectors:

If you want to use a SNES case, here is a diagram that shows the pin out of the original SNES controller front:

SNES Controller Front Pin Out
SNES Controller Front Pin Out

In order to poll NES and SNES controllers the configuration in the file /etc/controlblockconfig.cfg must set “gamepadtype” to “snes”:

    "input" : {
        "gamepadtype" : "snes"
    },

Video Demonstrations

Power Switch

The following video shows the power switch functionality of the ControlBlock:

Arcade Controllers

The the following demonstration video shows arcade controllers for two players that are mounted on a simple wooden console. The bottom of it looks as following:

Bottom view of the wooden demo arcade controllers console.

This video shows the controllers in action:

SNES Controllers

This video shows the ControlBlock with SNES controllers attached to it:

Conclusion

The ControlBlock is an extension board for the Raspberry Pi (TM). The two key features of the ControlBlock are

  • a power switch functionality and
  • general purpose input/output (GPIO) pins ready to use, e.g., for connecting arcade or SNES controllers.

The power switch functionality allows to turn on and off the power to the Raspberry Pi with a toggle switch. Therefore, a toggle switch can also be connected to the ControlBlock. There is also a connector for a status LED that indicates the power status of the Raspberry Pi.

The GPIO pins can be accessed from the Raspberry Pi via the I2C interface. The ControlBlock makes it very easy to connect arcade controllers for up to two players. The open-source driver for the ControlBlock can be configured for various controller types. It supports, e.g., arcade controllers that are mapped to game pad devices, as well as a mapping to a MAME keyboard configuration. The ControlBlock also supports, e.g., the polling of SNES and NES controllers so that it also provides the functionality of the RetroPie GPIO Adapter.

If you are interested in getting the ControlBlock for your project, it can be ordered at the shop.

Check Also

IMG_2907

New Revision of the PowerBlock: Increased Flexibility

The PowerBlock is a small support shield for the Raspberry Pi that provides a power …

  • MrMolinero

    If using the control block on the RPI 3B what size heatsink would you recommend using? I am not sure how big the gap is between the control block and the RPI.

    • I would recommend a heat sink of 8 mm height as maximum.

  • Luca Tortuga

    Great article! A quetion: I’ve a raspberry pi 3 model B, the
    ControlBlock is not usable on my model or i only can’t obtain a
    beautiful result combining my model with this ControlBlock? Thx

    • The ControlBlock and the Raspberry Pi 3 are fully compatible with each other!

  • Rudie Isgek

    I would like some unstructured instructions for attaching coin mechs. Are these available?

  • Chris Loental

    Hello! I just got my ControlBlock in the mail!

    I was wondering if it can support LED arcade buttons that light up?

    I currently have 4-terminal microswitches with embedded LEDs.

    • As long as the overall current is not greater than 3.7 A the ControlBlock can be used to driver other devices besides the Raspberry itself. However, in case of LEDs, an LED driver might be preferable.

  • Pavel Carrillo

    Hi, is this block compatible with orange pi one ?

    • I do not know. It would be interesting to hear about some experiences, though!

  • Goods

    If you were to wire this to SNES controllers, can you continue to use the USB ports or BT for additional/other controllers? Or is it an either/or situation?

    • Yes, you can continue to use any USB device.

%d bloggers like this:
Skip to toolbar