Skip to content

Instantly share code, notes, and snippets.

@quelleck
Forked from AGWA/rpi-hdmi.sh
Last active January 13, 2024 07:45
Show Gist options
  • Save quelleck/1d8fc8395fd52d4aa38a99ef46d8598e to your computer and use it in GitHub Desktop.
Save quelleck/1d8fc8395fd52d4aa38a99ef46d8598e to your computer and use it in GitHub Desktop.
Enable and disable the HDMI port on the Raspberry Pi: `rpi-hdmi on` to turn on, `rpi-hdmi off` to turn off.
#!/bin/sh
# Enable and disable HDMI output on the Raspberry Pi
is_off ()
{
vcgencmd display_power | grep "display_power=0" >/dev/null
}
case $1 in
off)
if is_off
then
echo Already off...
else
vcgencmd display_power 0
fi
;;
on)
if is_off
then
vcgencmd display_power 1
else
echo Already on...
fi
;;
status)
if is_off
then
echo off
else
echo on
fi
;;
*)
echo "Usage: $0 on|off|status" >&2
exit 2
;;
esac
exit 0
@fiveseven808
Copy link

This one is definitely an improvement! thank you for this!

@sebaacuna
Copy link

Worked for me, thanks!

@ksolomon
Copy link

Thanks! This is exactly what I was looking for to use on a build for my son. :)

@joenas
Copy link

joenas commented Nov 14, 2017

This is awesome! I have one issue though. I'm using Chromium in kiosk mode on my Pi and after turning the screen on again it's just dark. I've found a script to refresh the page but to no avail. Has anyone else had this problem?

@samuraicode
Copy link

This is awesome! I have one issue though. I'm using Chromium in kiosk mode on my Pi and after turning the screen on again it's just dark. I've found a script to refresh the page but to no avail. Has anyone else had this problem?

I had this problem and fixed it by uncommenting two lines in /boot/config.txt to force HDMI ouptut. See the article below about, but basically uncomment:
#hdmi_force_hotplug=1
#hdmi_drive=2

https://howtoraspberrypi.com/raspberry-pi-hdmi-not-working/

@ShadGates
Copy link

Nice! Using this, instead of the original rpi-hdmi.sh, works with my HDMI-to-DVI adapter-connected to an old monitor, where the original could turn it off, but not back on again.

@cwpollock
Copy link

This one worked for me too! Thanks!

@CzarLucius
Copy link

I am still struggling with this. Copied and pasted the code above into a new .sh file - file path: /home/pi Went into the crontab and the time came and went. I have repeated the steps multiple times to no avail - any known bugs with Pi 3 B+? Do I need to run the cron as a super user?

@nnyerges
Copy link

nnyerges commented Apr 25, 2023

Thanks but, tvservice only works for all driver. It doesn work for example with "tvc4-kms-v3d" driver. Any other solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment