Retrogaming part2: RetroPie on PiTFT

3 02 2016

20160202_225146In an earlier post (in French only, sorry folks) I documented in great details the making of my personal home arcade bartop thanks to Arcademy. You really want to check out Jérome’s latest projects – these are just amazing.

Another way of looking at retrogaming is by utilizing rather portable systems such as the Raspberry Pi. Phillip Burgess posted an amazing instructable at Adafruit on Running OpenGL-based Games & Emulators on Adafruit PiTFT Displays – unfortunately as he pointed out, recent updates to the Pi kernel & bootloader are incompatible with his guide.

We could not just wait till a fix, could we? So I decided I would try and give it a shot… and managed to get RetroPie 3.0 working on my Raspberry Pi B 2+ with Adafruit’s PiTFT 2.2”. I also added some additional features to facilitate the usage.

For the record, uname -a gives Linux raspberrypi 4.1.6-v7+ #2 SMP PREEMPT Fri Sep 4 16:49:07 UTC 2015 armv7l GNU/Linux.

Most of the work here is based on the article by Philippe Burgess on Adafruit: I cannot but recommend that you would read it carefully from A to Z before starting. You can also read for another perspective. Very similar in content but good to read as background.

PiTFT setup

Compared to Phillip Burgess’ approach, we are going to change a little bit the steps and start with the installation of the PiTFT screen. So we won’t be using the RetroPie distribution but rather start with a fresh Raspbian and run the RetroPie installation script at a later stage.

Attach your PiTFT hat to the Raspberry Pi and fetch the latest Raspian distribution. I’ll assume you know how to install Raspbian from the image. Once you’ve done this, follow the recommendations at Specifically,
– Expand Filesystem
– Under “Advanced Options,” disable Overscan, enable the Device Tree, SPI (load SPI kernel module by default), and force audio through 3.5mm jack (since HDMI will be disconnected later).

Next is installing the required kernel changes for the display. We are going to run most of the steps described at

$ curl -SLs | sudo bash 
$ sudo apt-get -y install raspberrypi-bootloader 
$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get -y install raspberrypi-bootloader 
$ sudo apt-get -y install adafruit-pitft-helper

I am using a 2.2″ HAT hence to run the configuration script,

$ sudo adafruit-pitft-helper -t 22

Same here, just go with Phillip Burgess’ recommendations, all good. Then we install the live framebuffer mirroring tool.

$ sudo apt-get install cmake 
$ git clone 
$ cd rpi-fbcp/ 
$ mkdir build 
$ cd build/ 
$ cmake .. 
$ make 
$ sudo install fbcp /usr/local/bin/fbcp

To launch fbcp fairly early in the startup sequence we need to edit /etc/rc.local. As we are not working (yet) with RetroPie we want to add the command /usr/local/bin/fbcp & to /etc/rc.local, just before the final “exit 0” line, and not in /etc/init.d/asplashscreen (which is quite obviously not yet here…)

Next is setting up the console with

$ sudo dpkg-reconfigure console-setup

(here again, follow the guide from P. Burgess) and editing the boot/config.txt file by adding at the end

hdmi_cvt=320 240 60 1 0 0 0 

Good! Let’s reboot.

$ sudo reboot

RetroPie setup

The next step is to install RetroPie. For doing this we are NOT going to use the distribution files (…) but the installation script as described here:

$ sudo apt-get install -y git dialog 
$ git clone git:// 
$ cd RetroPie-Setup 
$ chmod +x 
$ sudo ./

At this stage we should have all working good, so we can spend some time on doing some tuning.

Startup tuning


The script below and its usage is largely inspired by You can store this under /home/pi/


echo "*** RETROPIE WITH PITFT ***"
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" 
let secs=$((${upSeconds}%60)) 
let mins=$((${upSeconds}/60%60)) 
let hours=$((${upSeconds}/3600%24)) 
let days=$((${upSeconds}/86400)) 
UPTIME=`printf "%dd %02dh %02dm %02ds" "$days" "$hours" "$mins" "$secs"` 
# get the load averages 
read one five fifteen rest < /proc/loadavg
echo "$(tput setaf 2) 
`date +"%A %e %B %Y %R"` 
`uname -srmo` 
$(tput setaf 1) 
Uptime  : ${UPTIME} 
Memory  : $(tput setaf 2)$((`cat /proc/meminfo | grep MemFree | awk {'print $2'}`/1024)) mo $(tput setaf 1)/ $((`cat /proc/meminfo | grep MemTotal | awk {'print $2'}`/1024)) mo 
Load    : ${one}, ${five}, ${fifteen} (1, 5, 15 min) 
Process : `ps ax | wc -l | tr -d " "` 
IP@     : 
$(tput setaf 2)`/sbin/ifconfig | /bin/grep "Bcast:" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` 
$(tput setaf 1)`wget -q -O - | tail` 
Temp    : `vcgencmd measure_temp | sed "s/temp=//"` 
$(tput sgr0)"

echo "$(tput setaf 5)Press #27 to start EmulationStation. 
Press #23 to initiate immediate Shutdown. 

Once done, we just need to make it executable and to ensure it is executed on logging (did I say that you want to auto-log as user “pi”? go back to raspi-config!):

$ chmod 755
$ vi .bashrc

add at the end of the file

# informations 

# buttons control 
sudo python

then test it with

$ source .bashrc

Oops! missed to share the /home/pi/ script for handling GPIO #27 (remember #23 is directly configured in /etc/modprobe.d/adafruit.conf – which we did select during the PiTFT installation, right ?)

import RPi.GPIO as GPIO 
import time 
from subprocess import call

GPIO.setup(27,GPIO.IN, pull_up_down=GPIO.PUD_UP) 
while True:         GPIO.wait_for_edge(27, GPIO.RISING)         call(["/home/pi/ttyecho", "-n", "/dev/tty1", "emulationstation"])         quit()

Alright, now to the…

ROMs installation

Samba can ease the process (although RetroPie already adds some shares for ROMs and BIOSes)

$ sudo apt-get install samba samba-common-bin
$ smbpasswd -a pi 
$ smbpasswd -a pi
$ sudo smbpasswd -a pi
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig
$ sudo vi /etc/samba/smb.conf

Ensure you have the following at the end of the file

[pihome]     comment= Pi Home     path=/home/pi     browseable=Yes     writeable=Yes     only guest=no     create mask=0777     directory mask=0777     public=no


$ sudo /etc/init.d/samba restart
$ sudo reboot

One thing I almost forgot: in order to issue the emulationstation command when hitting GPIO #27, I needed to echo the command on the correct tty. Tried a number of things…

$ su -c emulationstation pi
$ echo -e "emulationstation\n" (notice the carriage return...)
$ runuser -l pi -c emulationstation
$ sudo runuser -l pi -c emulationstation
$ eval `echo -e emulationstation`

… and more.

Then I found ttyecho, an Utility to Send Commands or Data to Other Terminals (tty/pts).

This one is simply a blast. Go for it:

$ vi ttyecho.c
$ make ttyecho

Test it:

$ sudo ./ttyecho -n /dev/tty1 emulationstation

Works like a charm -> let’s use this! 🙂

Extra: Wifi configuration

I am using my favorite TP-Link TL-WN725N dongle for this. You can either use the wpa_supplicant or manually edit the interfaces file. If required, you can find drivers here.

What’s missing?

20160126_213531Hope you found this guide useful. The last piece of it it that I have not yet found a way to get Bluetooth connectivity up & running with the excellent 8Bitdo NES30 GamePad. If anyone knows… ping me!