In a recent post, I showed you how to hack the HDMIPi power switch so that you can turn the screen on and off from the Pi.
But no sooner had I done that than my friend Peter Onion, wondering if there was a way to detect if the LCD is on or off in case it gets “out of sync”, tweeted this…
@RasPiTV Is there a switched 3v3 supply to the LCD pannel ? Wire that to a GPIO input pin ? Or can you test monitor "on" via hdmi ?
— Peter Onion (@PeterOnion) January 14, 2015
…and that was all I needed. Well. That and a multimeter. I started carefully probing the various 3-legged semi-conductors on the HDMIPi board. I thought it would take a long time to find what I was looking for, but it only took about 10 minutes. I found a transistor where one leg reads 0V when the HDMIPi LCD is on and 3V3 when it’s off. Perfect!
Oh Dear – It’s Really Small
The only problem is it’s really small…
…but I put the smallest tip on my soldering iron, cut a length of my finest wire, and used 0.7mm leaded solder to reduce the required heat. It was intricate, but I managed it without too much difficulty. Although it’s not the best solder joint I’ve ever done (I could have done with a magnifying lamp) it works…
This One’s A Bit More Difficult
Whereas the previous hack involved soldering to a button leg, which is fairly easy, this one is more advanced because of the precision required in soldering to this tiny component. I soldered a 330R resistor to the other end of the wire, (to protect the GPIO port) and wrapped one end of the resistor’s wire round the pin for GPIO 22. This makes for a nice ‘semi-permanent, but removable if needed’ connection…
I also still have my wire connecting GPIO25 to the HDMIPi power switch in place (from the previous hack).
Let’s Write Some Python Code
So that’s the hardware side of it done. Now we’ll need a bit of Python code to control and read the status of the LCD. Here’s what I came up with. I’ve tried to name the variables sensibly so that it reads almost as English…
#!/usr/bin/env python2.7 # HDMIPi_toggle2.py by Alex Eames http://raspi.tv/?p=7580 import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN) # 25 used for switching HDMIPi power GPIO.setup(22, GPIO.IN) # 22 used for sensing HDMIPi power status def toggle(switch_lcd_on): # switch_lcd_on = 1 for on, 0 for off hdmipi_is_off = GPIO.input(22) # only toggle lcd power if its measured status != what we want if (switch_lcd_on and hdmipi_is_off) or (not switch_lcd_on and not hdmipi_is_off): GPIO.setup(25, GPIO.OUT, initial=0) # press 'button' sleep(0.2) # hold button for 0.2 seconds GPIO.setup(25, GPIO.IN) # set port back to input (re-enables HDMIPi buttons) sleep(0.5) # small delay needed to avoid false readings for x in range(3): # on for 10s, off for 5s, iterate 3 times hdmipi_is_off = GPIO.input(22) # check if HDMIPi is powered up or not if not hdmipi_is_off: print "HDMIPi is ON at start of loop" , x+1 print "HDMIPi will stay on for 10 seconds" else: print "HDMIPi is OFF at start of loop" , x+1 print "HDMIPi will switch on for 10 seconds" toggle(1) # 1 = on sleep(9) print "HDMIPi is switching off for 5 seconds\n" sleep(1) toggle(0) # 0 = off sleep(5) toggle(1) # 1 = on if hdmipi_is_off: toggle(1) # 1 = on print "Leaving HDMIPi on to finish, so we know where we are" print "finished, now cleaning up GPIO ports" GPIO.cleanup() # How it works... ################# # If 25 is set as an input, the hardware pullup on the HDMIPi board # keeps value at HIGH. We only change the port to an output when we # want to toggle the button. # This is because, when set as an output, the HDMIPi buttons are disabled. # So each time we toggle the HDMIPi on or off, we set port back to input # 22 is used as an input to detect whether HDMIPi is powered on or not. # An input wire + 330R resistor join GPIO 22 to a transistor on # the HDMIPi board (It signals 0 when LCD is on, 3V3 when off)
So Now We Have Both Control And Status Reading
Now that we can read the status of the LCD and control it as well, what will you do with yours?
Will It Affect My Warranty?
I just know that someone will ask that, so I’m pre-empting the question. If your HDMIPi driver board breaks because you have interfered with it, it would be unreasonable to expect a free replacement. But if you know what you’re doing and solder carefully, there shouldn’t be a problem. (And if there is, we can sell you another one for something in the region of £20.)