How to read the status of the Power-LED on Raspberry Pi 3 with Python
<p>How to read the status of the Power-LED (or the rainbow square - if you like that better) on Raspberry Pi 3 to detect an low-voltage-condition in a python script? Since the wiring of the Power-LED has changed since Raspberry Pi 2, it seems that GPIO 35 cannot longer be used for that purpose.</p>

<hr>

<p><strong>Update:</strong></p>

<p>Since it seems to be non-trivial to detect a low-power-condition in code on Raspberry Pi 3, i solved it with a quick hardware hack. I soldered a wire between the Output of the APX803 (the power-monitoring device used on Pi 3) and GPIO26 and that way I can simply read GPIO26 to get the power status. Works like a charm.</p>

<p>I have dig into the topic. Found a very good <a href="https://github.com/raspberrypi/linux/issues/1332" rel="nofollow">discussion</a>. In RPi 3 control of power LED from GPIO has been removed as OP mentioned.</p>

<p>The probable reason:</p>

<blockquote>
  <p>The power LED is different on Pi3. It is controlled from GPU through a
  GPIO expander which is configured as an input. It may not be possible
  to drive it from the arm (certainly it is not currently). <strong>Pi3's
  BT/wifi support required a number of additional GPIOs compared to Pi2</strong>.
  So, the ACT and PWR leds had to move to make that possible.</p>
</blockquote>

<p>Also:</p>

<blockquote>
  <p>Since the B+ the functionality of PWR LED has doubled, power indicator
  and as well as an under-voltage indicator. Since GPIOs are in short
  supply, as well as being an indicator it is also the under-voltage
  detector - there is some external circuitry that can detect the GPIO
  direction so that it is either an input with an automatic LED or an
  output. This circuitry is only present on the red LED. <strong>The ability to
  change the "PWR" LED pin to an output, bypasses the under-voltage detection, which is permitted but
  not recommended</strong>.</p>
  
  <p>These GPIOs may never be available as fully
  featured GPIOs because they are too slow to use in many circumstances.
  There is a simple GPIO driver that can efficiently control the ACT
  LED, but more effort is needed to make it work with the PWR LED and
  change its direction to an output. <strong>This is something we may address,
  but it isn't high on the list of priorities at the moment</strong>.</p>
</blockquote>

<hr>

<p><strong>The possible wayout</strong>: Didn't find any way of using Python to access GPU, but found some discussions regarding accessing GPU configuration - sharing it as looking into it could be helpful for you in replicating an equivalent functionality in Python.</p>

<blockquote>
  <p>There is also the mailbox service that would allow userspace to <strong>fiddle
  with the outputs on the expander</strong>, but not set direction - see
  <a href="https://www.raspberrypi.org/forums/viewtopic.php?f=43&amp;t=109137&amp;start=100#p990152" rel="nofollow">https://www.raspberrypi.org/forums/viewtopic.php?f=43&amp;t=109137&amp;start=100#p990152</a>
  and <a href="https://github.com/6by9/rpi3-gpiovirtbuf" rel="nofollow">https://github.com/6by9/rpi3-gpiovirtbuf</a></p>
</blockquote>

<p><a href="https://github.com/raspberrypi/linux/issues/1332#issuecomment-231744888" rel="nofollow">Also</a>:</p>

<blockquote>
  <p>For the complete list of GPIO allocations, look at the dt-blob.dts
  that configures the GPU side -
  <a href="https://github.com/raspberrypi/firmware/blob/master/extra/dt-blob.dts#L1175" rel="nofollow">https://github.com/raspberrypi/firmware/blob/master/extra/dt-blob.dts#L1175</a>
  Documentation is at
  <a href="https://www.raspberrypi.org/documentation/configuration/pin-configuration.md" rel="nofollow">https://www.raspberrypi.org/documentation/configuration/pin-configuration.md</a></p>
</blockquote>

<p>If I get something helpful 'll post it as update 2.</p>

python raspberry-pi3