Rotate USB touch screen Pi 4 / Raspbian Buster

I’m just setting up a “FUJITSU Display E24-9 TOUCH” touchscreen with a Raspberry Pi 4. The display connects via HDMI and USB for touch functionality. Initially, I had some trouble getting the touch input aligned with the rotated display, so I would like to share what I’ve figured out.

It was easy to change the rotation using the “Screen Layout Editor” (which is what you are supposed to use for Pi 4:

The problem I had was that the image was rotated, but the touch input was not. It didn’t match up anymore.

My solution was to follow this article: in Step 3: Rotating the Touchscreen.

I’ve modified /usr/share/X11/xorg.conf.d/40-libinput.conf (might be a different file for you, check the guide). I’ve added Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1" to the touchscreen section. The section then looked like this:

Section "InputClass"
        Identifier "libinput touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"

The article only mentions degrees whereas the Screen Layout Editor named it differently. So here is another list with both. Choose one depending on your displays rotation:

  • 90° / left: Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"
  • 180° / inverted: Option "TransformationMatrix" "-1 0 1 0 -1 1 0 0 1"
  • 270° / right: Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"

Then restart xserver.

I was posting too early. My earlier post only sets up the touchscreen using the desktop environment. Openframe on the other hand requires to boot into CLI (also called terminal or command line) instead. In the CLI this rotation doesn’t apply it’s in standard landscape.

I’m not sure if this is a problem with Raspian Buster or Pi 4 (which doesn’t run on earlier Rasbian systems than Buster). How to rotate the command line on a Pi 4 / Buster?

Has anyone tested Buster on a Pi 3 and rotated the screen?


I’ve found some potential solutions here:

  1. Adding to display_hdmi_rotate=1 to /boot/config.txt and turning GL driver off had no effect for me.

  2. Adding video=HDMI-A-1:1920x1080M@60,rotate=270 to /boot/cmdline.txt and turning on the GL driver on rotates the command line for me. But unfortunately all windows opened by Openframe are still not rotated.

  3. Adding @xrandr -o right to /etc/xdg/lxsession/LXDE-pi/autostart didn’t work either. I guess, because some Openframe extensions are using the legacy xserver components and not LXDE.
    Maybe that would work if we move to the newer and more lightweight LXDE which we should anyway as suggested here:
    That said, some other extension are not even using those components though, like the video extension. For those extensions, there might be a separate solution. OXMPlayer which is what the video extension is using has implemented --orientation to rotate the video, for example. Of course, a global setting would be a lot better!

I’m not sure how I could miss the part on display rotation in the Raspberry Pi documentation.

After reading this, it seems like the rotation issue is not necessarily related to the version of the Pi, but the GPU driver selected.

Fake or Full KMS graphics driver (Default on Pi4)

Using the Screen Configuration Utility from the desktop Preferences menu, which is a GUI for xrandr afaik.

If you are using the console only (no graphical desktop) then you will need to set the appropriate kernel command line flags. Change the console settings as described on the this page.

Legacy graphics driver (default on models prior to the Pi4)

Using display_hdmi_rotate in config.txt.

This still doesn’t fix the rotation issue in KMS with Openframe but explains the different behaviour.

It’s possible to rotate all extensions using the .xinitrc template by adding xrandr --output HDMI-1 --rotate right as first line of the template. The Website and Processing extension are making use of those templates and could profit from this solution.

The current display configuration saved with Screen Configuration Utility seems to be stored in /usr/share/ Instead of xrandr we could run the in the beginning of the .xinitrc script. I’m not sure this is the only place or the best way to go about it though.

Going along the route of rotating each application/extension separately … other extensions to be tested:

  • Image and shader extensions are using glslViewer. Not sure if it offers an option for image rotation.
  • Video extension is using omxplayer which comes with a --orientation option.
  • VLC extension might be able to use Video transformation filter

… of course, it would be better to have a global setting for this instead.

omxplayer with --orientation 90 works.

VLC 3.0.10 with --video-filter "rotate{angle=90}" or --video-filter=transform --transform-type=90 works on macOS but not on a Pi4. I remember to have read this in unsupported at the moment.

I’m starting to think it might be better to run Openframe within X. That way xrandr would work normally and extensions requiring X would start much faster. I’m wondering what difference in performance it would really make compared to running Openframe from the command line (the currently intended way).