Install browser as kiosk mode on raspberry with touch screen

Requirements

This tutorial has been written for this specific following configuration. It might work if you have something similar, but you might have to tweak some parameters.

Here are the components that have been used:

  • Raspberry 3B
  • Touch Screen 3.5
  • SD Card 16GB

Initial setup

As a start, you will need to install a clear image of Raspberry Pi OS Lite on your SD card, using the Raspberry Imager.

Once the image has been written to your SD card, you can insert your card in your RPI, connect an HDMI screen, a keyboard and a mouse.

Now, perform all the updates on this device and install the needed packages.

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y xserver-xorg raspberrypi-ui-mods lightdm chromium-browser git

Once the initial setup is done, you’ll have to execute

sudo raspi-config

raspi-config to set up the auto-boot. Go to System Options > Boot / Auto Login and select Desktop Auto-login.

Kiosk configuration

Now that the OS is ready, let’s move on with the kiosk mode configuration and LCD configuration.

You should first prevent the cursor to display. For that, edit the following file: /etc/lightdm/lightdm.conf and uncomment that following line by adding -nocursor at the end:

xserver-command=X -nocursor

Now, prepare your script that will automatically start the kiosk mode by editing /usr/local/bin/kiosk.sh with your own URL:

#!/bin/sh

xset s noblank
xset s off
xset -dpms

/usr/bin/chromium-browser --app="https://my.url/page" \
  --kiosk \
  --noerrdialogs \
  --disable-session-crashed-bubble \
  --disable-infobars \
  --check-for-update-interval=604800 \
  --disable-pinch \
  --force-device-scale-factor=0.79 \
  --disable-gpu

and make that script executable:

chmod +x /usr/local/bin/kiosk.sh

Create a service to auto-run on startup by creating the file /etc/systemd/system/kiosk.service

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

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

[Install]
WantedBy=graphical.target

and enable that service:

systemctl daemon-reload
systemctl enable --now kiosk

LCD configuration

Now we want to configure the LCD screen to display our content instead of using HDMI output. Type the following commands in order to install drivers and set your LCD screen working:

cd /opt
sudo apt-get install xinput-calibrator
git clone https://github.com/goodtft/LCD-show.git
chmod -R 755 LCD-show
cd LCD-show/
sudo ./LCD35-show

You might have to calibrate your touch screen by going to Preferences > Calibrate touch screen):

If you need to rotate the screen, you can do so by executing those commands:

cd /opt/LCD-show/
sudo ./rotate.sh 90

and you’re all set, your rpi as kiosk with touch screen should now work fine !

Optional: disable the LEDs

If you want to prevent LEDs from blinking on your raspberry, you can easily disable that by adding these lines at the end of this file: /boot/config.txt

# Turn off Power LED
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off
# Turn off Activity LED
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
# Turn off Ethernet ACT LED
dtparam=eth_led0=14
# Turn off Ethernet LNK LED
dtparam=eth_led1=14