Installing Kodi on RetroPie, Mega Super Guide! 4



In a previous series of blog posts, I detailed the process by which we can triple boot the Raspberry Pi with three separate OSes (Raspbian/RetroPie/Openelec). If you’re curious how that was done, I urge you to check it out! Though a little complicated, it provided us with some flexibility to boot RetroPie and OpenELEC – a specific built-from-the-ground-up version of Linux only running Kodi.

This time however, I’d like to simplify the process. What if there was a way to run Kodi directly from RetroPie? More specifically, start Kodi directly from the RetroPie UI interface EmulationStation, instead of rebooting? In this blog post, I’d like to detail the process by which I did this and give a general step-by-step tutorial on basic setup and configuration. I’ll also cover some advanced topics like connecting you RPi to a NAS and configuring display power management. Questions and comments are always welcome and encouraged.

RetroPie, retro-what?

RetroPie, as you may or may not know (and ripped from the RetroPie homepage), “allows you to turn your Raspberry Pi or PC into a retro-gaming machine. It builds upon Raspbian, EmulationStation, RetroArch and many other projects to enable you to play your favourite Arcade, home-console, and classic PC games with the minimum set-up. For power users it also provides a large variety of configuration tools to customise the system as you want. RetroPie sits on top of a full OS, you can install it on an existing Raspbian, or start with the RetroPie image and add additional software later”

And Kodi, well, unless you’ve been living under a rock for the last while, you’d know what it is and what it does – no need to explain.

All righty, enough of that. I assume you know why you’re here and what you want to accomplish – let me help you along your journey!

Requirements

  • Raspberry Pi 3/2/1/0
  • USB gamepad (Buffalo Classic USB, or old Xbox, 360, PS controller)
  • MicroSD card (at least 16GB) and an SD card reader
  • HDMI cable, Ethernet cable, case…
  • Mini USB power adapter (at least 2 Amps for RPi 2/3)
  • Some free time and a little command line know-how would help!

Overview

Please note, I strive to keep my articles relevant and up-to-date but inevitably guides like these will not reflect the latest and greatest, as such, certain things: screens, menu items, & links may likely change over time. I’m open to user input for relevancy. I produced the following guide with RetroPie version 3.8.1.

Write the RetroPie Image

Download

Download and decompress the most recent version of RetroPie. There should be two versions of RetroPie; one for the RPi Zero or 1 and another for the RPi 2/3. Please download accordingly.

Format

It’s probably good practice to format your SD card, not technically needed when you write an image to a card, but we’ll do so anyway. So while we’re at it insert the SD card into your reader and proceed to format.

If you’re on Windows, go to the trusty Explorer, find the SD card, right-click it, and select Format from the context menu. Select the FAT32 option and click the Start button.

If you’re on a Mac, you can do so by opening the Disk Utility by navigating to Applications > Utilities > Disk Utility. Select your SD card in the left pane. For Yosemite and older, navigate to the Erase tab, select MS-DOS (FAT) as the Format, give it a name, and click the Erase button. For El Capitan and newer, simply click the Erase button, Select MS-DOS (FAT) as the Format, give it a name, and click the Erase button.

If you’re on Linux, you can use a tool called GParted to proceed with the formatting. I’ll not bore you with the details.

Install RetroPie

Next, we’ll need to write the RetroPie image to your SD card. Various options exit to accomplish this feat.

Windows

For Windows we can use a tool called Win32DiskImager. Download this small executable and proceed with these instructions.

Mac OS

There’s a great tool called ApplePi-Baker. Get the application. ApplePi-Baker does require administrative privileges so don’t be surprised if it asks for your password.

Select your SD card in the left hand column once you open the Application. Hit the “Restore Backup” button and select the RetroPie SD-Card Image that you hopefully unzipped – it should only have a .IMG file extension and not a .GZ extension.

Linux

On Linux, get to the command line and proceed as follows, assuming your SD card in sdb.

dd if=retropie-4.1-rpi1_zero.img of=/dev/sdb bs=1M

Configuration

Boot up

Plug in everything as this point while being mindful to connect the power adapter ’til the very end; so connect SD card, TV/Monitor, USB keyboard, gamepad, ethernet, and power adapter.

Now, there are a couple of ways to get at the command line – because at some point you’ll need to! So I’ll show you how now. You can either exit the RetroPie UI to get to the shell or use SSH, the latter being the more difficult option.

RetroPie’s Shell

With a physically attach USB keyboard, you can simply press F4 to exit the RetroPie UI and be transported to the shell. Simple. To reboot RetroPie from the command line, do:

sudo reboot

SSH Connection

