1.3 Inches RetroPie Zero

by 陳亮 in Circuits > Raspberry Pi

31538 Views, 198 Favorites, 0 Comments

1.3 Inches RetroPie Zero

IMG_5681.jpg
1.3 Inches RetroPie Zero
IMG_5677.jpg
IMG_5536.jpg
IMG_5560.jpg

This instructables show how to use a 1.3" Retina grade IPS LCD HAT to make a tiny RetroPie Zero.

Preparation

IMG_5356.jpg
IMG_5357.jpg
IMG_5358.jpg
IMG_5619.jpg
IMG_5618.jpg
IMG_5682.jpg
IMG_5683.jpg
IMG_5557.jpg
IMG_5614.jpg
IMG_5615.jpg
IMG_5616.jpg
IMG_5617.jpg

RPi Zero

Both Raspberry Pi Zero and Raspberry Pi Zero W is ok. WiFi version can make subsequent setup easier but in contrast it may draining more power continuously, i.e. shorter battery life.

LCD HAT

Waveshare released 2 LCD HAT for RPi Zero, both have a tiny square LCD. The newer version have a 240 x 240 1.3" IPS LCD. It is 261 PPI and within the apple defined retina display range (218 - 458 PPI). This resolution is capable to emulate many retro game console in the CRT TV age, e.g. NES at 256 x 240 resolution, we can cut 8 pixels from both left and right overscan area and make it become 240 x 240.

Pin Header

To closely fit for the Waveshare 1.3" LCD HAT, it require a 8 mm tall 2 x 20 pins header. But I cannot buy one with 8 mm tall, so I will modify from a 12 mm tall pin header.

LiPo Battery

The interior size between RPi and LCD HAT can fit for a 5 mm x 23 mm x 45 mm battery, any LiPo battery with protection circuit that within this dimension should be ok.

Tiny LiPo Charge Board

I have some 10 mm x 10 mm tiny 5 V LiPo charge board in hand. It is small enough for this project, but the limitation is it only can charge the battery up to 50 mA current. A 400 mAh battery require over 8 hours for fully charged.

Power Switch

A tiny power switch.

Wrist Strap

Since this Game pad is so tiny and easy to slip from hand, it is recommended wearing a wrist strap while playing it.

Screw

The 3D printed case require four 14 mm M2.5 flat-head screws for assembly.

Ref.:

https://www.waveshare.com/wiki/1.3inch_LCD_HAT

https://www.waveshare.com/product/modules/oleds-lc...

3D Print Case

IMG_5541.jpg
IMG_5542.jpg
IMG_5544.jpg
IMG_5543.jpg

3D print the case model you can find in Thingiverse:

https://www.thingiverse.com/thing:3328994

For ease of illustration, I print each part in different colors:

  • Layer123.stl - Carbon Black
  • Layer4.stl - Translucent Yellow
  • Layer5.stl - Translucent Orange
  • Layer678.stl - Translucent Red
  • ButtonHead.stl - Translucent Red, Translucent Blue and Translucent Green
  • CrossButtonHead.stl - Gundam Red

Direct Battery Power

2019-01-02_174104.png
main-qimg-6d277284837ff04417b2577c91676a96.gif

This tiny gamepad has no room to fit in a step up circuit board, is it possible a LiPo battery direct power the RPi Zero (W) without step up?

There are some unofficial discussion about is it require full 5 V power supply for RPi Zero (W).

According to the RPi Zero reduced schematics, there are only 2 pins direct connected to 5 V, it is USB plug and PAM2306 regulator. All other parts powered by regulated 3.3 V and 1.8 V.

Assume we do not use any external USB device while powered by battery, the key factor is the regulator.

According to PAM2306 datasheet, there are still keep over 90% efficient for 3.3 V output when the input voltage dropped to 3.5 V.

RPi Zero average draw around 100 - 200 mA and the LiPo is around mAh, the discharge rate is around 0.5 C. It can still utilise 90% of LiPo capacity before drop below 3.5 V.

Ref.:

https://www.raspberrypi.org/forums/viewtopic.php?t...

https://www.raspberrypi.org/documentation/hardware...

https://www.mouser.hk/datasheet/2/115/PAM2306-3367...

https://electronics.stackexchange.com/questions/32...

https://www.quora.com/Is-it-possible-to-see-the-ch...

Note:

