OpenHAB UI in Raspberry Pi Touch Display 2
This tutorial describes how to enable Raspberry Pi Touch Display 2 and have it start with OpenHAB’s user interface in an OpenHABian system. This is useful i.e. if you want to use the display as a control panel for your home automation. The set-up used in the tutorial is as follows:
- Raspberry Pi 4b, 4Gbytes
- Raspberry Pi Touch Display 2
- Linux openHABian 6.12.25
- OpenHAB 5.0.2
To avoid confusion, I follow a hybrid approach making sure every file is edited only once and explaining the purpose of every change.
Enable the Touch Display 2
Connect the Raspberry Pi Touch Display 2 as indicated by its manual.
To enable the display, you just need to edit the file /boot/firmware/config.txt. Comment or remove the dtoverlay parameter in the [cm5] section and add it to the [all] section with the value vc4-kms-v3d. The bottom of your file should look like this:
[cm5]
#dtoverlay=dwc2,dr_mode=host
[all]
gpu_mem=16
dtparam=i2c_arm=on
dtparam=i2c1=on
dtoverlay=vc4-kms-v3d
Restart your Raspberry Pi. The screen should start in text mode. If the orientation of the text is correct, jump to the next section.
In my case the text was upside down for the way I planned to install the screen in the wall. To fix this, I had to edit the file /boot/firmware/cmdline.txt and add a kernel video argument like this:
console=serial0,115200 console=tty1 root=PARTUUID=e2373d0a-02 rootfstype=ext4 fsck.repair=yes rootwait video=DSI-1:720x1280M@60,rotate=180
Try 90 or 270 for values of rotate if you plan to use the screen in landscape orientation.
Install the packages to show OpenHAB’s UI
Run the following command to install the packages we will need in this how-to:
sudo apt install raspberrypi-ui-mods chromium-browser --no-install-recommends -y
What you are doing here is:
-
raspberrypi-ui-mods: Install PIXEL, Raspberry Pi’s default graphical desktop. -
chromium-browser: Install the Chromium web browser, necessary to display OpenHAB’s ui. -
--no-install-recommends: Do not install anything that is not strictly required. This system will only serve one purpose. -
-y: Automatically answer yes to any question during the installation process.
Start the display in a graphical desktop
Once the installation finishes, we need to tell the system we want to start in the graphical desktop mode. Launch the Raspberry Pi configuration:
sudo raspi-config
Navigate to System Options > Boot and select the option that boots into the desktop GUI (the exact label varies between raspi-config versions). Exit the configuration and answer yes to reboot. The boot process should end with PIXEL’s graphical login screen.
Create a new user for the graphical desktop and auto-login with it
We want our system to show the OpenHAB UI when the system starts. For that, we need to auto-login into the graphical desktop with an existing user. I don’t recommend to login with the “openhabian” user for security reasons. Let’s create a new user that we may call “gui-user”. Connect with a remote terminal and run the following command:
sudo adduser gui-user
Give the user permissions to use input devices, including the touch screen:
sudo usermod -aG input gui-user
Edit the lightdm.conf file to configure auto-login for the new user:
sudo nano /etc/lightdm/lightdm.conf
Look for the [Seat:*] section. Inside it, you should see lines like #user-session= and #autologin-user=. Change them as shown below. Don’t forget to remove the hash (#) at the beginning of every line we change:
user-session=lightdm-xsession
autologin-user=gui-user
Don’t close the editor yet — we’ll make more changes to this file in the next section.
Get rid of the mouse arrow, change time-to-sleep
Since I’m using the touch screen input and not a mouse, I don’t need a mouse arrow and I don’t like it showing up in the screen.
In the same [Seat:*] section of the /etc/lightdm/lightdm.conf file look for a line like #xserver-command=. Change it as shown below:
xserver-command=X -nocursor
To change how long the screen waits for inactivity to go to sleep, look for a line like #display-setup-script= in the same [Seat:*] section. For sixty seconds, change it as shown below:
display-setup-script=xset s 60 60 && xset dpms 60 60 60
Restart the lightdm service to apply the changes:
sudo systemctl restart lightdm
Fix the orientation of the touch input
If you used the kernel video argument to rotate the screen as explained in the end of the first section, the graphical desktop could not be receiving the correct coordinates of the place where you touch the screen. What I mean is, you touch the screen in some place and the desktop behaves as if you were touching it somewhere else. In my case, when I touched the bottom-right corner, the desktop would open the File Manager whose icon is in the top-left.
You can check this by dragging your finger in the screen. A selection square will be drawn in the desktop, and the corner of the square should follow your finger. If that is the case, skip the rest of this section.
Create a new rules file:
sudo nano /etc/udev/rules.d/99-touchscreen-rotation.rules
The following line fixed the issue for my setup:
ENV{ID_INPUT_TOUCHSCREEN}=="1", ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 -1 1 0 0 1"
Save the file and apply the changes with the following command:
sudo udevadm control --reload-rules && sudo udevadm trigger
If the behavior doesn’t change, reboot your Raspberry Pi.
Other LIBINPUT_CALIBRATION_MATRIX values that may work for you are "0 -1 1 1 0 0 0 0 1" or "0 1 0 -1 0 1 0 0 1". You can find the meaning of these numbers here.
Verify that the graphical desktop responds at the exact location you touch. Drag your finger and check that the selection square follows it. Check that icons and buttons (i.e., the File Manager or time at the top bar) respond when you touch them.
If you didn’t hide your mouse pointer arrow, it could still not follow your finger or have a wrong orientation. This seems to be a different issue from the desktop touch coordinates. I tried many suggestions from the AI to fix it, but none of them worked.
Display OpenHAB’s UI with Chromium
Now we want the screen to display OpenHAB’s UI whenever the Raspberry Pi starts. Since the UI is a web page, we need to use the Chromium browser we installed earlier. We will start it in kiosk mode so OpenHAB’s UI will be the only thing displayed. No desktop bar, no Chromium window, no buttons, nothing else.
Create a script to start Chromium when the Raspberry Pi starts:
sudo mkdir -p /home/gui-user/chromium
sudo nano /home/gui-user/chromium/start.sh
Put this in the script:
#!/bin/bash
# Wait for the X server to become available
while ! xset q &>/dev/null; do sleep 1; done
# Reset Chromium exit state to prevent "Restore Pages" or "Crashed" prompts on startup
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/gui-user/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/gui-user/.config/chromium/Default/Preferences
# Wait for the OpenHAB web interface to return a 200 OK status
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:8080); do sleep 2; done
# Launch Chromium with Kiosk and stability flags:
# --kiosk: Enables full-screen mode without browser UI
# --noerrdialogs: Suppresses error messages during startup
# --disable-infobars: Prevents the "controlled by automated software" notification
# --ozone-platform=x11: Explicitly selects the X11 backend
# --disable-gpu / --disable-software-rasterizer: Workarounds for hardware acceleration issues
# --force-device-scale-factor: Adjusts UI scaling (currently 150%)
# --window-size: Matches specific display resolution (720x1280 for portrait)
chromium-browser \
--kiosk \
--noerrdialogs \
--disable-infobars \
--ozone-platform=x11 \
--disable-gpu \
--disable-software-rasterizer \
--force-device-scale-factor=1.5 \
--window-size=720,1280 \
"http://127.0.0.1:8080"
I had to add the --window-size=720,1280 \ line because my screen is in portrait position, but you may not need it.
Fix the permissions:
sudo chmod +x /home/gui-user/chromium/start.sh
sudo chown -R gui-user:gui-user /home/gui-user/chromium
Make the LXDE session launch the script. Create an autostart script:
sudo mkdir -p /home/gui-user/.config/lxsession/LXDE-pi/
sudo nano /home/gui-user/.config/lxsession/LXDE-pi/autostart
Put this in the autostart script:
@bash /home/gui-user/chromium/start.sh
Fix the ownership of the path and file:
sudo chown -R gui-user:gui-user /home/gui-user/.config
Restart the system.
Remaining issues
I wanted to have a virtual keyboard pop up in the screen whenever I selected an input field, but I couldn’t make it work. The best I could do was having a fixed keyboard occupying the bottom of the screen all the time. None of the widgets that I use in the panel need to input any text, so I decided not to display a keyboard. If I need a keyboard, I connect to the OpenHAB UI remotely from a computer.
I noticed the right edge of UI screen is slightly cut. I didn’t investigate this, but I suspect it’s due to OpenHAB’s UI having a minimum width rather than something being wrong in the screen configuration. Hopefully you don’t experience this if your screen’s horizontal resolution is bigger.
That’s it. I hope this is useful. Let me know how I can improve this how-to — I appreciate your feedback.