Page 1 of 1
Switch between LCD and HDMI
Posted: Fri Aug 25, 2017 6:55 am
by joao
Hi,
I was trying to switch between the LCD and HDMI with the correct resolution for each, so that I could have an external HDMI port in the mintyPi. Based on some other forum I was able to create a script with the command tvservice -n to check if HDMI is connected or not, and then use the correct config.txt file.
But now I have two issues that I would like to solve.
When in HDMI the TV blinks from time to time.
And also when in HDMI the LCD keeps the white light on and I would like to turn it off.
Any suggestions?
Re: Switch between LCD and HDMI
Posted: Fri Aug 25, 2017 10:23 am
by joao
The HDMI config_hdmi.txt file contains the following in the end:
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
gpu_mem_256=128
gpu_mem_512=256
gpu_mem_1024=256
overscan_scale=1
#lcd_off
And the LCD config_lcd.txt file contains the following:
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
gpu_mem_256=128
gpu_mem_512=256
gpu_mem_1024=256
overscan_scale=1
#lcd_on
dtparam=spi=on
disable_overscan=1
hdmi_cvt=640 480 60 1
hdmi_group=2
hdmi_mode=87
And the script that performs the change is the following:
#!/bin/bash
rm -f hdmi.name
tvservice -n 2> hdmi.name
if grep "No device present" hdmi.name; then
if ! grep "#lcd_on" /boot/config.txt; then
echo "reboot with LCD configuration"
sudo cp -f /boot/config_lcd.txt /boot/config.txt
sudo reboot -n
fi
else
if ! grep "#lcd_off" /boot/config.txt; then
echo "reboot with HDMI configuration"
sudo cp -f /boot/config_hdmi.txt /boot/config.txt
sudo reboot -n
fi
fi
This script is called by 10-retropie.sh
# Check display config
/home/pi/displayBoot/initDisplay.sh
sleep 5
# launch our autostart apps (if we are on the correct tty)
if [ "`tty`" = "/dev/tty1" ]; then
bash "/opt/retropie/configs/all/autostart.sh"
fi
The original forum was
https://retropie.org.uk/forum/topic/422 ... n-lcd-hdmi
Any suggestions on how to improve this?
Re: Switch between LCD and HDMI
Posted: Sun Sep 03, 2017 6:43 am
by joao
It seems not a lot of interested parties on this subject

Nevertheless I was able to fix the issue with the white screen by moving the led pin to gpio 18 (pin 12). And now I can control it off/on with:
sudo sh -c "echo 1 > /sys/class/backlight/fb_ili9341/bl_power"
sudo sh -c "echo 0 > /sys/class/backlight/fb_ili9341/bl_power"
I also disconnect and connect the sound card depending if I'm using HDMI or LCD. The new script looks like this:
#!/bin/bash
# HDMI connection?
rm -f hdmi.name
tvservice -n 2> hdmi.name
if grep "No device present" hdmi.name; then
if ! grep "#lcd_on" /boot/config.txt; then
echo "reboot with LCD configuration"
sudo cp -f /home/pi/displayBoot/config_lcd.txt /boot/config.txt
sudo cp -f /home/pi/displayBoot/asound_lcd.conf /etc/asound.conf
sudo sh -c "echo 1 > /sys/class/backlight/fb_ili9341/bl_power"
sudo reboot -n
fi
else
if ! grep "#lcd_off" /boot/config.txt; then
echo "reboot with HDMI configuration"
sudo cp -f /home/pi/displayBoot/config_hdmi.txt /boot/config.txt
sudo cp -f /home/pi/displayBoot/asound_hdmi.conf /etc/asound.conf
sudo sh -c "echo 0 > /sys/class/backlight/fb_ili9341/bl_power"
sudo reboot -n
fi
fi
Re: Switch between LCD and HDMI
Posted: Wed Sep 13, 2017 6:31 am
by joao
The blink issue was just a question of power supply. All is working fine now. Just need to think on a way to have the HDMI port out of the tin.
Re: Switch between LCD and HDMI
Posted: Wed Sep 13, 2017 11:23 pm
by Helder
Can you provide a script to install these modifications or the modified files so anyone can easily install these on their setup?
Re: Switch between LCD and HDMI
Posted: Fri Sep 15, 2017 10:14 am
by joao
Hi,
I'm just doing my first steps on this but here you have the files I used.
The 10-retropie.sh file should replace the one under /etc/profile.d/10-retropie.sh
The displayBoot directory should be placed under /home/pi
Enjoy it.
Re: Switch between LCD and HDMI
Posted: Mon Sep 25, 2017 2:57 am
by joao
I see that now the new PCB includes the LCD backlight pin so this option can be easily implemented if the image or script from wermy include the activation for this.
The command line in setup.sh:
echo 'options fbtft_device name=fb_ili9341 gpios=reset:25,dc:24 speed=80000000 bgr=1 rotate=90 custom=1 verbose=0 fps=60' >> $fbtft_conf
Should be replace by:
echo 'options fbtft_device name=fb_ili9341 gpios=reset:25,dc:24,led:18 speed=80000000 bgr=1 rotate=90 custom=1 verbose=0 fps=60' >> $fbtft_conf
After this you can use the information available in this post to turn on/off the screeen.