According to my simply test, the battery can last over 90 minutes while WiFi turned on. It should last longer if using RPi Zero.

Pin Header Patch

IMG_5359.jpg
IMG_5360.jpg
IMG_5361.jpg
IMG_5362.jpg
IMG_5363.jpg

Waveshare LCD HAT use low profile female pin header, it can make the product more slim. But we need a corresponding low profile male pin header at RPi Zero to make it. The male pin header should be 8 mm tall, but I cannot find on the web. So patch it from a 12 mm male pin header.

It require some patient to trim 40 pins the same length.

Soldering Work

IMG_5364.jpg
IMG_5545.jpg

Solder all pin headers with RPi Zero.

Here are the connection summary of power circuit:

Waveshare Pin 2 -> Charge Board +vin, Power Switch Pin 1
Waveshare Pin 6 -> Charge Board -vin
                   Charge Board -vout -> LiPo -ve
                                         LiPo +ve -> Power Switch Pin 2
                   Charge Board +vout             -> Power Switch Pin 3
  • When Power Switch closed pin 1 and 2, it is Battery Powered Mode
  • When Power Switch closed pin 2 and 3, it is Battery Charging Mode / Power Off

Note:

Waveshare LCD HAT pin header is at the bottom, so the pin arrangement is upside down

Assembly Layer 4

IMG_5546.jpg
  • Put Layer 4 under LCD HAT
  • Fit the power switch in Layer 4
  • Put charge board and battery inside Layer 4 frame

Assembly Layer 5

IMG_5547.jpg

Put Layer 5 over Layer 4

Plug in RPi Zero

IMG_5548.jpg

Assembly Layer 678

IMG_5549.jpg

Put Layer 678 over RPi Zero.

Put Screw Into Screw Hole

IMG_5550.jpg

Put Buttons Head on LCD HAT

IMG_5551.jpg
IMG_5552.jpg

Assembly Layer 123

IMG_5553.jpg

Put Layer 123 on the LCD HAT.

Screw Up the Screws

IMG_5554.jpg

Assembly Cross Button Head

IMG_5555.jpg

Put the cross button head into the cross button.

Download RetroPie Image

螢幕快照 2017-04-16 下午2.03.02.png

Download RetroPie image here:

https://retropie.org.uk/download/

Select "Raspberry Pi 0/1" option to download the image for Raspberry Pi Zero

Download Source

2 further source code required for the Breadboard RetroPie:

mk_arcade_joystick_rpi:

https://github.com/recalbox/mk_arcade_joystick_rpi

rpi-fbcp:

https://github.com/tasanakorn/rpi-fbcp

Simple click "Clone or download" button and then "Download ZIP" from both source web page.

Prepare ROM Files

For the non license free game, I think you should only use the ROM that you have the original game.

Or you may find some license free games here:

http://pdroms.de/files

http://www.doperoms.com

Flash the RetroPie Image

The steps to flash RetroPie image to the micro SD card is as same as flashing Raspbian image. If you are not familiar the flashing steps, please follow the steps provided by Raspberry.org:

P.S. remember to replace the image file name with the RetroPie image.

Copy Files

Copy "mk_arcade_joystick_rpi-master.zip", "rpi-fbcp-master.zip" to the RetroPie micro SD just created.

Configure Micro SD

We need further config after RetroPie boot, before that, we need to enable DWC2 USB controller to make network connection between computer and Pi Zero.

Edit the config.txt in micro SD, append the follow line at the tail:

dtoverlay=dwc2

Edit the codlin.txt in micro SD, insert "modules-load=dwc2,g_ether" after "rootwait" keyword. The result should be something like that:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=14a75fe9-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet loglevel=3 consoleblank=0 plymouth.enable=0 quiet init=/usr/lib/raspi-config/init_resize.sh

Create a blank file called "ssh" in the micro SD to enable openssh server, e.g. in my Mac:

touch /Volumes/boot/ssh

Ref.:

https://www.instructables.com/id/Connect-to-a-Rasp...

USB Connect

IMG_5556.jpg
IMG_5680.jpg
  • Insert the micro SD to Pi Zero
  • Set the power switch to Battery Charge Mode
  • Connect the Pi Zero 2nd USB socket (labelled "USB") to the computer.

Wait around a minute, you should find a new network adaptor in your computer. Type the follow command connect to the Pi Zero:

ssh pi@retropie.local