More complicated is using SSH. For this to work, it helps having another computer connected to the same physical switch or router as the RPi. So the obvious assumption here is that your RPi is connected to your network, either via Ethernet or WiFi. If connected to your router, your router most certainly has provided it with an IP address. Assume we’ve connected the RPi via an Ethernet cable. We’ll cover WiFi a little later.

Windows

Download a tool called putty – a small application that’s used to make secure shell connections.

Putty RetroPie SSH Connection

Putty RetroPie SSH Connection

Make a connection as above.

If retropie does not work as the Host Name, try to ascertain the IP address of your RPi yourself – I know you can do it! The IP address should be attainable by inspecting your router Device’s page –  I do hope you know how to access your router’s configuration interface… I’ll give you a hint, it’s usually in something like DHCP Leases or Device List.

An alternate method to find the IP address using the RetroPie UI is to go into the RetroPie options from the main menu, and select the last option Show IP address.

If putty succeeds to connect to your RPi, you’ll be prompted for the username and password, speaking of which, the default credentials should be:

username: pi
password: raspberry

Mac OS / Linux

To connect to your RPi for both Mac and Linux, you can simply type the below from a terminal.

ssh pi@retropie

Or:

ssh pi@IP_ADDRESSS

Change Password

It’s probably good practice to change the default user’s password – in this case the Pi user. Run the command:

passwd

You’ll be prompted for current password and then a new password, twice.

Expand Filesystem

On first boot, RetroPie will have hopefully expanded the filesystem automatically, if not, you’ll need to connect via SSH and do it manually. You can tell if RetroPie has expanded the filesystem by running the df command and looking for the /dev/root size.

df -h

But if you want to run the expansion regardless, connect to your Pi via SSH or from the UI hit F4, and run the following command:

sudo raspi-config

And then select, “Expand filesystem“.

WiFi

For WiFi I suggest you take a look at this link. The RetroPie peeps do a good job here to walk you through the WiFi setup.

Update RetroPie

As we already know, RetroPie runs on a flown blown Linux version. The following commands help to ensure that all packages are up to date. Press F4 to get back to the shell/command line or use SSH, and run the these commands:

sudo apt-get update
sudo apt-get upgrade

Moving ROMs

What are ROMs you say? ROMs, in essence are the games – and no, I cannot provide any, nice try! But before you can start playing though, you’ll need to find some and copy them over to RetroPie. There are many ways to accomplish this. I’ll offer the easiest method.

Samba Shares

From a Windows machine type \\retropie into the computer folder. Again, you can also replace retropie with your Raspberry Pi’s IP address as above. A window should open, as in:

Samba Share on RetroPie from Windows

Samba Share on RetroPie from Windows

If on MAC OS X open finder, select “Go” menu and “Connect to Server”. Type smb://retropie and hit “Connect”. At this point you can navigate in the roms folder and dump your roms in the appropriate folder. So you know, folders are grouped by console in the roms folder, i.e.: snes, nes, ps…

From USB

ROMs can also be installed via USB stick but this requires a little Linux knowledge and ease with the command line – but that’s a little beyond the scope of this post. Instead of delving further off course – as this blog post is already getting too long – I’ll point you to the RetroPie Wiki, and hopefully they’ll lead you in the right direction.

From SSH/SFTP

ROMs can also be installed via SSH/SFTP – if you don’t know what that is don’t worry! Read on…

SSH or secure shell, is a means of using a terminal-like interface to connect to a Unix based machine to issue commands. If you don’t already know, the “secure” portion comes from the fact that the communication is encrypted. I’m assuming you know what FTP is (file transfer protocol), therefore SFTP is a means of transferring files similarly to FTP but doing so over the SSH protocol, hence the acronym SFTP.

In short, there are many SFTP programs that you can use, for Windows many people use WinSCP for the Mac crowd, you guys can use something like Cyberduck.

Below is a screenshot of the connection details with the Windows program WinSCP.

WinSCP Credentials

WinSCP Credentials

Connection Details

  • Protocol: SFTP
  • Host name: You can try to use RetroPie and see if that works, if not use the IP address. To find the IP address of your RetroPie, go into RetroPie options from the main menu, and select the last option Show IP address.
  • Username: pi (default)
  • Password: raspberry (default)

Oh, the first time you connect to RPi via SFTP, you’ll undoubtedly get prompted to accept the key, just hit ok.

WinSCP Key Prompt

WinSCP Key Prompt

I’ll just say this, all ROMs at some point or another will end up in the following path below, where $CONSOLE is the name of the target console, e.g. snes or arcade.

/home/pi/RetroPie/roms/$CONSOLE

