When working on Raspberry Pi projects, you often need to rotate the screen by 90 or 180 degrees due to the physical mounting in the case. The process varies slightly depending on whether you are using an older model (RPi 3) or a newer one (RPi 4/5).
Raspberry Pi 3 and Older Models
- Open the
config.txtfile:sudo nano /boot/config.txt - Add the rotation line to the end of the file (0=normal, 1=90°, 2=180°, 3=270°):
lcd_rotate=2 - Save (Ctrl+O) and reboot:
sudo reboot
If the above method doesn't work, try using the xrandr command in the desktop environment:
sudo chmod 644 /etc/xdg/lxsession/LXDE-pi/autostart
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Add the following line: @xrandr --output DSI-1 --rotate inverted
Raspberry Pi 4 and Newer Models
Newer models use a different graphics driver (KMS), so the file path has changed:
- Edit the configuration file:
sudo nano /boot/firmware/config.txt - Change the line
dtoverlay=vc4-kms-v3dto:dtoverlay=vc4-fkms-v3d - Add
lcd_rotate=2to the end of the file and reboot.
If it still doesn't work, use the same autostart method with the xrandr command as described above.