How to setup Raspberry PI 4 in Kiosk Mode

Setting up Raspberry Pi 4 in kiosk mode is pretty straight forward. This setup has also been tested with a touch screen. We will use raspbian buster full [version sep. 2019], openbox, etcher and chromium with on screen keyboard. You could use “fullpage OS”, however this might be another post for the future. Fullpage OS is in my opinion more suitable for displaying dashboards or websites without keyboard interaction…

Following what you need:

Step 1
Download Raspian Buster Full [.zip]

Step 2
Start Etcher to flash an SD card with the Raspbian Buster Lite - use the .zip file.
The easiest way is to attach a screen/monitor and mouse, keyboard to your Pi, if not please note:
Since Raspberry Pi [Jesse] SSH is disabled, if you haven’t connected your Pi to a screen, you need to place an empty file called [SSH], with no extension, into the /boot/ directory.
Insert the SD card into your Raspberry Pi and connect the Pi to your network.

Step 3
Search for the hostname:
Shell on Unix Systems and Command Prompt [cmd] on Windows:

ping raspi
If that’s not working try:
ping raspberrypi

If you have problems to connect to your Pi try the next step.

Step 4
Use nmap to find your Raspberry’s IP.
Windows
On Windows, open the Network and Sharing Center [Control Panel > Network and Sharing Center > View network connections].

Linux
On linux, type the following command in a shell:

hostname -I

Then run this command using sudo:

sudo nmap -sn 10.0.1.0/24

You’ll see all devices connected to the network:

...
MAC Address: B3:28:EC:79:80:F2 (Raspberry Pi Foundation)
Nmap scan report for raspberrypi.attlocal.net (10.0.1.13)
Host is up (0.51s latency).
MAC Address: B5:23:EC:55:3D:7B (Raspberry Pi Foundation)
...
From here you can discover the IP address for each Pi.

Step 5
Use SSH to connect to your Pi. Either putty, cmd or shell use:

ssh pi@raspberrypi

Step 6
Let’s start the setup… After startup insert the default login details for Raspbian Buster:

username:

pi
password:
raspberry

After login, run the following commands:

sudo apt-get purge wolfram-engine scratch scratch2 nuscratch sonic-pi idle3 -y
sudo apt-get purge smartsim java-common minecraft-pi libreoffice* -y

Clean up local repositories:

sudo apt-get clean
sudo apt-get autoremove -y

Update & upgrade Raspbian Buster:

sudo apt-get update
sudo apt-get upgrade

Step 7
Type:

sudo raspi-config

Change the following:

  • [1] Change User Password -> Change password for the current user
  • [2] Network Options -> Configure network settings -> Hostname
  • [3] Boot options -> CLI Desktop -> Console Autologin
  • [4] Localisation Options -> Change Time zone
  • [5] Interfacing Options -> SSH -> Enable
  • [5] Interface Options -> VNC -> Enable
  • [7] Advanced Options -> Update

Finish -> Reboot.

Step 8
SSH into [your hostname] [port 22]
Login with user: pi and [new password]

Step 8
Install unclutter to hide mouse and xdotool allows us through our bash script to execute key presses without anyone being on the device:

sudo apt-get install xdotool unclutter sed

Step 9
Create kiosk bash script:

sudo nano /home/pi/kiosk.sh

Insert:

#!/bin/bash
xset s noblank  #turn off screen blanking
xset s off      #turn off screen saver
xset -dpms      #turn off display power management system

unclutter -idle 0.5 -root &

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences

/usr/bin/chromium-browser  http://YourWebsite.com

Exit file with:

ctrl-o and then ctrl-x

sudo reboot

Step 10
On Pi after restart, in chromium go to: http://tiny.cc/wnnycz and add to chrome and enable.

Through SSH:

sudo nano /home/pi/kiosk.sh

Insert [–noerrdialogs –disable-infobars –kiosk before your website]:

#!/bin/bash
xset s noblank # turn off screen blanking
xset s off # turn off screen saver
xset -dpms # turn off display power management system

unclutter -idle 0.5 -root &

# Remove exit errors from the config files that could trigger a warning
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences

# Start chromium-browser and URL
/usr/bin/chromium-browser  --noerrdialogs --disable-infobars --kiosk http://YourWebsite.com

Exit file with ctrl-o and ctrl-x, then restart with:

sudo reboot

Step 11
To start kiosk on boot we need to create a new file:

sudo nano /lib/systemd/system/kiosk.service

Insert into file:

[Unit]
Description=Chromium Kiosk
Wants=graphical.target
After=graphical.target

[Service]
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
Type=simple
ExecStart=/bin/bash /home/pi/kiosk.sh
Restart=on-abort
User=pi
Group=pi

[Install]
WantedBy=graphical.target

Close file again with:

ctrl-o and then ctrl-x

sudo reboot

Step 11
After restart you should see your website in full mode / kiosk mode. If you notice that the webpage doesn’t fill the whole screen.. press ctrl + alt + 2 and you are able to open another instance. Log on with your credentials and go to:

cd /boot/

sudo nano config.txt

Change and enable disable_overscan=0 to disable_overscan=1

sudo reboot

Step 12

Done.