Raspberry Pi Kiosk Mode using Raspbian Lite

Download the latest Rasbian Lite from the Raspberry Pi Foundation (at time of writing we’re on Jessie) and unpack it so you’ve got a .img file.

Setting up the SD card

NOTE: The following section is a truncated version of the Mac instructions from the Raspberry Pi Foundation. Instructions for other operating systems (or further details for Mac users if the below fails) are available here: https://www.raspberrypi.org/documentation/installation/installing-images/README.md.

  • Open a terminal window and run: diskutil list
  • From the list identify the disk (not partition) of your SD card in this instance it is disk4:

  • Unmount the SD card diskutil unmountDisk /dev/disk<NUMBER>
  • Copy the data to the card sudo dd bs=1m if=route/to/disk/image.img of=/dev/rdisk<NUMBER>
  • Wait. There will be no on screen info during this time.
  • Run:sudo diskutil eject /dev/rdiskthen remove the disk from your computer and plug it into your Pi.

Setting up the Pi

The default login is set to:

  • Username: Pi
  • Password: Raspberry

SSH

This is worth doing as if you have a short piece of network cable you can create a direct connection between your pi and your main computer, allowing you to use your full keyboard and screen to set up your pi. Cool huh? If you have a screen and keyboard you can setup SSH using raspi-config:

  1. type sudo raspi-config
  2. select interfacing options
  3. select SSH
  4. choose Yes
  5. select OK
  6. choose finish

Running headless? In that case you will want to create a file named ssh on the boot partition of the SD card. When the Pi boots, it looks for the ‘ssh’ file. If it is found, SSH is enabled, and the file is deleted. The content of the file does not matter: it could contain text, or nothing at all. Do these instructions look familiar? They’re the same ones as appear here: https://www.raspberrypi.org/documentation/remote-access/ssh/.

Finding the IP address of your pi

If you have a monitor to hand the simplest way to find your ip address is to boot the pi and type hostname -I. If you’re running headless you probably want to use nmap as per the instructions on the raspberry pi foundation.

WiFi

If you don’t need WiFi for your end setup skip this step and just use a network cable to connect yourself directly to the pi. Setup your network by editing wpa_supplicant.conf to include your network data (instructions via The Pi Hut). Open the file using Nano: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf Then add the following to the bottom of it:

network={
    ssid="YOUR_SSID"
    psk="YOUR_PASSWORD"
}

Then save (ctrl+o) and exit (ctrl+x). Run sudo reboot to connect to your network.

Code editor

If like me, you have a preference as to text editor you will want to install that next: sudo apt-get install vim

Check everything’s up-to-date

Even though you only just downloaded the disk image you will want to run the following: sudo apt-get update && sudo apt-get -y upgrade

Install the stuff you need in order to have a GUI

sudo apt-get install --no-install-recommends xserver-xorg xinit xserver-xorg-video-fbdev lxde lxde-common lightdm

  • --no-install-recommends stops it installing ALL THE THINGS which it will otherwise do.
  • x gives you a screen session
  • lxde gives you the UI
  • light dm is the login manager

Do some configuration

Type sudo raspi-config into the command line and do the following:

  1. Expand the file system: Advanced Options > Expand Filesystem.
  2. Disable overscan: Advanced Options > Disable Overscan. This helps ensure the display fills the entire screen rather than leaving black bars down the sides.

Install Chromium

This is now as simple as sudo apt-get install chromium-browser. So all of this faffing is no longer necessary:

This should be simple… but really isn’t. Fortunately this blog post explains how to do it. These links take you to the latest libcrypt11, Chromium and Chromium codecs. Once you have the correct links you need to wget them onto the Pi then install. (It’s simplest to run headless when doing this because copy/paste).

wget http://launchpadlibrarian.net/237755896/libgcrypt11_1.5.3-2ubuntu4.3_armhf.deb
wget http://launchpadlibrarian.net/263322752/chromium-browser_51.0.2704.79-0ubuntu0.14.04.1.1121_armhf.deb
wget http://launchpadlibrarian.net/263322754/chromium-codecs-ffmpeg-extra_51.0.2704.79-0ubuntu0.14.04.1.1121_armhf.deb

sudo dpkg -i libgcrypt11_1.5.3-2ubuntu4.3_armhf.deb
sudo dpkg -i chromium-browser_51.0.2704.79-0ubuntu0.14.04.1.1121_armhf.deb
sudo dpkg -i chromium-codecs-ffmpeg-extra_51.0.2704.79-0ubuntu0.14.04.1.1121_armhf.deb

You may need to run sudo apt-get -f install after you’ve done this to install the dependencies.

Unclutter

Install unclutter to hide the curser: sudo apt-get install unclutter

Auto-login

sudo vim /etc/lightdm/lightdm.conf

Then uncomment and amend the following lines so that they match the below:

autologin-user=pi autologin-user-timeout=0

Setup your .xsession script

If you don’t have a .xsession file in /home/pi/ then create one and add the following to it:

# Dont want screensavers or screen blanking
 xset s off &
 xset -dpms &
 xset s noblank &

# Hide the mouse cursor
[ ! -x "`which unclutter 2>/dev/null`" ] || unclutter -idle 10 -noevents &

# Sit and wait until you can hit the URL you'll be showing in the kiosk
while ! curl http://urlofthepageyouwanttoload.co.uk 2>/dev/null | grep -q "String that's on the page you want to load";
do sleep 1
done

# Sit for 3 seconds
sleep 3

# Open chrome in incognito mode + kiosk mode
/usr/bin/chromium-browser --incognito --kiosk http://urlofthepageyouwanttoload.co.uk

Make sure everything works

Run sudo reboot. If the chromium browser doesn’t fill the whole screen you may need to edit .config/chromium/Default/Preferences It’s an awful file to navigate visually and the code is in one very long string, I’ve put it on separate lines here to make it more readable.

"window_placement":{
    "bottom":1050,
    "docked":false,
    "left":0,
    "maximized":false,
    "right":1680,
    "top":0,
    "work_area_bottom":1050,
    "work_area_left":0,
    "work_area_right":1680,
    "work_area_top":0},

You need to change the values for "bottom" and "right" to the maximum dimensions of your screen and ensure that "top" and "left" are 0. EDIT: as Jacob says in the comments these settings don’t appear to be in the file any more. However, you can fix it by adding --window-size=1920,1080 to the browser launch line in your .xsession script. I found that it still wasn’t launching the browser squarely in the center of the screen so I added --window-postion=0,0 as well. If you need to set other options on launch you’re best having a look at Peter Beverloo’s awesomely useful list of chromium command line swatches.

Things I read in order to make this happen (that aren’t explicitly mentioned above)

Thanks everyone :)