How you get them in there, really doesn’t matter – just know that it’s the place where RetroPie looks for the games on boot up.

Controller Setup

You’re probably itching to a play a game right about now, but you’re still not done. All that’s really left is to configure your USB gamepad to work with your Pi. Most individuals recommend the Buffalo Classic USB Gamepad since it’s cheap, and highly compatible with the Pi – it should just work out-of-box, as they say.

I, on the other hand, am using an old Xbox controller with an adapter. The adapter is necessary because of Microsoft’s proprietary connector (but it’s really USB). Search for “Microsoft Xbox Controller to USB Female Adapter For Computer PC” on Ebay, if you’re a little curious.

Also, if you have an Xbox 360 controller collecting dust somewhere, that will work as well. But this requires some extra work and you’ll need to install a driver. If interested, take a look at this here. In fact, you can use all sort of controllers, some more easy than others to set up. I’ll leave the selection of controller for you as your homework…

Once you have a controller, configure it to work with the menu system and games. Boot up your RPi. Your RPi will automatically launch the RetroPie UI where you will be prompted to configure the controller. If you mess up, don’t worry — you can access this configuration menu again later by pressing Start in the RetroPie UI or by typing F4 on your keyboard and then rebooting your Pi.

Controller Configuration

Controller Configuration

Advanced Configuration

All rightly, now that’s taken care of, I’d like to offer some advance setup techniques I’ve used.

Kodi Installation

As of this writing, RetroPie currently installs Kodi 16.1 Jarvis.

To install Kodi, launch the RetroPie Setup either by going to the configuration screen with the UI, in which case you want “RETROPIE-SETUP” option, or by logging into your RPi via SSH. I’ll do the latter because you know… it’s more fun…, and besides if you followed this guide, or some of my other guides, you’re probably a command line pro by now!

Once logged in, go into the RetroPie Setup directory and launch the RetroPie setup script.

cd /home/pi/RetroPie-Setup/
sudo ./retropie_setup.sh

Go to “Manage packages” and then “Manage optionally packages” – that may or may not be different for you – YMMV. Then locate Kodi and press enter (I have it already installed).

Manage Optional Packages Kod Install

Manage Optional Packages Kod Install

Kodi Integration

Since RetroPie boots directly into EmulationStation, the problem becomes; how do we launch Kodi? Well, simple enough, we’ll create a “faux” entry for Kodi in ES.

Let’s start by creating an entry in EmulationStation’s main configuration file.

sudo nano /etc/emulationstation/es_systems.cfg

Add then add the following at the very end of the file, right before the </systemList> tag.

  <system>
    <fullname>Kodi</fullname>
    <name>Kodi</name>
    <path>~/RetroPie/roms/kodi</path>
    <extension>.sh</extension>
    <command>bash %ROM%</command>
    <platform>Kodi</platform>
    <theme>Kodi</theme>
  </system>

Instead of altering the system level configuration you can make a copy of it and save it to your home directory. And edit that one instead.

If you’d prefer not to change the system level EmulationSystem configuration file, then do the below.

sudo cp /etc/emulationstation/es_systems.cfg /home/pi/.emulationstation/es_systems.cfg
sudo nano /home/pi/.emulationstation/es_systems.cfg 

Next create a launcher file in the directory: /home/pi/RetroPie/roms/kodi by doing the below:

cd /home/pi/RetroPie/roms/kodi
sudo nano kodi.sh

And add the following simple line in the file kodi.sh:

kodi-standalone

If “kodi-standalone” is not on your system (you can verify with the “which” command) then simply put “kodi” in the above file instead.

The which command will return nothing if kodi-standalone is not found on your system (more specifically, not found in your system path).

which kodi-standalone

Finally, if you got all that sorted out, the last thing to do is to make the file executable.

chmod +x /home/pi/RetroPie/roms/kodi/kodi.sh

Great! Now inspect your work by rebooting. You should see the following new menu item:

EmulationStation Kodi Menu

EmulationStation Kodi Menu

And within that, a sub-menu item as follows:

EmulationStation Kodi Menu

EmulationStation Kodi Menu

Press A on your controller (which I hope works by now) and well, it should launch Kodi… Hope it works for you! Quitting Kodi should also plop you back to ES. If it all works, hooray! If it doesn’t, sorry…

Storing ROMs on a NAS (Advanced)

Lastly, I chose not to keep my ROMs on the RetroPie itself and instead decided to put them all on my NAS or Network Attached Server. You can do the same if you have a NAS or any other networked computer or server around your house. I won’t go into details on how to configure the server side of things, so this assumes you’ve got that portion already working and all. So, this may be highly specific to my case, but if you wanna give it go, read on…

