Probably a very simple question, but I haven't had much luck finding a answer on my own. I have a Tontec 3.5" touchscreen plugged into my RPi2. Is there any way that I can use the touchscreen when there's no monitor attached, but if I plug an HDMI cable in, the video output changes from the touchscreen to the attached display? Any tips are appreciated.
You need to do two things :
1 Setup your xorg.conf with two layouts , HDMIOnly and TFTOnly. Use this as inspiration : https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=91764&start=25#p661085
2 Use a script to auto-switch between the two layouts. Try this:
#!/bin/bash HDMI_ON = false while true; do if (/usr/bin/tvservice -s | /bin/egrep 'HDMI|DVI') ; then if [ ! "$HDMI_ON" = true ] ; then /usr/bin/pkill X /usr/bin/startx --layout HDMIOnly $HDMI_ON = true fi else if [ "$HDMI_ON" = true ] ; then /usr/bin/pkill X /usr/bin/startx --layout TFTOnly $HDMI_ON = false fi fi sleep 1 done
You can do what i did, and it works fine, i have a raspberry pi official 7 inch touchscreen, i connected a switch to the power pin of the touchscreen(powered through GPIO), so whenever i have to switch between displays, i just power off or on the switch, and then reboot the pi. I know this is a little manual labour but still it works very smoothly, if you want only one display at a time.