Controlling the raspberry pi Zero built-in LED: via BMC pin or led0

The activity LED on the pi PCB is normally driven by "disk" activity but you can control it directly.  The PiZero broadcom pin number for the LED differs from the other models so you may tear out your hair if you want to control it from wiringPi or other programming libraries, but from the command line it's called led0 just like all other pi boards.

Command line:

Put LED under manual control:
echo none > /sys/class/leds/led0/trigger 


turn on led:
echo 0 >/sys/class/leds/led0/brightness

turn off led:

echo 1 >/sys/class/leds/led0/brightness

Yes, that's backwards from what you would expect. The LED is active-low and the designers didn't encapsulate that detail.

What if you want to control it from a library like WiringPi? Then you need to know the broadcom (BCM) pin wired to the LED. On the Zero (w) it's pin 47. You can test this for yourself at the command line:

gpio -g blink 47

If you have a non-zero pi, try BCM pin 16. I only deal in zeros, so I cannot confirm.

For controlling the LED0 from C/C++ code I've found two libraries, here's the examples/docs for both: (pigpio) http://abyz.me.uk/rpi/pigpio/cif.html and (wiringpi) http://wiringpi.com/examples/blink/.  Don't know which I would use yet. There's at least one thread suggesting pigpio has better latency.

In any case, using wiringpi:

#include
int main (void)
{
wiringPiSetupGpio ();
  pinMode (47, OUTPUT) ;
  for (;;)
  {
    digitalWrite (47, HIGH) ; delay (500) ;
    digitalWrite (47,  LOW) ; delay (500) ;
  }
  return 0 ;
}


Note: pi zero only has one LED, despite having a led1 in the filesystem path.

Comments

Email me

Name

Email *

Message *

Popular posts from this blog

Panasonic TH-42PX75U Plasma TV review: input lag and upscaling tested using the piLagTesterPRO

piLagTester PRO order page

Vizio VX20L HDTV review: input lag and upscaling tested using the piLagTesterPRO