How to use the Pi-LITEr from Ciseco

Controlling LEDs is one of the first projects people tend to shoot for, after the initial "Hello World" introduction to the Raspberry Pi. The problem with this is that not everyone is as good with the hardware side as they are with the code - with LEDs, resistors, current, volts etc putting people off initially.
There's also the difficulty for teachers trying to manage 20 children in a class, each soldering parts and/or getting things the wrong way round - a mammoth, and brave, task!

This is where small, pre-assembled and simplistic add-on boards such as the Pi-LITEr from Ciseco come in handy. Let me show you the board, and go through a few examples of simple code that I have written...

Ciseco PiLITEr

The PiLITEr - Small, but full of potential


The Board
First of all - what is it?
The Pi-LITEr is a small add on board that pushes on to the Raspberry Pi's GPIO pins. It comes with 8 LEDs, complete with the appropriate resistors, connected to 8 of the GPIO pins of your Pi. It's as simple as that - it's the same as if you broke out your GPIO to a breadboard and wired up 8 LEDs yourself - albeit this is a much smaller, easier and tidier package.
No resistors, soldering or messing around. You simply place the order online, and the nice people at Ciseco send you the pre-assembled board. I think this is great as an educational tool, ticking all the boxes that educators need - Cheap, simple, easy and safe.

It's the same size as an 8-point Lego brick!


What can I do with it?
This is the same as asking "What can I do with a Raspberry Pi and some LEDs" - depending on your level of Python skill, the possibilities really are endless. The LEDs are connected to standard GPIO pins, so if you can define an 'event' that would set a GPIO pin to 'output' - then you can make it happen on the Pi-LITEr.

The Pi-LITEr has 8 mega bright LEDs


Now some of us haven't even got that far yet, and this is probably more focussed towards new learners, so continue reading and we'll cover some code examples...
Preparation
Hold on there my friend, your Pi might not be ready to use GPIO commands just yet. You may have these modules installed already, but there's no harm in checking.
Get yourself into Terminal and run the following commands:

 sudo apt-get update  

(Updates your Raspberry Pi - just in case)

 sudo apt-get install python-dev  

(Gives our Pi everything it needs to use Python)

 sudo apt-get install python-rpi.gpio  

(Installs a module that enables you to control the GPIO pins)


Code Examples
There are 2 ways to control the Pi-LITEr that I know of - WiringPi and RPi.GPIO. I've always used the latter just because it's the first method that I learnt when starting out, so I'll use that in the code examples here. (which we set up in the previous step)
I have added 5 code examples for try out and learn with your Pi-LITEr, in order of difficulty/complexity. Go ahead and play with the numbers...breaking is learning (my dad knows this from all the PCs I killed as a child).
Before you try, here's a video showing how each one should work:


BEGINNER - Light LED 1 Only
If you're just starting out, have a go at this first. It will show you how we assign a single GPIO pin to 'turn on' as such (LED 1):

 #!/usr/bin/python  
 #  
 # PiLITEr 'beginner' script by the "Average Man"  
 # Check out http://AverageManVsRaspberryPi.com for more PiLITEr code examples  
   
 #import  
 import RPi.GPIO as GPIO  
 import time  
 import os  
   
 # Define PiLITEr to GPIO mapping  
 LED1 = 7  
 LED2 = 11  
 LED3 = 13   
 LED4 = 12  
 LED5 = 15  
 LED6 = 16  
 LED7 = 18  
 LED8 = 22  
   
 # Main program  
 def main():  
  GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbers  
  GPIO.setup(LED1, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED2, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED3, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED4, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED5, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED6, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED7, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED8, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
          
  # Turn on LED 1  
  GPIO.output(LED1) == True  
   
 if __name__ == '__main__':  
  main()  

BASIC - Light LEDs 1, 2, 3 and 4
A step up from the last example - light the first 4 LEDs:

 #!/usr/bin/python  
 #  
 # PiLITEr 'Basic' script by the "Average Man"  
 # Check out http://AverageManVsRaspberryPi.com for more PiLITEr code examples  
   
 #import  
 import RPi.GPIO as GPIO  
 import time  
 import os  
   
 #Turn off annoying warnings  
 GPIO.setwarnings(False)  
   
 # Define PiLITEr to GPIO mapping  
 LED1 = 7  
 LED2 = 11  
 LED3 = 13   
 LED4 = 12  
 LED5 = 15  
 LED6 = 16  
 LED7 = 18  
 LED8 = 22  
   
 # Main program  
 def main():  
  GPIO.setmode(GPIO.BOARD)  
  GPIO.setup(LED1, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED2, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED3, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED4, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED5, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED6, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED7, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED8, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
          
  # Turn on LED 1  
  while 1:  
   GPIO.output(LED1,GPIO.HIGH)  
   GPIO.output(LED2,GPIO.HIGH)  
   GPIO.output(LED3,GPIO.HIGH)  
   GPIO.output(LED4,GPIO.HIGH)  
     
   #Stay on for 6 seconds, then turn off LEDs and close  
   time.sleep(6)  
   GPIO.output(LED1,GPIO.LOW)  
   GPIO.output(LED2,GPIO.LOW)  
   GPIO.output(LED3,GPIO.LOW)  
   GPIO.output(LED4,GPIO.LOW)  
   
   return  
   
 if __name__ == '__main__':  
  main()  


SIMPLE - Light LEDs 1 to 8 In Turn
This time, we add timing to light one LED after another:

 #!/usr/bin/python  
 #  
 # PiLITEr 'Simple' script by the "Average Man"  
 # Check out http://AverageManVsRaspberryPi.com for more PiLITEr code examples  
   
 #import  
 import RPi.GPIO as GPIO  
 import time  
 import os  
   
 #Turn off annoying warnings  
 GPIO.setwarnings(False)  
   
 # Define PiLITEr to GPIO mapping  
 LED1 = 7  
 LED2 = 11  
 LED3 = 13   
 LED4 = 12  
 LED5 = 15  
 LED6 = 16  
 LED7 = 18  
 LED8 = 22  
   
 # Main program  
 def main():  
  GPIO.setmode(GPIO.BOARD)  
  GPIO.setup(LED1, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED2, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED3, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED4, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED5, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED6, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED7, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED8, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
          
  # Turn on LED 1  
  while 1:  
   #LED1  
   GPIO.output(LED1,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED1,GPIO.LOW)  
   #LED2  
   GPIO.output(LED2,GPIO.HIGH)  
   time.sleep(1)   
   GPIO.output(LED2,GPIO.LOW)  
   #LED3  
   GPIO.output(LED3,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED3,GPIO.LOW)  
   #LED4  
   GPIO.output(LED4,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED4,GPIO.LOW)  
   #LED5  
   GPIO.output(LED5,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED5,GPIO.LOW)  
   #LED6  
   GPIO.output(LED6,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED6,GPIO.LOW)  
   #LED7  
   GPIO.output(LED7,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED7,GPIO.LOW)  
   #LED8  
   GPIO.output(LED8,GPIO.HIGH)  
   time.sleep(1)  
   GPIO.output(LED8,GPIO.LOW)  
     
   return  
   
 if __name__ == '__main__':  
  main()  


LESS SIMPLE - Knight Rider Light
Remember KITT? This one makes further use of the timing function (no max loop exit so just close the script once you're done riding the knight):

 #!/usr/bin/python  
 #  
 # PiLITEr 'Simple 2' script by the "Average Man"  
 # Check out http://AverageManVsRaspberryPi.com for more PiLITEr code examples  
   
 #import  
 import RPi.GPIO as GPIO  
 import time  
 import os  
   
 #Turn off annoying warnings  
 GPIO.setwarnings(False)  
   
 # Define PiLITEr to GPIO mapping  
 LED1 = 7  
 LED2 = 11  
 LED3 = 13   
 LED4 = 12  
 LED5 = 15  
 LED6 = 16  
 LED7 = 18  
 LED8 = 22  
   
 # Main program  
 def main():  
  GPIO.setmode(GPIO.BOARD)  
  GPIO.setup(LED1, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED2, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED3, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED4, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED5, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED6, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED7, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED8, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
          
  # Turn on LED 1  
  while 1:  
   #LED sequence down  
   GPIO.output(LED1,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED1,GPIO.LOW)  
   GPIO.output(LED2,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED2,GPIO.LOW)  
   GPIO.output(LED3,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED3,GPIO.LOW)  
   GPIO.output(LED4,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED4,GPIO.LOW)  
   GPIO.output(LED5,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED5,GPIO.LOW)  
   GPIO.output(LED6,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED6,GPIO.LOW)  
   GPIO.output(LED7,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED7,GPIO.LOW)  
   GPIO.output(LED8,GPIO.HIGH)  
   time.sleep(0.05)  
   #LED sequence up  
   GPIO.output(LED8,GPIO.LOW)  
   GPIO.output(LED7,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED7,GPIO.LOW)  
   GPIO.output(LED6,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED6,GPIO.LOW)  
   GPIO.output(LED5,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED5,GPIO.LOW)  
   GPIO.output(LED4,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED4,GPIO.LOW)  
   GPIO.output(LED3,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED3,GPIO.LOW)  
   GPIO.output(LED2,GPIO.HIGH)  
   time.sleep(0.05)  
   GPIO.output(LED2,GPIO.LOW)  
   
   
 if __name__ == '__main__':  
  main()  


INTERMEDIATE - Temperature Monitor
A lot more going on in this example, but not too difficult once you break it down. Take a look at the code - it lights up each LED depending on the temperature of the Pi's chip. (This is set between 30 and 44 degrees, as mine normally sits at about 34 degrees)

 #!/usr/bin/python  
 #  
 # PiLITEr 'Intermediate' script by the "Average Man"  
 # Check out http://AverageManVsRaspberryPi.com for more PiLITEr code examples  
   
 #import  
 import RPi.GPIO as GPIO  
 import time  
 import os  
   
 #Turn off annoying warnings  
 GPIO.setwarnings(False)  
   
 # Define PiLITEr to GPIO mapping  
 LED1 = 7  
 LED2 = 11  
 LED3 = 13   
 LED4 = 12  
 LED5 = 15  
 LED6 = 16  
 LED7 = 18  
 LED8 = 22  
   
 # Main program  
 def main():  
  GPIO.setmode(GPIO.BOARD)  
  GPIO.setup(LED1, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED2, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED3, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED4, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED5, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED6, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED7, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
  GPIO.setup(LED8, GPIO.OUT) #Set GPIO pin to output (to 'give' power)  
   
  time.sleep(1)  
   
  timelastchecked = 0  
    
  #Clear LEDs if already lit from last usage  
  GPIO.output(LED1,GPIO.LOW)  
  GPIO.output(LED2,GPIO.LOW)  
  GPIO.output(LED3,GPIO.LOW)  
  GPIO.output(LED4,GPIO.LOW)  
  GPIO.output(LED5,GPIO.LOW)  
  GPIO.output(LED6,GPIO.LOW)  
  GPIO.output(LED7,GPIO.LOW)  
  GPIO.output(LED8,GPIO.LOW)  
       
  while 1:  
   if time.time() >= timelastchecked:  
    timelastchecked = time.time()+3 #Check every 3 seconds  
    mytemp = ""  
    f=os.popen("/opt/vc/bin/vcgencmd measure_temp") #Temperature command for terminal  
    for i in f.readlines():  
     mytemp += i  
     mytemp = mytemp[5:-5] #removes 5 characters from the front of the string, and 5 from the back  
     if '30' <= mytemp <= '31': #If temp between 30 and 31  
      GPIO.output(LED1,GPIO.HIGH)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.LOW)  
     if '32' <= mytemp <= '33':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.HIGH)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.LOW)  
     if '34' <= mytemp <= '35':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.HIGH)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.LOW)  
     if '36' <= mytemp <= '37':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.HIGH)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.LOW)  
     if '38' <= mytemp <= '39':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.HIGH)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.LOW)  
     if '39' <= mytemp <= '40':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.HIGH)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.LOW)  
     if '41' <= mytemp <= '42':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.HIGH)  
      GPIO.output(LED8,GPIO.LOW)  
     if '43' <= mytemp <= '44':  
      GPIO.output(LED1,GPIO.LOW)  
      GPIO.output(LED2,GPIO.LOW)  
      GPIO.output(LED3,GPIO.LOW)  
      GPIO.output(LED4,GPIO.LOW)  
      GPIO.output(LED5,GPIO.LOW)  
      GPIO.output(LED6,GPIO.LOW)  
      GPIO.output(LED7,GPIO.LOW)  
      GPIO.output(LED8,GPIO.HIGH)  
   
 if __name__ == '__main__':  
  main()  
   


Summary
There is a lot more that can be done with LED control, it really is all down to how much you can do in Python (or other languages), but hopefully the code examples above have taught you a few things and have got you thinking about creating your own code.
If you have any questions, just leave a comment below.
Want a Pi-LITEr? Get one direct from Ciseco

Continue reading here: How To Set Up WiFi on the Raspberry Pi

Was this article helpful?

0 0