Reviving "Borkin" Power On/Off Button for the Raspberry Pi 4B

13/04/2020 - 13:37 by poney

There are some resources explaining how to leverage the jack audio port from the Raspberry Pi 2, 3 and 3B+ to make a neat and nice power on/off button. However this doesn't work for the Raspberry Pi 4B.

This post explains the general concept behind it, why it doesn't work on RPi4B and how to revive it.

How can we make a power on/off button?

According to BCM2711 bootloader config documentation, if WAKE_ON_GPIO is set to 1, then powering off a Raspberry Pi leads to switching it to a low power mode. It can then wake up by grounding GPIO3 or GLOBAL_EN. This same port can be leveraged to implement the shutdown process as well.

This can be acheived in 2 ways:

  1. wire GPIO3 (Pin#5) and any ground GPIO (eg. Pin#6) to a push-button (example)
  2. wire GPIO3 to an existing port. That's exactly what the Borkin button does by repurposing one of the Jack Socket (example 2).

Here is a view of the Raspberry Pi GPIOs:

Raspberry Pi GPIOs highlighting the Pin#5 (GPIO3) and Pin#6 (GND)

How to leverage the A/V Jack Socket for a power on/off button?

From the official schematics, we can see the following wiring for A/V Jack port:

RPi2 rev 1.2:

Raspberry Pi 2 A/V Schematics

RPi3B rev 1.2:

Raspberry Pi 3B A/V Schematics

RPi3B+ rev. 1.0:

Raspberry Pi 3B+ A/V Schematics

RPi4B 4.0:

Raspberry Pi 4B A/V Schematics

From these schematics, it's possible to highlight two important bands #1 and #2 (GND). The #1 can be a good candidate to get wired with GPIO3.

Mapping these schematics to their implementation, shows that the Raspberry Pi board is using the 3.5mm 4 Pole Jack Sockets from CLIFF (FC68125):

Raspberry Pi used FC68125 Jack Socket

Using a multimeter, these ports can be mapped to the following pins on the RPi4B:

Raspberry Pi Jack Socket Pins Identification

Can we make or reuse an existing technology to make a push button connecting Sleeve (band #1) and Ring2 (band #2)? The answser is yes, there are some "click 3.5mm jack buttons" sold for around 1 USD online. Pressing the button will connect the two pointed parts, which is exactly what is looked for here.

Raspberry Pi Click Jack Button

This has been proven to be working on the RPi2, 3B and 3B+, but doesn't work on the RPi4B, where the documented A/V schematics are exactly the same.

Why doesn't it work on the RPi4?

Testing current continuity between Sleeve and Ring2 on the RPi4 shows that it's already grounded with a 77 ohm of resistance, where it shows no continuity on the previous models of the Pi. Is this tied to a weird behavior of the BAV99 Signal Diode (D4)? or termination resistors?

Cutting the circuit between Sleeve and the D4 diode, didn't help:

Raspberry Pi 4B Cutting Sleeve to D4 Track

The resistance is still 77 ohm. This cut wasn't required.

Desoldering the Jack Socket to undercover hidden tracks and exclude the hypothesis of a defective socket:

Raspberry Pi 4B Desoldered Jack Socket

The socket isn't involved in this resistance, however, there is an undocumented second track between Sleeve and a termination resistor, which didn't exist in previous models:

Raspberry Pi 4B Sleeve to a Termination Resistor Undocumented Track

Cutting it down finally isolates Sleeve from ground:

Raspberry Pi 4B Sleeve to a Termination Resistor Undocumented Track Cut

Great, this did the job.

What about the software side so the push button can be detected to trigger the power on/off?

Shutdown script:

The shutdown script can leverage GPIO callbacks to reduce CPU resource consumption and trigger the shutdown routine only at GPIO change level (button pressed). Also, to prevent accidental power off, the script reads a second time the GPIO3 (Pin#5) value after 3 seconds to confirm that the power off button is still pressed.

#!/usr/bin/python
import time, subprocess

import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)  # RuntimeWarning: A physical pull up resistor is fitted on this channel!
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
        GPIO.wait_for_edge(5, GPIO.FALLING)
        print("[*] Power off detected")
        time.sleep(3)
        ret = GPIO.input(5)
        if ret == 0:
                print("[*] Power of still pressed after 3 sec, shutting down")
                subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        else:
                print("[*] Power of not pressed anymore. Skipping shutdown")

This one can be executed at boot time by either leveraging crontab or systemd. Example of a root crontab:

@reboot /root/scripts/shutdown.py

Conclusion:

In order to revive the Borkin power on/off button for the Raspberry Pi 4B, cutting the undocumented track between Sleeve and the termination resistor is required. This allows isolating it from ground. Then wiring the GPIO3 to the Sleeve pin as explained will do the trick.

One more thing: did the author implement the idea presented before?

Of course no, this is because:

  1. track between Sleeve and D4 diode was already cut for testing
  2. track between Sleeve and termination resistor was also cut for validation purposes
  3. the most important 2 pins from the Jack Socket (Sleeve and Ring2) were detroyed during the desoldering process

Author ended up performing:

  1. a dirty fix of the Jack Socket without soldering
  2. soldering a wire between GPIO3 (Pin#5) and the broken Sleeve on the Jack Socket
  3. soldering another wire between GND (Pin#6) and the broken Ring2 on the Jack Socket.

Open idea: in all Raspberry Pi models, leaving the COMPVID track between Sleeve and the D4 diode uncut does propably trigger a shutdown when it's active. This happens when the RPi is switched to composite video mode which can be done by pressing 3 (PAL) or 4 (NTSC) during NOOBS startup. Don't do it :)

Adel

Comments

comments powered by Disqus