Especially if you have connected an external screen, you may be faced with the problem of wanting to rotate the screen output.
A typical use case, for example, is if you use your RaspberryPi to build a MagicMirror. To do this, the screen is often hung rotated by 90°. Now of course you also have to rotate the screen output by 90°.
How this works and what you need to know is described in the following article.
Requirements
Helpful articles:
Before you start with this article you should have prepared the RaspberryPi so that it is accessible via the network and controllable via SSH.
The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
Required tool:
-no-
Required material:
In the following list you will find all the parts you need to implement this article.
Log in to the RaspberryPi via SSH
To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.
Adjust the screen orientation using config.txt
There are basically different ways to rotate the screen output. One possibility is to set the screen orientation in the configuration of your Raspberry Pi.
To do this, connect to your RaspberryPi and open the configuration file with the following command.
sudo nano /boot/config.txt
In the open configuration file you now have to navigate to the bottom of the file using the arrow keys.
Once there, insert the following line.
display_rotate=2
But be careful: The value you set here determines the rotation of the display. The setting “display_rotate=2” causes the screen content to be rotated by 180°. For other angles you must set this parameter according to the table below.
Value | rotation |
---|---|
0 | normal |
1 | 90° |
2 | 180° |
3 | 270° |
0x10000 | flip horizontally |
0x20000 | flip vertically |
As soon as you have chosen the setting correctly, you can save the configuration file with the key combination CTRL-X, then Y and Enter.
Now all you have to do is restart your RaspberryPi and your screen content should be rotated accordingly. 🙂
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂
Hello Fabian,
your great site inspired me to build a Magic Mirror.
Magic Mirror runs perfectly on a PI 4, various modules are installed and thanks to your description of the PM2, the MM also starts automatically. So far so good 🙂
What I can't do is rotate the picture. I open with sudo nano /boot/config.txt
the file and navigate to the end and write display_rotate=2 there and save the file. After a reboot the image remains horizontal. The following note may be interesting: If I navigate directly to conf.txt via the explorer on the PI, after editing the line I get the message “Save not possible, no authorization”. But if I access the Rasp from the PC via SSH, I can edit and save the file. When I then look at the file on the PI, the new value is also there. I tested it with values 1,2 and 3. Unfortunately the display always remains horizontal. Do you have an idea? Below is my conf.txt
Thanks very much,
Thomas
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details
# uncomment if you get no picture on HDMI for a default “safe” mode
#hdmi_safe=1
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700MHz is the default.
#arm_freq=800
# Uncomment some or all of these to enable the optional hardware interfaces
# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
[Alles]
#dtoverlay=vc4-fkms-v3d
display_rotate=3
—————————————————
As I said, editing is only possible via ssh 🙁
hey thomas,
I just looked at that. The method of rotating the screen output seems to have changed with the release of the Raspi4. In that respect, thanks for the hint. 🙂 (Will update the article)
Please try the following commands:
Normal orientation: DISPLAY=:0 xrandr –output HDMI-1 –rotate normal
Rotate left: DISPLAY=:0 xrandr –output HDMI-1 –rotate left
Rotate right: DISPLAY=:0 xrandr –output HDMI-1 –rotate right
Rotation upside down: DISPLAY=:0 xrandr –output HDMI-1 –rotate inverted
I would appreciate a feedback. 🙂
Best regards
Fabian
Hi Fabian,
First of all, thank you very much for your quick answer 🙂
I have now deleted the original command display_rotate=3 in the config.txt and replaced it with your command. Unfortunately it doesn't have the desired effect and the display doesn't rotate (I tried with all four orientations). One thing struck me: So that I don't destroy anything while testing, I saved the config.txt in the same directory. There are now the files there (“config.txt”, config.txt.save” and config.txt.save.1″. Is it possible that there are problems there? I wanted to delete the files in the PI explorer, I get them there but always the message "The file operation was completed with errors. Error removing the file.....No permission:-(
Here are the last lines of my config.txt
[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
[Alles]
#dtoverlay=vc4-fkms-v3d
DISPLAY=:0 xrandr –output HDMI-1 –rotate right
I'm sorry I can't tell you otherwise.
Best regards
Thomas
Hello Fabian,
I found a solution and I wanted to share it with you.
Sometimes you just think too complicated. You don't need the terminal console at all to rotate the display, this can be done easily using the Raspbian graphical interface. Here the solution:
for the Raspberry OS with desktop:
> Settings
> Screen Configuration
> Help/About displays the ARandR screen layout editor
> close
> Right-click on DSI-1 or HDMI
> rotation
Then select the desired rotation and confirm with “Configure Apply”.
The screen is rotated immediately and remains in this setting even after a reboot.
Sometimes it's very simple 🙂
Anyway thanks for your support.
Greetings Thomas
hey thomas,
great, thank you for the feedback.
I'll add that to the article then. 🙂
Best regards
Fabian
Hello, maybe someone can help me.
I wanted to go the same way via Screen Configuration, but the right and left buttons are grayed out for me, I can't select them. What could be the reason?
Hi Toby,
uh, i'll have to take a look at that. With screen configuration you mean the program on the graphical user interface of the Raspberry Pi, right?
Best regards
Fabian
Hello, turning the screen with the Raspbberry Pi2 works as described at the beginning....only then there is an error in the description....it must say "String X and J and Enter"...and not Y. The Y stands for Yes, if the operating system is in English...and J stands for yes...since it is in German you can also see that J is to be used in the mask for saving and not the Y!
Worked for me immediately with Raspberry Pi 2
Kind regards
Uwe Oszinda