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. – stevieb Jul 07 '17 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 – hmmy92 Jul 07 '17 at 13:23
-
Ok, fair enough :) – stevieb Jul 07 '17 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 Jul 07 '17 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? – hmmy92 Jul 07 '17 at 14:13
-
Please do not bother asking how to read the state of a GPIO on a Raspberry Pi. This must have been regurgitated here and elsewhere on the internet *literally thousands of times*. You might as well ask other people to do basic arithmetic for you ("Please, what is 3 + 5?") when there is a calculator in your hand. **Use a search engine.** – goldilocks Jul 07 '17 at 14:59
-
I know how to read the state of a GPIO but GPIO 35 is not working so I asked if somebody else has tried something different – hmmy92 Jul 07 '17 at 17:17
-
@goldilocks the supposed duplicate refers to Pi2. On the Pi3 the power is connected to a port expander. The question is a duplicate, see [Raspberry Pi Power Limitations](http://raspberrypi.stackexchange.com/questions/51615/raspberry-pi-power-limitations) which has some comments. There are other answers (how DO you find duplicates you know are there) – Milliways Jul 08 '17 at 00:08
-
@Milliways You're right; [someone here implies](https://stackoverflow.com/questions/39251079/how-to-read-the-status-of-the-power-led-on-raspberry-pi-3-with-python) because of this it's not possible, although the end of your answer implies there is. I don't see this as a duplicate of that though. – goldilocks Jul 08 '17 at 13:09
2 Answers
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.
- 56,430
- 17
- 109
- 217
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.
- 54,718
- 26
- 92
- 182
-
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 – hmmy92 Jul 11 '17 at 08: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. – Milliways Jul 11 '17 at 12:35