20 Raspberry Pi
ohsqueezy edited this page 2023-11-26 01:02:27 -05:00

Raspberry Pi

Replacing the computer and Arduino with a Raspberry Pi transforms Scrapeboard into a plug and play device, capable of being played by plugging into a power source and any HDMI display. This is beneficial because it makes the system more portable.

This chapter explains how to install everything from scratch on an empty SD card using Raspberry Pi OS Lite as the operating system. It also explains how to connect the same circuit to a Raspberry Pi's GPIO pins instead of an Arduino. A wi-fi or LAN connection, external display, and USB keyboard are required.

Model

The Raspberry Pi model must have 2GB or higher RAM. Only the Raspberry Pi 4 has been tested, but Raspberry Pi 5 should work as well. A 4GB or larger micro SD card should be used.

Operating System

Pi imager home screen

  1. Get the Raspberry Pi imager software and launch it (note: must be run as authorized user)
  2. Choose "Raspberry Pi OS (other)" -> "Raspberry Pi OS Lite (64-bit)" under "Operating System"
  3. Connect your SD card and choose it under "Storage"

Imager settings tab

Pi imager settings

  1. Click the gear button to open the settings
  2. Check off "Set hostname" and change to "scrapeboard"
  3. Check off "Enable SSH" with "Use password authentication"
  4. Check off "Set username and password" and choose your own username and password
  5. Check off "Configure wireless LAN" and set the SSID and password for your wi-fi network (if wi-fi is unavailable, you can use the Raspberry Pi's ethernet connection or transfer the Scrapeboard files onto the SD card manually later)
  6. Check off "Set locale settings" and set to your time zone and keyboard layout

Begin installation

Click "WRITE" in the Imager window

Boot

  1. Insert the SD card into the Raspberry Pi
  2. Connect the Pi to an external HDMI display
  3. Connect a USB keyboard
  4. Power up the Pi (note: an official power adapter is recommended)
  5. Login with the username and password set during installation
  6. (Optional) run sudo apt update && sudo apt upgrade to update the operating system
  7. The system is ready for installing the game software and other software requirements

Installing the software

Install Python, Git, and PIL through the package manager

sudo apt install python3 git python3-pygame python3-pil

Resolution

To set the resolution to game resolution 800x450, edit /boot/cmdline.txt by adding a custom video definition to the end of the file

video=HDMI-A-1:800x450M@60

Reboot to use the new resolution

sudo reboot

Pygame 2

It is recommended to install Pygame 2 and SDL manually, following the steps below.

Install initial Pygame dependencies

sudo apt install build-essential libfreetype6-dev libportmidi-dev libjpeg-dev \
	python3-setuptools python3-dev python3-numpy cython3

Download SDL2 source. For example, this will download version 2.24.2.

wget https://github.com/libsdl-org/SDL/releases/download/release-2.24.2/SDL2-2.24.2.tar.gz
tar -xf SDL2-2.24.2.tar.gz
cd SDL2-2.24.2/

Enable deb-src repositories by uncommenting the deb-src lines in /etc/apt/sources.list.

Install everything necessary to build SDL2.

sudo apt update && sudo apt build-dep libsdl2

Configure, make, and install

./configure && make && sudo make install

Download and compile SDL image, SDL ttf, and SDL mixer

wget https://github.com/libsdl-org/SDL_image/releases/download/release-2.6.2/SDL2_image-2.6.2.tar.gz
wget https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.20.1/SDL2_ttf-2.20.1.tar.gz
wget https://github.com/libsdl-org/SDL_mixer/releases/download/release-2.6.2/SDL2_mixer-2.6.2.tar.gz
tar -xf SDL2_image-2.6.2.tar.gz
cd SDL2_image-2.6.2/
./configure && make && sudo make install
cd ..
tar -xf SDL2_ttf-2.20.1.tar.gz
cd SDL2_ttf-2.20.1/
./configure && make && sudo make install
cd ..
tar -xf SDL2_mixer-2.6.2.tar.gz
cd SDL2_mixer-2.6.2/
./configure && make && sudo make install
sudo ldconfig

Build Pygame

git clone https://github.com/pygame/pygame
cd pygame
python3 setup.py -config -auto
python3 setup.py build_ext --inplace
python3 setup.py install --user

Audio configuration

It may be necessary to configure sound by replacing the contents of ~/.asoundrc with

defaults.pcm.card 1
defaults.pcm.device 0
defaults.ctl.card 1

Scrapeboard

Use Git clone with the --recursive flag to download both the game and framework

git clone --recursive https://open.shampoo.ooo/scrape/scrapeboard
cd scrapeboard/

Launch

Launch from command line

It should be possible to run in keyboard mode and test input with key presses now.

./OPEN-GAME --kms --no-serial

To run the game using the scrapeboard and platform, use the --pi flag.

./OPEN-GAME --kms --pi

Set to run at launch

First, make the Raspberry Pi skip the login prompt. Use the raspi-config script and select System Options -> Boot / Auto Login -> Console Autologin.

To launch Scrapeboard at startup, create a file at /etc/systemd/system/scrapeboard.service with the following contents (replace tony with your Pi's user name)

[Unit]
Description=It is Scrapeboard you slime bag
After=multi-user.target

[Service]
ExecStart=/home/tony/scrapeboard/OPEN-GAME --kms --pi --go-to-dir
Restart=always
RestartSec=5s
TimeoutStartSec=2min
User=scrapeboard

[Install]
WantedBy=default.target

and enable it

sudo systemctl enable scrapeboard.service

Now Scrapeboard will launch at startup and will restart itself if it ever is closed or crashes. If it needs to be restarted or stopped manually it can be controlled through systemd.

sudo systemctl [start | stop] scrapeboard

Use SHIFT + q to permanently quit and get back to the Raspberry Pi console because the regular quit button Q will cause the game to be relaunched automatically.

Electronics

Replace Arduino pins 2, 3, 4, and 5 with Raspberry Pi pins 37, 35, 33, and 31 (these pins are also referred to as GPIO 26, GPIO 19, GPIO 13, and GPIO 6) in the circuit. Otherwise, the circuit remains the same as described in the Electronics chapter. The game will automatically communicate with the Raspberry Pi if the --pi flag is used when starting the game.

⬅ Previous Page Next Page ➡
Board Improved Platform