Hi there, I’m using an “auto-detection” script using bash commands leveraging using tvservice in my rc.local file. It’s not perfect, but it uses the typical config.txt style swapping (mentioned by other posts) to achieve my needs. It does have to reboot the Pi to switch, but it’s less than 10 seconds to get what I want. Hope it works for you.
- Stock Raspberry Pi 3 - Retropie Jessie standard image
- Hyperpixel 800x480 display.
- Pibow PITFT+ case modified to fit the Hyperpixel (modified Slice 9 and clear slice to make it fit).
- Standard HDMI monitor supporting 1080p 60hz
I added the following code in my rc.local file above the exit 0 statement:
# Check to see if display is not connected
_NOHDMI=$(tvservice -n ) || true
# Check to make sure it's not already in LCD mode
_ISLCD=$(tvservice -s | grep "LCD") || true
# HDMI is connected - turn off backlight LCD
_HDMI=$(tvservice -s | grep "0x12000a") || true
if [ -z "$_NOHDMI" ]; then
if [ "$_ISLCD" ]; then
printf "NO HDMI connected, Hyperpixel display config already active\n"
printf "NO HDMI connected, Switching to Hyperpixel display\n"
#change config to Hyperpixel and reboot since no display detected
sudo cp /boot/hyper-config.txt /boot/config.txt
elif [ "$_NOHDMI" ]; then
if [ "$_ISLCD" ]; then
printf "HDMI is connected, but Hyperpixel config is being used\n"
#we need to switch to HDMI display config and reboot
sudo cp /boot/hdmi-config.txt /boot/config.txt
elif [ "$_HDMI" ]; then
printf "HDMI is connected, HDMI config detected, so turning off LCD BL\n"
#we need to shut off the backlight on the Hyperpixel display since we aren't using it
#don't panic, a reboot automatically resets this - it isn't a persistent value
#also to do this the config.txt file needs to load the backlight module on startup
#to control it even if you aren't loading the overlay driver for the display
echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
#debugging catchall - shouldn't happen since we expect 0x12000a - but you never know...
printf "HDMI is connected, HDMI config detected, your tv might not like 1920x1080 resolution\n"
#do nothing - based on previous if statements - you either have HDMI or you don't have it...
printf "Debug catchall point - sorry I can't help you out - I haven't run into the error state yet!\n"
To use the above code in your own rc.local file, you need to create two files (hdmi-config.txt) and (hyper-config.txt) that live in your /boot directory. It’s strongly suggested to make a backup of your existing config.txt so you don’t accidentally nuke yourself just because my configuration may not 100% match your equipment.
file 1 - hyper-config.txt – a copy of the stock retropie jessie build with hyperpixel drivers installed with the following audio tweak:
# Use cleaner headphone audio output mode - trust me leave this enabled
file 2 - hdmi-config.txt – a copy of the stock build with one tweak:
# Use a basic GPIO backlight driver with on/off support
# Even if you use HDMI, you need to load this driver to be able to control the backlight
# of the Hyperpixel even when it is not used