Pico-8 on Raspberry Pi with a ILI9341 2.2'' 320x240 SPI TFT

Here is a fast HOWTO get Pico-8 running on a 2.2'' TFT Display (ILI9341 board) and a Raspberry Pi.
I use a Raspi B+ here but it should work on all other versions too.

The display is a cheap one with 320x240 pixel. You should get one at ebay for about 5 bucks.

img_0802

Setup your raspbian without connecting the TFT! I got strange errors at fistboot a fresh raspbian with the TFT connected. So at first:

Setup a fresh rasbian jessie(lite) SD card, boot up and setup the pi with "sudo raspi-config".
Enable the SPI-Interface under 'Advanced Options'.
(If you run Pico-8 on a GameBoy like keyboardless setup also enable the 'auto')

Setup your network.

Update raspian with 'sudo apt-get update' and 'sudo apt-get dist-upgrade'. (reboot)

Update firmware with 'sudo apt-get install rpi-update' and 'sudo rpi-update' (reboot, shutdown)

Now let's wire up the TFT to your Raspi GPIO header.

The pin connections:

GPIO Pi ILI9341 ILI9341 Pi GPIO
3V3 1 1-VCC 2 5V
GPIO2 (SDA) 3 4 5V
GPIO3 (SCL) 5 2-GND 6 GND
GPIO4 (GPCLK0) 7 8 GPIO14 (TXD)
GND 9 10 GPIO15 (RXD)
GPIO17 11 8-LED 12 GPIO18 (PCM-CLI)
GPIO27 13 14 GND
GPIO22 15 16 GPIO23
3V3 17 5-D/C 18 GPIO24
GPIO10 (MOSI) 19 6-SDI(MOSI) 20 GND
GPIO9 (MISO) 21 9-SDO (MISO) 4-RESET 22 GPIO25
GPIO11 (SCLK) 23 7-SCK 3-CS 24 GPIO8 (CE0)
GND 25 26 GPIO7 (CE1)

(Note: It will run without it but just for the sake of savety add a 47..50 ohm resistor to the LED pin)

Edit the raspi config with 'sudo nano /boot/config.txt' and uncomment/change the framebuffer settings like this:

framebuffer_width=320
framebuffer_height=240

Check if SPI is enabled there. (dtparam=spi=on)

I also need to enable 'hdmi_drive' and fix the overscan to get sound and screen right over HDMI:

overscan_left=25
overscan_right=25
overscan_top=25
overscan_bottom=25
hdmi_drive=2

It' time to test the display.

Load the kernel module:

sudo modprobe fbtft_device custom name=fb_ili9341 gpios=reset:25,dc:24,led:18 speed=64000000 rotate=90 bgr=1

Turn on the console on TFT:

con2fbmap 1 1

BOOM! Now you should see something. If not... something went wrong (doubecheck config, wiring,...)

From here you can use console (and even GUI) on the TFT but if you start Pico-8 it will only comes up over HDMI. It's because Pico-8 is made with SDL2 that, unfortunately, does not support the frame buffer anymore.

Get over this:

Grab (or compile) 'rpi-fbcp' from Github and put it to your home directory. If TFT is still on, turn it off with 'con2fbmap 1 0'. Turn on 'rpi-fbcp':

./fbcp&

Now you should see the console on HDMI and TFT. (to turn it off again kill the process with the id you can see after fbcp started up like: 'sudo kill 810')

Now start up Pico-8 and have fun! But how to get Pico-8 start up at boot? First setup the module auto load:

Edit 'fttft.conf':

sudo nano /etc/modules-load.d/fbtft.conf

and add this:

spi-bcm2835
fbtft_device

save... and edit 'fbtft.conf':

sudo nano /etc/modprobe.d/fbtft.conf

and add:

options fbtft_device custom name=fb_ili9341 gpios=reset:25,dc:24,led:18 speed=64000000 rotate=90 bgr=1

(modify 'gpios', 'speed', 'rotate' settings to your needs, 'bgr=1' fixes a red/blue color issue)

Make 'fbcp' and 'pico-8' run at boot by editing 'rc.local':

sudo nano /etc/rc.local

and add this above 'exit 0':

cd /home/pi/
./fbcp &
cd /home/pi/pico8
./pico8 -splore

After reboot you should see Pico-8.

Note: Quitting Pico-8 from there doesn't work. I can't get console back after quit... So to change something on your setup you have to SSH into your raspi then.

img_0782

Notes:

To get a smaller font in console run 'sudo dpkg-reconfigure console-setup' and select the smallest one you can find e.g. 'Terminus 6x12')