Blog about Web Programming and Electronics
💬 👤
back Back to blog
Miscellaneous

How to rotate the screen on Raspberry Pi

In Raspberry Pi projects, it frequently happens that you need to rotate an official or external display by 90, 180, or 270 degrees due to its physical orientation inside an enclosure. Since newer Raspberry Pi models have transitioned to modern graphics drivers, the process depends on the specific model you are using.

In this guide, we will look at how to quickly and correctly rotate the screen on older models (RPi 3) as well as modern ones (RPi 4 & 5).

1. Raspberry Pi 3 and Older Models

Older boards rely on legacy system firmware, where display configurations are edited directly inside the config.txt boot file.

  1. Open the terminal and launch the text editor:
    sudo nano /boot/config.txt
  2. Scroll to the end of the file and add the line corresponding to your desired rotation:
    # 0 = normal, 1 = 90°, 2 = 180°, 3 = 270°
    lcd_rotate=2
  3. Save the file using Ctrl + O, hit Enter, exit with Ctrl + X, and reboot the system:
    sudo reboot

2. Raspberry Pi 4 and Raspberry Pi 5

Newer models utilize the modern KMS (Kernel Mode Setting) graphics driver. This means the legacy lcd_rotate directive will no longer work. Instead, screen rotation must be handled within the desktop environment (X11) or via terminal using xrandr.

To make the rotation persistent on desktop boot, edit the autostart file:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Append the following command to the end of the file (choose your orientation: left, right, inverted, or normal):

@xrandr --output DSI-1 --rotate inverted

Note: If you are connecting your display via an HDMI port, replace DSI-1 with the appropriate output name (e.g., HDMI-1). You can verify your exact output name by simply running the xrandr command in the terminal.

3. Rotating Display in Modern Wayland (Bookworm)

If your Raspberry Pi runs the latest OS version featuring the Wayland compositor, the process is even easier. You can adjust the rotation graphically via: Menu > Preferences > Screen Configuration, or via terminal using the following command:

wlr-randr --output HDMI-A-1 --transform 180
back Back to blog