Hyperpixel - selective output (eg on boot)?

Hyperpixel is awesome, but I have a question: I’d like to be able to selectively use HDMI out instead of the hyperpixel. Is there a way to programmatically change at runtime, or alternatively at boot, such as checking for a particular keypress or GPIO - although it looks like all GPIOs are used by hyperpixel itself.

All suggestions gratefully received.

2 Likes

It’s actually quite a tricky thing to accomplish, since switching over to the display is one of the first things that happens upon boot.

As far as I know, it can only be done manually (by offering some mention to pick HDMI/DSI, tweaking the config.txt and rebooting) or semi-automatically, like the functionality offered by PINN: https://github.com/procount/pinn/blob/master/README_PINN.md#how-to-auto-switch-hdmidsi-screen-configurations

PINN will automatically boot the last selected OS after it times out. If a HDMI screen is attached, PINN will copy the config.hdmi file to config.txt on the selected OS and reboot into it.

So I guess PINN is worth a look into!

1 Like

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.

Best regards,
– C-S

My equipment:

  • 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"
    #do nothing
  else
    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
    sudo reboot
  fi
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
    sudo reboot
  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
  else
    #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"
  fi
else
  #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"
fi

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
audio_pwm_mode=2

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
dtoverlay=hyperpixel-gpio-backlight
4 Likes

Very nice way about it!
I was planning to put an auto-default timer on my own script as Gadgetoid suggested, but I never got around to understanding enough about Python multi threading to implement it. I salute you sir!

Sorry for not understanding this fully but am I correct in saying that the line of code will enable the pi to switch displays depending on if the HDMI port is occupied? If not, can someone explain how exactly this works? Thanks.

Pretty much so; it checks to see if the HDMI port is active, and if so, uses it, unless the Hyperpixel display is also connected, in which case, it uses that.
Well, I think so at least!

1 Like

Thanks! :) Does the Hyperpixel cancel out any other HAT modules if one was to stack them? Eg. https://www.modmypi.com/raspberry-pi/breakout-boards-229/pi-modules/ups-pico ? Im making a portable pi hence why im wondering this as ill need a battery pack HAT module. Any reccomendations on cases? Im wanting the sides of the Hyperpixel entirely closed of and would even settle for covering the screen entirely as long as i could use a bluetooth keyboard without a digital one appearing on the screen. Thanks!

I’m afraid the Hyperpixel display uses all of the GPIO pins in order to operate, so it’s likely that any other boards will be incompatible. You could try using something like a Black Hat H3cker, but I’m not sure whether it’d work.

As for a case, take a look at this thread. Pibow Suitability
I’m afraid I think the large case is still out of stock though…

1 Like

:( ah right, thanks anyway!

1 Like

You can always use the i2c to use an I/O expander for more GPIO pins (I am trying out the MCP23017 chip for this purpose for the powerboost’s low voltage signal for auto-shutdown, waiting for the custom pcb to arrive from China)

C-S, I can’t find the rc.local file. Can you give me the path?

JackMart

I suggest looking here to know about this file and what it does.

The path for rc.local is /etc/rc.local

To edit the file use something like this:

sudo nano /etc/rc.local

Just a note that I’ve tested with the new hyperpixel4 and this is working.

This is confusing because it did not work for me. (No display on LCD(when unplugged) or HDMI
Did you forget to mention that the content of those above files need to have all contents of config.txt file added for each? Also, this would have to be done before installing Hyperpixel drivers to get a ‘clean’ version of config.txt for the hdmi-config.txt

Or just use the one liners in a txt file? Not clear.

UPDATE: Got it working. Thanks…

Yes I was correct. You have to add the one liner (hdmi-config.txt) into a PRE-pixel screen install , and the other (hyper-config.txt) into a POST-pixel screen install.
Just copy your config.txt to two other files renamed the above. So you have 2 versions of config.tx
sudo cp config.txt hdmi-config.txt
sudo cp config.txt hyper-config.txt

Edit each and add the small section for each mentioned above.
If your following this after you installed the hyperpixel screen and it’s up and running do same, but add

(remark out) all the below for the hdmi-config.txt file;

#dtoverlay=hyperpixel4:rotate
#display_rotate=3
#overscan_left=0
#overscan_right=0
#overscan_top=0
#overscan_bottom=0
#framebuffer_width=800
#framebuffer_height=480
#enable_dpi_lcd=1
#display_default_lcd=1

For whatever reason, this didn’t work for me, but it was close. The original code always considers the first ‘if’ statement false, whether HDMI was connected or not.

I changed the code you put in /etc/rc.local to this:

# Check to see if HDMI display is connected.
_HDMI_EXISTS=$(tvservice -l | grep "HDMI" ) || true
# Is device in LCD mode?
_ISLCD=$(tvservice -s | grep "LCD") || true

if [ -z "$_HDMI_EXISTS" ]; then
  if [ "$_ISLCD" ]; then
   echo "[  \e[32mOK\e[39m  ] NO HDMI connected, Hyperpixel display config already active\n"
   #do nothing
  else
   echo "[\e[91mFAILED\e[39m] NO HDMI connected, switching to Hyperpixel config\n"
   #change config to Hyperpixel and reboot since no display detected
   sudo cp /boot/hyper-config.txt /boot/config.txt
   sudo reboot 
  fi
else
  if [ "$_ISLCD" ]; then
    echo "[\e[91mFAILED\e[39m] 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
    sudo reboot
  else
    echo "[  \e[32mOK\e[39m  ] HDMI is connected, HDMI config detected, so turning off LCD BL\n"
    #we need to shut off the GPIO backlight on the Hyperpixel display since we aren't using it
    gpio -g mode 19 out
    gpio -g write 19 0
  fi
fi

This also gives a more uniform output - it will write a green [ OK ] or red [FAILED] to match the other messages in the bootup screen. Just a small change that was bothering me. :)

I also did not add anything to the hdmi-config.txt. The rc.local code directly writes to the GPIOs using wiringpi, since the other solution brought up errors.

hdmi-config.txt was the default config.txt (you can get this by removing the group of the last 12 or so lines from the hyperpixel config.txt to get this).

hyperpixel-config.txt was just the config.txt copied over, unchanged in my case.

Thanks for providing that initial script/advice, I’m not too good at doing this bash stuff from scratch.

great! thanks for contributing to my hack!

Hey, Just here to share an alternative way that doesn’t need to create special config.txt files or rc.local scripts…
I found this on trial and error, after MANY tries. I created a DIY handheld (@compactPiArcade on instagram), and it features a Hyperpixel4 (non touch). And to complete the project I NEED to make this works. To have auto detection when the HDMI is plugged (before boot), and get the HyperPixel active when nothing is connected.
My solution was to use the Filter tag on the config.txt adding this to it, after the first lines… :

This is just what the Hyperpixel install adds to the config.txt by default, BUT with the [EDID=N/A-] filtering. It’s works ! :) After the [all] i put everything else of the original config.txt

[EDID=N/A-]  ##Hyperpixel HD CONFIG	
	dtoverlay=hyperpixel4
	overscan_left=0
	overscan_right=0
	overscan_top=0
	overscan_bottom=0
	framebuffer_width=800
	framebuffer_height=480
	enable_dpi_lcd=1
	display_default_lcd=1
	dpi_group=2
	dpi_mode=87
	dpi_output_format=0x7f216
	display_rotate=3
	hdmi_timings=480 0 10 16 59 800 0 15 113 15 0 0 0 60 0 32000000 6
      audio_pwm_mode=0
      disable_audio_dither=1
      ## LCD
[all]