JRoppert
JRoppert

Reputation: 5962

How to read the status of the Power-LED on Raspberry Pi 3 with Python

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.


Update:

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.

Upvotes: 2

Views: 4078

Answers (2)

Nabeel Ahmed
Nabeel Ahmed

Reputation: 19282

I have dig into the topic. Found a very good discussion. In RPi 3 control of power LED from GPIO has been removed as OP mentioned.

The probable reason:

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). Pi3's BT/wifi support required a number of additional GPIOs compared to Pi2. So, the ACT and PWR leds had to move to make that possible.

Also:

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. The ability to change the "PWR" LED pin to an output, bypasses the under-voltage detection, which is permitted but not recommended.

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. This is something we may address, but it isn't high on the list of priorities at the moment.


The possible wayout: 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.

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

Also:

For the complete list of GPIO allocations, look at the dt-blob.dts that configures the GPU side - https://github.com/raspberrypi/firmware/blob/master/extra/dt-blob.dts#L1175 Documentation is at https://www.raspberrypi.org/documentation/configuration/pin-configuration.md

If I get something helpful 'll post it as update 2.

Upvotes: 0

theBugger
theBugger

Reputation: 451

Because of Pi3's BT/wifi support Power LED is controlled directly from the GPU through a GPIO expander.

I believe that there's no way to do what you want

Upvotes: 1

Related Questions