Rotate display on Intel NUC

Thanks for sharing that link, it was very useful.

I am running an ElectronJS app, so I moved the sleep, rotate to a separate script. Then my startx command runs my electron.sh startup script, where the electron.sh startup does the rotate and starts electron. This will also prevent the asynchronous call of the sleep. (Just in case X takes a really really long time to start.)

Here are my scripts, with pieces taken from several examples from github:

(1) start.sh:

#!/bin/bash

# by default docker gives us 64MB of shared memory size but due to
# display heavy pages we need more
umount /dev/shm && mount -t tmpfs shm /dev/shm

# using local electron module instead of the global electron lets you
# easily control specific version dependency between your app and electron itself.
# the syntax below starts an X istance with ONLY our electronJS fired up,
# it saves you a LOT of resources avoiding full-desktops envs
rm /tmp/.X0-lock &>/dev/null || true

# start X11 and Electron app
if [ ! -c /dev/fb1 ] && [ "$TFT" = "1" ]; then
    modprobe spi-bcm2708 || true
    modprobe fbtft_device name=pitft verbose=0 rotate=${TFT_ROTATE:-0} || true
    sleep 1
    mknod /dev/fb1 c $(cat /sys/class/graphics/fb1/dev | tr ':' ' ') || true
    FRAMEBUFFER=/dev/fb1 startx /usr/src/app/electron.sh
else
    startx /usr/src/app/electron.sh
fi

(2) electron.sh

#!/bin bash

# First, wait a few seconds for X11 to start
sleep 3

# Rotate screen
# rotate screen if env variable is set [normal, inverted, left or right]
if [[ ! -z "$ROTATE_DISPLAY" ]]; then
    DISPLAY=:0 xrandr -o $ROTATE_DISPLAY
fi

# Start ElectronJS -- this width/height example is for a display mounted in portrait mode (left or right)
URL_LAUNCHER_KIOSK=1 URL_LAUNCHER_WIDTH=1080 URL_LAUNCHER_HEIGHT=1920 /usr/src/app/node_modules/electron/dist/electron /usr/src/app/ --enable-logging
1 Like

Thank you for sharing what worked for you @pzarfos!