Note:

Default password is "raspberry", you should change it ASAP by "passwd" command

Configure LCD

Append to "/etc/modules"

spi-bcm2835
flexfb
fbtft_device

create the "/etc/modprobe.d/fbtft.conf"

options flexfb setaddrwin=0 width=240 height=240 init=-1,0x11,-2,120,-1,0x36,0x70,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3
options fbtft_device name=flexfb gpios=reset:27,dc:25,cs:8,led:24 speed=125000000 bgr=1 fps=60 custom=1 height=240 width=240

Enable Fbcp

Extract source files:

unzip /boot/rpi-fbcp-master.zip

Compile and install:

cd rpi-fbcp-master/
mkdir build
cd build
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp
cd ../..

Create new file "/etc/init.d/fbcp":

#! /bin/sh<br>### BEGIN INIT INFO
# Provides:          fbcp
# Required-Start:    kmod
# Required-Stop:     kmod
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description:
# Description:
### END INIT INFO
case "$1" in
  start)
  /usr/local/bin/fbcp &
  ;;</p><p>  stop|restart|reload|force-reload)
  killall fbcp
  exit 0
  ;;</p><p>  *)
  log_success_msg "Usage: $0 start"
  exit 1
esac

Make the file executable:

sudo chmod +x /etc/init.d/fbcp

Set it init at startup:

sudo update-rc.d fbcp defaults

Append the follow line in "/boot/config.txt" at the tail:

disable_overscan=1
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt=240 240 60 1 0 0 0
dtparam=spi=on

Ref.: https://github.com/tasanakorn/rpi-fbcp

Configure Joystick

Extract source files:

unzip /boot/mk_arcade_joystick_rpi-master.zip

Edit buttons definition:

cd mk_arcade_joystick_rpi-master/
vi mk_arcade_joystick_rpi.c

Find the "static const int mk_arcade_gpio_maps[]" row and update to HAT button mapping:

static const int mk_arcade_gpio_maps[] = {6,19,5,26,13,21,16,20,0,0,0,0};

Compile and install module:

sudo mkdir /usr/src/mk_arcade_joystick_rpi-0.1.5/
sudo cp -a * /usr/src/mk_arcade_joystick_rpi-0.1.5/
export MKVERSION=0.1.5
sudo -E dkms build -m mk_arcade_joystick_rpi -v 0.1.5
sudo -E dkms install -m mk_arcade_joystick_rpi -v 0.1.5

Test the buttons:

sudo modprobe mk_arcade_joystick_rpi map=1
jstest /dev/input/js0

Append to "/etc/modules":

 mk_arcade_joystick_rpi

create the "/etc/modprobe.d/joystick.conf":

options mk_arcade_joystick_rpi map=1

Ref.: https://github.com/recalbox/mk_arcade_joystick_rp...

Copy ROM Files

Copy ROM files from "/boot" folder to "~/RetroPie/roms/$CONSOLE" folder

Ref.:

https://github.com/retropie/retropie-setup/wiki/Tr...

Raspi-config

2018-12-14_152143.png
2018-12-14_152209.png
2018-12-14_152245.png
2018-12-14_152300.png
2018-12-14_152316.png
2018-12-14_152329.png
2018-12-14_152352.png
2018-12-14_152408.png
2018-12-14_152514.png
2018-12-14_152537.png
2018-12-14_152549.png
2018-12-14_152600.png
2018-12-14_152611.png

Run:

sudo raspi-config
  • WiFi: 2 Network Options -> N2 Wi-fi -> fill your WiFi details
  • Not wait network: 3 Boot Options -> B2 Wait for Network at Boot -> No -> OK
  • Timezone: 4 Localisation Options -> I2 Change Timezone -> select your timezone
  • Disable serial port: 5 Interfacing Options -> P6 Serial -> No -> No -> OK

Ref.:

https://www.raspberrypi.org/documentation/configur...

RetroPie Setup

2018-12-13_164439.png
2018-12-13_170025.png
2018-12-13_170049.png
2018-12-13_170202.png
2018-12-13_170255.png
2018-12-13_170340.png

Run:

sudo ~/RetroPie-Setup/retropie_setup.sh

Fine tune for 1.3" LCD: C Configuration / Tools -> 805 configedit -> 1 -> 0 -> 2 Render Resolution -> O Video output resolution -> OK -> Cancel -> Cancel -> Cancel