To accomplish this, I will install a service that auto mounts the shared filesystem on demand, aptly named, autofs.

Since my NAS speaks SMB/CIFS (Windows Networking Protocol), I will configure autofs to use said protocol. At minimum, you’ll need the IP address, user/pass credentials (stored in the file /etc/cifs.creds) and a shared directory (roms, in my case) for your server. I won’t get into detail what all this means, so if your curious, Google is your friend!

So let’s first install autofs.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install autofs cifs-utils

Now installed, we must configure the mount point.

sudo nano /etc/auto.master

Add the following:

/media/MY_NAS /etc/auto.cifs  --timeout=6000    --ghost

Now create the /etc/auto.cifs and add the following, while ensuring you alter for you case!

sudo nano /etc/auto.cifs
roms  -fstype=cifs,rw,nounix,iocharset=utf8,_netdev,uid=pi,gid=users,file_mode=0777,dir_mode=0777,credentials=/etc/cifs.creds    ://YOUR_NAS_IP/roms

And lastly the credentials file.

sudo nano /etc/cifs.creds

Add the following to that file:

username=YOUR_USERNAME
password=YOUR_PASSWORD

Now restart the service and hope nay, pray that you see you files in /media/MY_NAS.

sudo service autofs restart

Lastly, because RetroPie only sees ROMs in the /home/pi/RetroPie/roms folder, we’ll need to create a link to the shared mount point for each console. I structured my shared directory “roms” to have within in it, folders per console, i.e.: a directory for nes, snes, gb, etc…

Below, I use “snes” as an example.

cd /home/pi/RetroPie/roms
rmdir snes
ln -s /media/MY_NAS/roms/snes snes

Kodi Display Power Management (Advanced)

The Raspberry Pi, for all its marvels, lacks one important thing – a power or on/off switch. The minute the micro USB adapter gets plugged in, the RPi boots. If the power is pulled out, well, the RPi dies rather ungracefully and SD card corruption may occur. More over, the RPi doesn’t go into “standby” and can’t “wake” or “resume” from standby. As a consequence you are left with two options: 1) keep the RPi on – at all times or 2) shut it down via the interface and start it up by plugging in the power (or use a USB toggle switch). As a side note, power switches, that can gracefully shut down the RPi, can indeed be procured – but they aren’t cheap.

I don’t mind keeping the RPi on, as it’s not a power hungry device, however my monitor (tv) is. I’d much prefer a way to simply put the display to sleep or into standby mode when I’m not using Kodi. As luck would have it, there’s a way to put the display to sleep from the command line, tying it into Kodi however, is not so trivial. I will show you my solution.

Keep in mind this solution will only work while in Kodi and NOT in EmulationStation.

Create two files in any directory on RetroPie. I created the following directory.

mkdir /home/pi/kodi_scripts

Now for the first file:

sudo nano screen_off.sh
#!/bin/sh
tvservice -o

And the second:

sudo nano screen_on.sh
#!/bin/sh
tvservice -p
killall -9 kodi.bin

Now we’ll need to install a Kodi Addon called “Kodi Callbacks“. I will assume that you know how to install addons in Kodi, afterall, this is the advanced section of the guide!

This addon enables us to provide user definable actions for specific events within Kodi. I will use two specific events: “on Idle” with an idleTime of 180 seconds – which will call the script screen_off.sh and “on Resume After Idle” with a afterIdleTime of 180 – which will call the script screen_on.sh.

The scripts are first associated to tasks before they can be tied into events within the addon. As they say, a picture is worth a thousand words, so keep on reading…

This is for the first task.

Kodi Callbacks - Task 1 Screen Off

Kodi Callbacks – Task 1 Screen Off

And the second.

Kodi Callbacks - Task 2 Screen On

Kodi Callbacks – Task 2 Screen On

Now we tie the Tasks into the Events as such.

Kodi Callbacks - Event 1 - Screen Off

Kodi Callbacks – Event 1 – Screen Off

And the second event.

Kodi Callbacks - Event 2 - Screen On

Kodi Callbacks – Event 2 – Screen On

So after all this work, the display *should* go into standby after 180 seconds. Any keep press, whether it be on the Kodi remote (remote setup with Kodi is not covered here) or keyboard (if you have one attached), should bring the monitor out of standby!

Conclusion

Oh well, that brings this rather lengthy guide to an end – and about time too! Thanks for visiting this guide, and I do hope it’s proved helpful in your gaming endeavors. Questions and comments are always welcome and encouraged.


Leave a comment

Your email address will not be published. Required fields are marked *

4 thoughts on “Installing Kodi on RetroPie, Mega Super Guide!