Raspberry Pi Kiosk Mode using Raspbian Lite

EDIT: I have updated this post to remove all the bits that have changed as it was getting unreadable. I use this as a notebook a lot of the time so I didn’t really want to have two posts with the same or very similar information in them.

Download the latest Rasbian Lite from the Raspberry Pi Foundation 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/Vim: sudo {{ editor }} /etc/wpa_supplicant/wpa_supplicant.conf Then add the following to the bottom of it:

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

Then save and exit (Nano: ctrl+o ctrl+x, Vim: :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 Browser

sudo apt-get install chromium-browser

Unclutter

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 EDIT: now incorporating additions by @thinkl33t to set the browser size automatically.:

# Set this to your URL - it must return a 200 OK when called, not a redirect.
export URL={{kiosk.url}}

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

# Hide the mouse cursor
unclutter -idle 10 -noevents &

# Sit and wait until you can hit the URL you'll be showing in the kiosk
while ! curl -s -o /dev/null -w "%{http_code}" ${URL} | grep -q "200"; do
  sleep 1
done

# get screen resolution
WIDTH=`sudo fbset -s | grep "geometry" | cut -d " " -f6`
HEIGHT=`sudo fbset -s | grep "geometry" | cut -d " " -f7`

# Open chrome in incognito mode + kiosk mode
/usr/bin/chromium-browser --window-size=${WIDTH},${HEIGHT} --window-position=0,0 --incognito --kiosk ${URL}

Chromium swatches

Jacob told me about these in the comments on my original unedited WP post as I was originally using a settings file that no longer exists to set the size of the browser. He didn’t leave a URL so I can’t easily link him until I manage to get my comments up and running again.

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.

Make sure everything works

Reboot: sudo reboot.

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

Thanks everyone :)

Disclosure

As an Amazon Associate I earn from qualifying purchases.