Simple Power Indicator Script?

Forums:

Hi, I just purchased a LEDBORG however my python skills are limited. I was wondering how a basic script to have the led turn on once the unit is powered on would look.

Basically when the unit turns on, I would like a blue light to turn on and remain until it is powered off.

Thanks!

I'm currently working on it through Raspbian but I mainly use the Pi for Retropie.

piborg's picture

This should be nice and simple to do :)

First you want to create a script which sets the LedBorg to blue.
This can be based on LedBorg: lesson 1, but you do not need the delay or to turn the LedBorg off at the end.

You should end up with something like this:

#!/usr/bin/env python
 
# Import the library functions we need
import time
import wiringpi2 as wiringpi
wiringpi.wiringPiSetup()
 
# Setup the LedBorg GPIO pins
PIN_RED = 0
PIN_GREEN = 2
PIN_BLUE = 3
wiringpi.pinMode(PIN_RED, wiringpi.GPIO.OUTPUT)
wiringpi.pinMode(PIN_GREEN, wiringpi.GPIO.OUTPUT)
wiringpi.pinMode(PIN_BLUE, wiringpi.GPIO.OUTPUT)
 
# Set the colour channels (1 is on, 0 is off)
red = 0
green = 0
blue = 1
 
# Set the LedBorg colour
wiringpi.digitalWrite(PIN_RED, red)
wiringpi.digitalWrite(PIN_GREEN, green)
wiringpi.digitalWrite(PIN_BLUE, blue)
print 'LedBorg on'

I would recommend making the file in the cd ~/ledborg directory. Save it as something like powerLed.py.

Next edit the startup script for the pi: sudo nano /etc/rc.local. You want to add a new line just above the exit command to run this new script.

The bottom of the file should end up looking something like this:

sudo /home/pi/ledborg/powerLed.py &
exit 0

At this point the blue LED should come on when the Raspberry Pi is started :)

From memory that is all you need to do, I think the GPIO pins are switched off when the Raspberry Pi is shutdown anyway, which will make the LedBorg turn off.

Thanks brah. I'll try it tomorrow.

Greatly appreciate your help dude.

Subscribe to Comments for "Simple Power Indicator Script?"