Skip to content

Instantly share code, notes, and snippets.

@flokli
Last active October 20, 2023 09:50
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flokli/ddf08bf68d11ee0bc2c4 to your computer and use it in GitHub Desktop.
Save flokli/ddf08bf68d11ee0bc2c4 to your computer and use it in GitHub Desktop.
Raspberry Pi with LCD display

Raspberry Pi with Touch Display - Installation Instructions

Operating System

  • prepare an SD Card as described on archlinuxarm.org
  • SSH into your system, add your public key (initial root password is "root")
  • disable root password by calling passwd -d root
  • set a useful hostname by calling echo $hostname > /etc/hostname
  • run pacman -Suy to update packages

Hardware support

LCD Module

The LCD Module works is fb_ili9341compatible and is supported by the linux kernel. It needs enabled SPI support to work. Uncomment device_tree_param=spi=on in /boot/config.txt to enable.

Now, add the following to /etc/modules-load.d/fbtft_device.conf:

spi_bcm2708
fbtft_device

And set module parameters in /etc/modprobe.d/fbtft_device.conf:

options fbtft_device custom name=fb_ili9341 speed=48000000 gpios=dc:22,reset:27 bgr=1 rotate=0

After a reboot, this should generate a /dev/fb1 framebuffer device. For a quick test, you can cat /dev/urandom > /dev/fb1 which should show some noise on the display.

Touch controller

The Touch Controller ( probably XPT2046, compatible with ADS7843) is supported by the ads7846 kernel driver . However, there is no builtin way to add a new touch input device on demand by loading the module with some parameters, so we need to compile an external kernel module which does exactly that for us:

pacman -S base-devel linux-raspberrypi-headers git
git clone https://github.com/notro/fbtft_tools.git
cd fbtft_tools/ads7846_device
make
make install
depmod -a

Of course, we could also put this inside a PKGBUILD to keep everything clean. Remember you'll have to rebuild the module on each kernel update.

We now add the needed kernel modules and module parameters:

/etc/modules-load.d/ads7846_device.conf:

spi_bcm2708
ads7846_device

/etc/modprobe.d/ads7846_device.conf:

options ads7846_device model=7846 cs=1 gpio_pendown=17  speed=1000000 keep_vref_on=1 swap_xy=0 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

This should generate a new input device in /proc/bus/input/devices. If you want, to can pacman -S evtest and watch some events when touching the display.

GPIO

TODO

Software

Utilities

Install some basic applications to make your life easier:

pacman -S vim wget rsync htop strace lsof tree

Graphical Interface

Install the following packages:

pacman -S xorg-server xorg-xinit xorg-xset xf86-video-fbdev xterm

Needed/Recommended packages

Install needed/recommended packages:

pacman -S matchbox-window-manager unclutter xdotool

Allow non-console users to start X

To allow non-console users to start X, add the following to /etc/X11/Xwrapper.config:

 allowed_users=anybody

/etc/X11/xorg.conf.d

This is where X server configuration should stay. To configure X11 to use the Framebuffer provided by the LCD, add the following to /etc/X11/xorg.conf.d/99-fbdev.conf:

Section "Device"
        Identifier "myfb"
        Driver "fbdev"
        Option "fbdev" "/dev/fb1"
EndSection
Custom keyboard layout

A custom keyboard layout can be set by adding a file /etc/X11/xorg.conf.d/20-keyboard.conf:

Section "InputClass"
        Identifier "German Keyboard"
        MatchIsKeyboard "yes"
        Option "XkbLayout" "de"
EndSection

Kiosk Mode (Midori Webbrowser)

This mode will start a fullscreen browser.

Required Packages

Of course, you need a Browser. We use Midori here, because its provided in Archlinux ARM and based on the WebbKit engine.

pacman -S midori
User

Create a kiosk user to run X:

useradd kiosk -m
.xinitrc

Create a .xinitrc in kiosk's home directory (su kiosk -):

#!/bin/sh
# disable screen blanking
xset -dpms
xset s off

# automatically hide mouse cursor after if idle
unclutter &

# start matchbox window manager
matchbox-window-manager -use_titlebar no &

# queue click event in webbrowser to focus webview
xdotool sleep 10 mousemove 0 0 click 1 &

# start webbrowser
midori -e Fullscreen -a $website_url
systemd unit file

To simplify starting a session, you could add a unit file to /etc/systemd/system/kiosk.service:

[Service]
Environment = "DISPLAY=:0"
ExecStart = /usr/bin/startx

ExecStop = /usr/bin/xset dpms force off
# screen will stay blank until there is something to be displayed again

SuccessExitStatus=1 SIGHUP SIGINT SIGTERM SIGPIPE 
# TODO: this needs further work

Restart = always
User = kiosk

[Install]
WantedBy = graphical.target

Normally, you want to automatically start one X session on bootup, so don't forget to systemctl enable kiosk.

Look & Feel

To get a nicer Look and Feel, install the following themes and fonts:

pacman -S ttf-bitstream-vera gtk-theme-orion

# as user 'kiosk' (`su kiosk -`)
echo 'include "/usr/share/themes/Orion/gtk-2.0/gtkrc"' > ~/.gtkrc-2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment