How can I read the status of the on board red led in raspberry 3.0 model B? Thank you
-
The red LED is the power LED. If any code is running at all, you can assume that this LED is on.– steviebCommented Jul 7, 2017 at 13:07
-
In raspberry 3 when voltage in lower than 4.65 Voltage red led turns off. So I would like to detect voltage drops using the value of this LED– hmmy92Commented Jul 7, 2017 at 13:23
-
Ok, fair enough :)– steviebCommented Jul 7, 2017 at 13:28
-
In case GPIO 35 is confusing, it does not have a breakout pin but you can still read its state normally (using the BCM numbering).– goldilocks ♦Commented Jul 7, 2017 at 14:01
-
Thanks for your reply, I am using Raspberry Pi 3 Model B Rev 1.2 how can I read the status of this pin? As I have seen pi3 is not supporting detection of under-voltage using this pin. Am I wrong?– hmmy92Commented Jul 7, 2017 at 14:13
2 Answers
Your question is ambiguous.
If you want to determine the low voltage state, you can do this by reading the state through a mailbox interface. I have used the following c code:-
https://raspberrypi.stackexchange.com/a/54328/8697
Other code described in https://raspberrypi.stackexchange.com/a/44177/8697 may also make it possible, but untested.
If you just want to read LED status /sys/devices/platform/leds/leds/led1
seems to work; whether this also reflects the low voltage state is unknown (and AFAIK) undocumented. It is certainly possible to extinguish the LED by writing 0
to brightness
.
Examination of the Pi3 circuitry (which differs from earlier models) seems to indicate that if the voltage is Low the LED will ALWAYS be off.
I have not explored what the impact of writing to /sys/devices/platform/leds/leds/led1
is on the rpi3-gpiovirtbuf
. GPIO can be input OR output (but who knows about the expander), so they may be incompatible functions.
Testing low voltage is a non-trivial task.
-
Thank you for your reply, I tested the code you suggested and unfortunately didn't work. It returns always "Get state of 135 as 0" despite there is or not under-voltage. Finally, I checked for the directory but there is no folder leds on /sys/device/platform– hmmy92Commented Jul 11, 2017 at 8:29
-
The code worked last time I tried it. As I stated testing low voltage is a non-trivial task. If you don't have led1 you don't have the latest 4.9.35 kernel. Commented Jul 11, 2017 at 12:35
Current kernels have the board LEDs in /sys/device/platform/leds/leds
. There are two; in each subdirectory you will find a uevent
node with some information. led0
is evidently the green ACT light:
OF_NAME=act
OF_FULLNAME=/leds/act
OF_COMPATIBLE_N=0
And led1
is the red PWR light:
OF_NAME=pwr
OF_FULLNAME=/leds/pwr
OF_COMPATIBLE_N=0
Note these names correspond to another sysfs directory, /sys/firmware/devicetree/leds
-- but the information there does not look pertinent. However, in the same directory as uevent
there is brightness
, which apparently has a range of 0-255; normally when running it's 255. Although that node is writable, trying to change the value has no effect. But reading its state is obviously possible.