Make your OS automatically rotate your display when you physically rotate your monitor. Supports multiple monitors with minimal setup and Wallpaper Engine.
Note: The only Arduino I own is the Nano 33 BLE. This should work with other boards as well, but you may need to modify the script to read the data from your accelerometer.
- Install the latest version of the Arduino IDE.
- Open NanoBLE.ino in the Arduino IDE, then go to Tools > Library Manager, and install 'Arduino_LSM9DS1'.
- Set
displayID
to the ID of the monitor your Arduino will be connected to. To get this number in Windows, you can open the Settings app, and take the monitor ID shown there. This process is (probably) similar for Linux. - Upload the sketch. You can use the serial monitor (Tools > Serial Monitor) to verify that it's working.
- Install Python 3.11 or higher.
- Run
pip install -f requirements.txt
to install the required Python modules. - If you want to change where the config file is stored (by default, it's the same folder as AutomaticDesktopRotation.py), set
config_path
to the absolute path of the new location.
- Set
device_count
to the number of Arduinos you are using. - If you use Wallpaper Engine, create a
[monitor.X]
section for each monitor, where X is the monitor ID you used in the Arduino script. - Set
monitor_index
to what Wallpaper Engine thinks the monitor ID is. This should match the ID assigned by the operating system, but if wallpapers are appearing on incorrect monitors, themonitor_index
probably needs to be changed. X.path
refers to the absolute path of the wallpaper's project.json file, where X is the angle (0, 90, or 270) that you want the wallpaper to be assigned to. A wallpaper's path can be found by right-clicking it in Wallpaper Engine and selecting "Open in Explorer".X.name
should be used to store the name of the wallpaper.
The datatype of a value matters in TOML files. The included config can be used as a reference, but make especially sure to either enclose file paths in single quotes to parse it as a raw string, or escape the backslashes with a second backslash. Failure to do so will result in a parser error and require a script restart.
Here's an example config for monitor 1:
[monitor.1]
monitor_index = 1
0.name = 'Goat'
0.path = 'H:\SteamLibrary\steamapps\workshop\content\431960\2376779016\project.json'
90.name = 'Garfield'
90.path = 'H:\SteamLibrary\steamapps\workshop\content\431960\2208437588\project.json'
270.name = 'Life could be dream'
270.path = 'H:\SteamLibrary\steamapps\workshop\content\431960\2512005692\project.json'
There are two methods this script can use to rotate your monitor on Windows: The pywin32 Python module (this is used by default) and display64.exe.
While they are functionally the same, I've noticed that while using pywin32, if you rotate your monitor from 90 to 270 degrees without letting Windows rotate to 0 degrees partway through, the screen will not rotate. If this affects you, use Display64.exe, as it does not have this issue.
There may be other scenarios where one is better than the other, so give them both a try.
To use display64.exe instead of pywin32:
- Download it from here. While it is free to download, buy a copy if you can to support the creator.
- In the config, set
windows_fallback
toTrue
and setdisplayexe
to wherever you've extracted display64.exe to.
To make AutomaticDesktopRotation.py start on boot:
- Move AutomaticDesktopRotation.py to
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\
and AutomaticDesktopRotation.toml to a non-startup folder. - In AutomaticDesktopRotation.py, change
config_path
to the absolute path of the config file - Change the file extension of AutomaticDesktopRotation.py to
.pyw
. - Make sure Windows is set to open .pyw files by right-clicking AutomaticDesktopRotation.pyw, selecting 'open with', checking 'always use this app to open .pyw files', and selecting pythonw.exe, located in
AppData\Local\Programs\Python\Python311
.
Linux support currently only extends to KDE + Wayland. Any other DE + compositor combination is unsupported
- Install xrandr using your distro's package manager.
Debian-based:sudo apt install xrandr
Arch-based:sudo pacman xorg-xrandr
rpm-based:sudo dnf install xrandr
- To make AutomaticDesktopRotation.py start on boot:
- Run
sudo nano /etc/systemd/system/AutoScreenRotation.service
- Paste the following text, replacing {python path} and {script path} appropriately.
- Run
[Unit]
Description="Automatic screen rotation"
[Service]
ExecStart={python path} {script path}/AutomaticDesktopRotation.py
[Install]
WantedBy=multi-user.target
- Reload the daemon.
sudo systemctl daemon-reload
- Enable the service.
sudo systemctl enable AutoScreenRotation.service
- Start the service.
sudo systemctl start AutoScreenRotation.service
Your Arduino Nano should have its USB port pointing down, and its reset button facing outwards like this: