äThis amazing How To Transform Raspberry Into A Gaming Machine will transform your Raspberry Pi into a true gaming machine. You will love it! Try it out!
Index of Transform Raspberry Into A Gaming Machine:
- Background
- How To Transform Raspberry Into A Gaming Machine
- Additional Information
- Start RetroPie from Raspian Desktop / X
- Option 1 – via Icon and killing Xorg
- Option 2 – via Icon and separate user
- Option 3 – Separate User
- Error message: could not install package(s)
- Error message: Could not successfully build sdl2- SDL (Simple DirectMedia Layer) v2.x
- Error message: You have the experimental desktop GL driver enabled.
- Error message: could not install package(s): omxplayer
Background of Transform Raspberry Into A Gaming Machine
Honestly, as ICT engineer that is in a managerial position facing my now 11 years old daughter that would love to play games on a computer. Of course, there are advantages and disadvantages… Whilst some in my family are completely against my daughter playing games, it’s clear to me that sooner or later she will do it anyway. There are friends that have Playstations, iPads, and and and… More than enough opportunities… Now, I thought I will allow her to not only play games, but also give her the opportunity to learn about computers. What is better then a Raspberry for this?
So let’s install a Raspberry for my daughter! Or… Maybe for your daughter or son? 🙂
Btw. This How To assumes you are using a Mac. If not, its not too much different for a Windows computer.
Lets go!
How To Transform Raspberry Into A Gaming Machine
First of all, you need to get a Raspberry, which is since Covid19 and the following chip crisis quite an expensive exercise. The good news is, a Raspberry Pi 3 B is enough. This is good to start!
Secondly, you need to install the software. You are not the first one that leverages on a Raspberry for gaming. There is even an amazing project existing that provides you a full fetched operating system based on Debian called RetroPi. This is however too easy and I also want my daughter to have the opportunity to learn about a full Linux, hence I have chosen to setup Debian Linux and put the RetroPi options on top. This will give my daughter in the future all options, whether it’s gaming or starting to learn programming.
Lets install Debian Linux on the Raspberry Pi
To install Debian, we will be downloading the official Imager from Raspberry. Following this, we will be writing the Debian operating system onto the Raspberry’s SD card.
- Download & Install the Raspberry Imager
- Now you plug the SD card that you like to use for installing Debian Linux for your Raspberry. Note, most likely your Mac will ask you whether you like to initialise the SD Card, Ignore or Eject it. You simply click “Ignore” and don’t worry.
- Start now the Raspberry Imager which you installed in step one and
– hit the first button “Choose OS”. Select the “Raspberry Pi OS (other)”. Within the subsection of this you select “Raspberry Pi OS (Legacy)”. Make sure it’s the “Debian Buster” version. Bullseye does work with RetroPie, but I hear and read about lots of issues. Better to go with Buster at the moment (as of December 2022)
– hit the second button “Choose Storage”. Select the SD Card that you have plugged in step 2.
– finally, hit the third button “Write”. This will install the Raspberry Pi OS onto your SD card. This now takes a while - Once you have written the Raspberry Pi OS onto your SD card, you will prepare it for remote access. This is not a necessary step, but it will make your live easier if you like to access the Raspberry remotely by for example SSH. Furthermore, it allows you to operate the Raspberry without plugging a screen into it. To enable this you may need to unplug and plug the SD card again, because most likely after it was imaged it was ejected automatically:
– open on your Mac the finder and click on the SD card the portion called “boot”. Within this partion you create a file that is called “ssh”. No content no nothing is needed. Simply create a file called “ssh” in the boot partition of the SD card. By this, you make your Raspberry Pi headless and you can access it remotely via SSH. - Next step is to eject the SD card and to plug it into your Raspberry Pi. Start your Raspberry Pi and Login
– SSH: If you like to access the started Raspberry Pi from Remote and with SSH (as configured in step 4) you like to check on the router the IP address it got and simply SSH to this IP Address. The default username is “Pi” and the default password is “raspberry”.
– Screen/Monitor: If you have plugged your Raspberry to a screen and connected mouse and Keyboard, then you will be guided thru the initial setup in which you create a username, a password, but also you connect your Raspberry to the network (e.g. wifi) etc. - Independent whether you logged in by SSH or by Screen/Monitor, you in a first step like to update your Raspberry Pi in order to get the latest functionality, hot fixes, security fixes and software features. Follow for updating the next steps in this How To.
Update your fresh installed Raspberry Pi OS (32-bit)
It’s always important to have the Raspberry up to date. Fortunately, updating it is very simple. You simply hit the below command into the command line:
sudo apt-get update && sudo apt-get upgrade
More about updating a Raspberry can be found in the How To Update & Upgrade Debian Linux blog.
Install RetroPie that to transform Raspberry into a gaming machine
First of all, either via remote SSH or directly on the Raspberry you open a command line (Terminal). Secondly, we will be executing a couple of commands that will install Retropie on top of the Raspberry Pi OS (32 bit) operating system.
- Open the command line (SSH) or Terminal (directly on the Raspberry)
- Ensure you have set the necessary local variables to allow the script working properly. To do so run
locale
This should provide you at least with the following variables:LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8
If any of these is missing, then you need to add them in order to ensure that the installation scripts are working properly. You do so by running for example the below in order to add Language=en_US.UTF-8. If in your case there is another one missing, than of course you run the same command but you add the variable necessary.sudo update-locale LC_ALL="en_US.UTF-8"
- Install the prerequisites for the RetroPie setup scripts
sudo apt install -y git dialog unzip xmlstarlet
- You like to download the latest RetroPie setup script. This you do by the following command:
git clone --depth=1 https://github.com/RetroPie/RetroPie-Setup.git
- Now, you enter into the folder with the RetroPi setup script. To do so enter
cd RetroPie-Setup
- And then we execute the script by entering:
chmod +x retropie_setup.sh sudo ./retropie_setup.sh
- Most likely, there is something like the below popping up at your screen:
- You basically run thru the guided RetroPi setup script. To start, I suggest to go with the “Basic install” options. This will all do for you. If you not happy at a later stage, then you will be able to adjust and fix. There are plenty of sources for this in the Internet. Depending on your Raspberry (e.g. Raspberry 3 or Raspberry 4) this will take a while and play with your patience.
- Once the setup script is finished, you get back to the same screen, that again looks like this:
- To be on the save site, i suggest to in a next step run thru the update. Simply select the second option that is „U Update“. Once done, reboot.
- After reboot, lets now install the Rapberry related items. Run once more the setup script
sudo ./retropie_setup.sh
– Select „C Configuration / tools“
– Select „220 raspiantools“
– Select „2 Install Pixel desktop environment“ - Finally, you would like to configure when RetroPi should start. There are different startup options and you like to select your preferred one. Run the below define the for you best fitting startup. In case you like to switch between RetroPie and Raspberry Desktop (X Desktop), then jump to Additional Information – Start RetroPie from Raspian Desktop / X.
Install the Game Controllers or Joystick
After you have installed your preferred option to start RetroPie, you most likely love to install your preferred controllers or joystick for gaming. This can be done once the RetroPi emulator is started. Of course, in order to do so, you should have controllers available. I did buy a set of cheap controllers in Amazon.
Configuring the controllers:
- Start your RetroPi by the icon you created with the above steps on your Raspian Desktop / X
- The Emulator will immediately tell you, that it did not find any controllers
- Plug your new controllers to the Raspberry. I assume you either have USB cable based controllers or Joysticks or you alternatively have wireless controllers or joysticks with a USB dongle. In my case I have the second one, hence I will be plugging the USB dongles.
- Following this configure the buttons of your controller
Find ROMs
In order to be able to play games you need to have so called ROMs. ROM stays for Read Only Memory. These can be found on the internet. The best way to find ROMs that suit your preference is to leverage on Google. There are tons of ROMs available! Enjoy!
Additional Information
Find out more about security for your fresh installed Raspberry! There are a couple of recommendations that will not hinder you having fun, but some of them even make your life easier whilst increasing considerably the security of you system (for example SSH login by keys instead of passwords). The Hardening of OpenHAB Guide should help you to a large extend for making your system secure. Maybe, at a later stage I am going to write a dedicated guide for RetroPi.
- Find out more about Debian Linux on the official Debian webpage
- Find out more about RetroPi on the official RetroPi webpage
Start RetroPie from Raspian Desktop / X
Option 1 – via Icon and killing Xorg
This chapter will help you to create an icon for RetroPie on your Raspian Desktop X. The below kills via a doubleclick on the icon the X Desktop and starts the RetroPie emulation. (Please note, i found no source in the internet by which I was able to run the Raspian Desktop / X and the RetroPie Emulation in parallel. This is why we by the below kill the X Desktop session).
Open a Terminal and type
cd /home/pie/RetroPi vi start_RetroPi_script.sh
Within the window opened by vi start_RetroPi_script.sh enter the below lines:
#!/bin/sh sudo pkill Xorg sleep 2 emulationstation
Save the script and ensure it is executable by running
sudo chmod +x /home/pi/RetroPi/start_RetroPi_script.sh
Before we create the desktop icon, we would like to ensure this will be opened as seamless as possible. Therefore:
- Open File Manager
- Select Edit->Preferences
- In the General section select “Don’t ask options on launch executable file”.
Click on the Raspi logo, and following this you select “Preferences” and “Main Menu Editor”, as shown in the below picture.
Under the Games section I have created the RetroPi Icon. See below picture.
Aas for the Command, select the path where you have stored your script. In the above steps its /home/pi/RetroPi/start_RetroPi_script.sh. As for the icon, not sure whether you have one on your Raspberry or you need to find one for example in the internet. In any case, the RetroPi icon is to be stored under /home/pi/RetroPi/ . Please be careful, this all is case sensitive.
Option 2 – via Icon and separate user
Option 1 might not work because of a conflicting situation between Raspberry X desktop and Retro Pi Emulations. There is a more extreme option that I found in the internet that allows to switch between the Raspberry X desktop and the Retro Pi Emulations. For this more extreme option we need to create a new user first. The user needs to be exactly the same as the current pi user with which you are working. OK, step by step. First:
Open a termina and find out the memberships of the pi user. To do so you run
cat /etc/group | grep pi
This will output something like this:
pi@raspberrypi:~ $ cat /etc/group | grep pi adm:x:4:pi dialout:x:20:pi cdrom:x:24:pi sudo:x:27:pi audio:x:29:pi,pulse video:x:44:pi plugdev:x:46:pi games:x:60:pi users:x:100:pi input:x:105:pi netdev:x:109:pi pi:x:1000: spi:x:999:pi i2c:x:998:pi gpio:x:997:pi lpadmin:x:117:root,pi
Now this is important. Keep this open in the terminal window and use for the next steps a new terminal window. The above basically shows in which groups the pi user is member. For the new user that we will create, we need these groups. So lets create in another terminal window the new user, that we call “retropi”.
sudo useradd -m -d /home/retropi retropi
Lets ensure the new user has no password (optional you can give it one):
sudo passwd -d retropi
Lets set the default bash for the new user:
sudo chsh -s /bin/bash retropi
We add the relevant groups to the user with the next command. You find the groups to be added in the other terminal window that you in the previous step opened.
sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio,lpadmin retropi
Lets add a couple of items to the new retropi user’s .bashrc allowing to autostart RetroPi
sudo vi /home/retropi/.bashrc
Add the end of the file add the lines
emulationstation exit
Create a new shell script
vi /home/pi/RetroPie/start_retropi_user.sh
Add into the script
sudo agetty -a retropi --noclear tty2
save and exit. Lets make the script executable:
sudo chmod +x /home/pi/RetroPie/start_retropi_user.sh
Click on the Raspi logo, and following this you select “Preferences” and “Main Menu Editor”, as shown in the below picture.
Under the Games section I have created the RetroPi Icon. See below picture.
Aas for the Command, select the path where you have stored your script. In the above steps its /home/pi/RetroPi/start_RetroPi_script.sh. As for the icon, not sure whether you have one on your Raspberry or you need to find one for example in the internet. In any case, the RetroPi icon is to be stored under /home/pi/RetroPi/ . Please be careful, this all is case sensitive.
Option 3 – Separate User
This is to me the option that worked best. Simply create 2 users:
- The main user that you like to use for your “daily business” on the Raspberry. Leverage on the above Option 2 to create your main user that you like to call “whatever”
- The retropi user as described in Option 2. Leverage on the above Option 2 to create the “retropi” user
- Adjust the additional users .bachrc by:
run the following commandsudo vi /hoome/retropi/.bashrc
add the following lines at the end of the .bashrcemulationstation exit
- Adjust the main users .bashrc by:
run the following commandsudo vi /hoome/MAIN USER/.bashrc
The main user should be your main user, but not the user “pi”. Add to your main users (that is not “pi”) the following lines at the end of .bashrcstartx end
Error message: could not install package(s)
During my installation I faced the below error message:
To resolve this error, simply install the packages manually and run the script again.To install the packages manually we leverage on the command “apt install” and add the packages that RetroPi was unable to install. Doing this manually either installs the missing packages or it gives an indication of the problem that then can be resolved. For the above the command is:
sudo apt install libasound2-dev libudev-dev libibus-1.0-dev libdbus-1-dev fcitx-libs-dev libsndio-dev libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxkbcommon-dev libxrandr-dev libxss-dev libxt-dev libxv-dev libxxf86vm-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libgl1-mesa-dev libglu1-mesa-dev libdrm-dev libgbm-dev
Following this and following potential errors were resolved, we restart the RetroPi installation. This can be done by first move to the RetroPi Setup directory
cd RetroPie-Setup/
and secondly, execute the setup script again:
sudo ./retropie_setup.sh
This way you end up with a clean installation.
Error message: Could not successfully build sdl2- SDL (Simple DirectMedia Layer) v2.x
Could not successfully build sdl2- SDL (Simple DirectMedia Layer) v2.x (/home/pi/RetroPie-Setup/tmp/build/sdl2/libsdl2-dev_2.0.10+5rpi_armhf.deb not found).
In order to fix this error message try to run the following:
cp /home/pi/RetroPie-Setup/scriptmodules/system.sh /home/pi/RetroPie-Setup/scriptmodules/system.sh.old vi /home/lea/RetroPie-Setup/scriptmodules/system.sh
Than, edit system.sh by the following:
__os_release="10" __os_codename="buster"
Install SDL2 manually by running:
sudo apt install libsdl2-2.0-0 libsdl2-dev
That’s it! Reboot the system and run the setup script again to see it’s working now.
Error message: You have the experimental desktop GL driver enabled.
You have the experimental desktop GL driver enabled. This is not supported by RetroPie, and Emulation Station as well as emulators may fail to launch. Please disable the experimental desktop GL driver from the rasp-config ‘Advanced Options’ menu.
To fix this run:
sudo raspi-config
- select Advanced Options
- select GL Driver
- select Legacy Original non-GL desktop driver
- reboot and run the setup script again to see it’s working now.
Error message: could not install package(s): omxplayer
Best way to fix this error message is to install the omxplayer manually. For this run the following
sudo apt-get install omxplayer Reading package lists... Done Building dependency tree... Done Reading state information... Done Package omxplayer is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'omxplayer' has no installation candidate
Either you get the omxplayer installed, or it looks like (like in the above) it’s not there. In case its not there, run the following:
/etc/apt/sources.list.d/raspi.list
Add in the raspi.list the following:
deb http://archive.raspberrypi.org/debian/ buster main ui
Once added, run
sudo apt update
Execute again:
sudo apt-get install omxplayer
You should be fine now. Reboot and start the setup again.