Change theme to fit tiny screen (require WiFi connected): 812 esthemes -> 14 Pixel-tft -> OK -> 1 carbon -> 2 Uninstall

Ref.:

https://github.com/retropie/retropie-setup/wiki/th...

Native Resolution

The LCD HAT have 3 buttons and 1 extra push button in the cross button, it can map to the retro game console that only have 4 buttons (select, start, A and B). The highest resolution for this type of game console should be NES, it have 256 x 240 resolution. It can just fit for the 240 x 240 LCD display if simply crop the horizontal overscan area.

If you only play NES game only like me, you can apply the follow configuration to gain native resolution display.

Append "/opt/retropie/configs/nes/retroarch.cfg":

video_fullscreen_x = "0"
video_fullscreen_y = "0"
video_scale_integer = true

Append "/opt/retropie/configs/all/retroarch-core-options.cfg":

quicknes_use_overscan_h = "disabled"

Controller Configuration

4f0c5b8e-15e6-11e5-9255-b920543518d6.png

Joypad settings for EmulationStation:

vi /opt/retropie/configs/all/emulationstation/es_input.cfg

Input text:

<?xml version="1.0"?>
<inputList>
  <inputAction type="onfinish">
    <command>/opt/retropie/supplementary/emulationstation/scripts/inputconfiguration.sh</command>
  </inputAction>
  <inputConfig type="joystick" deviceName="GPIO Controller 1" deviceGUID="15000000010000000100000000010000">
    <input name="start" type="button" id="11" value="1"/>
    <input name="down" type="axis" id="1" value="1"/>
    <input name="right" type="axis" id="0" value="1"/>
    <input name="select" type="button" id="10" value="1"/>
    <input name="left" type="axis" id="0" value="-1"/>
    <input name="up" type="axis" id="1" value="-1"/>
    <input name="a" type="button" id="0" value="1"/>
    <input name="b" type="button" id="1" value="1"/>
  </inputConfig>
</inputList>

Joypad settings for Retroarch:

vi /opt/retropie/configs/all/retroarch/autoconfig/GPIO\ Controller\ 1.cfg

Input text:

input_device = "GPIO Controller 1"
input_driver = "udev"
input_start_btn = "11"
input_exit_emulator_btn = "11"
input_down_axis = "+1"
input_right_axis = "+0"
input_state_slot_increase_axis = "+0"
input_select_btn = "10"
input_left_axis = "-0"
input_state_slot_decrease_axis = "-0"
input_up_axis = "-1"
input_a_btn = "0"
input_b_btn = "1"
input_reset_btn = "1"
input_enable_hotkey_btn = "10"

Speed Up Boot Time

Run:
sudo systemctl disable asplashscreen
sudo systemctl disable dphys-swapfile
sudo systemctl disable hciuart
sudo systemctl disable keyboard-setup
sudo systemctl disable nmbd
sudo systemctl disable raspi-config
sudo systemctl disable smbd
sudo systemctl disable nfs-config

Optional Tuning

Fine tune "/boot/cmdline.txt":

  • Disable USB Ethernet Gadget
  • no logo
  • fastboot
  • quiet
dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=14a75fe9-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait loglevel=3 consoleblank=0 plymouth.enable=0 logo.nologo fastboot quiet
#dtoverlay=dwc2

Boot RetroPie

  • Turn off the RetroPie:
sudo halt
  • Unplug the USB cable
  • Set the power switch to Battery Powered Mode
  • Wait around half minute to boot up
  • Follow the screen instruction to config the game button
  • Select the console and game you have uploaded

Emulation Station Power Option

Press start button (push down the cross button) to enter the Emulation Station configuration screen.

UI SETTINGS -> SCREENSAVER SETTINGS -> SCREENSAVER AFTER -> 1 minute

OTHER SETTINGS -> POWER SAVER MODES -> INSTANT

Tie Wrist Strap

IMG_5558.jpg
IMG_5559.jpg

Enjoy!

IMG_5679.jpg
IMG_5675.jpg
DA12E89B-3BE2-4B9D-99C7-BED1A69CDF09.jpeg

It's time to show off what you have made and play with it.

Gallery: Color Mix & Match

IMG_5459.jpg
IMG_5465.jpg
IMG_5478.jpg
IMG_5534.jpg
IMG_5527.jpg