Renewable Energy Innovation

  • Increase font size
  • Default font size
  • Decrease font size
Error
  • Error loading component: com_contact, 1
Email Print

No image

Having been to Derby Mini Maker Faire the previous day I had bought myself a very simple (and cheap) LED light add-on for the Raspberry Pi. This was called the Pi-LITEr. It is a plug-in PCB for the RPi GPIO (general purpose IO) pins. It has 8 LEDs on it.

I have not played too much with my RPi and wanted to have a go with controlling the GPIO.


The first problem was that I do not have a HDMI monitor. To get around this I followed these instructions to connect to the RPi using SSH (Secure Shell). I downloaded a copy of Occidentalis distribution for the RPi from AdaFruit learning onto a 4GB SD card. I put this into my RPi which was connected with an ethernet connection to my router, and booted up the RPi.

I needed to download Advanced IP Scanner from here. This allowed me to scan for the IP address of the RPi.

I downloaded an SSH client called PuTTy. I used the IP address from the scan to start an SSH session. I was greeted with the line "Login:" and entered 'pi' as the user and 'raspberry' as the password (this is the usual user/password combination).

This worked and I could talk to the RPi.

Now I wanted to switch one of the LEDs on. There was some documentation from CISECO, who make the Pi-LITEr. There is also a datasheet here which shows the wiring for the simple board.

I was going to follow the Adafruit learning system for the RPi, but probably with my own hardware. The Pi-LITEr was my first step towards this.

At this point I followed Adafruit's RPi lesson 4 - GPIO setput. This installed everything required to control the GPIO and also attach I2C devices. The Adafruit lessons then start to use the I2C bus to connect to a load of their boards. I just wanted to switch On and Off some LEDs.

I found this tutorial which explained how to create and run a Python program for the RPi (its from the 'for Dummies' series which is a prefect level for me). I also found this Python Tutorial from the Python website. I also needed the help of my housemate for basic editor commands (Cheers, Mouse).

I found a bit more about the GPIO commands here. And this led me to my very first python program here:

#!/usr/bin/env python

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GREEN_LED = 18
RED_LED = 23
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)

while True:

        GPIO.output(GREEN_LED, True)
        GPIO.output(RED_LED, False)

You need to be 'Sudo' to use the GPIO so I ran this with the line "sudo python led1", where "led1" is the filename.

This switched on an LED! Yey! Hello World!

Overview

The next simple challenge was just switching ALL the LEDs on. This proved harder than I thought. The main issue was that the Pi LITEr manual GPIO numbers do not tie in with the actual LEDs controlled. Through a bit of research and some trial and error I figured out the following GPIO pin numbers:

#!/usr/bin/env python

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

LED_1 = 4
LED_2 = 17
LED_3 = 27
LED_4 = 18
LED_5 = 22
LED_6 = 23
LED_7 = 24
LED_8 = 25

GPIO.setup(LED_1, GPIO.OUT)
GPIO.setup(LED_2, GPIO.OUT)
GPIO.setup(LED_3, GPIO.OUT)
GPIO.setup(LED_4, GPIO.OUT)
GPIO.setup(LED_5, GPIO.OUT)
GPIO.setup(LED_6, GPIO.OUT)
GPIO.setup(LED_7, GPIO.OUT)
GPIO.setup(LED_8, GPIO.OUT)


while True:

        GPIO.output(LED_1, True)
        GPIO.output(LED_2, True)
        GPIO.output(LED_3, True)
        GPIO.output(LED_4, True)
        GPIO.output(LED_5, True)
        GPIO.output(LED_6, True)
        GPIO.output(LED_7, True)
        GPIO.output(LED_8, True)

This worked and switched all the LEDs on....

Overview

I added some time functions to control them switching on and off. This simple routine flashes all the LEDs On and Off once per second, ten times then finishes.

#!/usr/bin/env python

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)

LED_1 = 4
LED_2 = 17
LED_3 = 27
LED_4 = 18
LED_5 = 22
LED_6 = 23
LED_7 = 24
LED_8 = 25

loop = 1

GPIO.setup(LED_1, GPIO.OUT)
GPIO.setup(LED_2, GPIO.OUT)
GPIO.setup(LED_3, GPIO.OUT)
GPIO.setup(LED_4, GPIO.OUT)
GPIO.setup(LED_5, GPIO.OUT)
GPIO.setup(LED_6, GPIO.OUT)
GPIO.setup(LED_7, GPIO.OUT)
GPIO.setup(LED_8, GPIO.OUT)


while (loop<10):

        GPIO.output(LED_1, True)
        GPIO.output(LED_2, True)
        GPIO.output(LED_3, True)
        GPIO.output(LED_4, True)
        GPIO.output(LED_5, True)
        GPIO.output(LED_6, True)
        GPIO.output(LED_7, True)
        GPIO.output(LED_8, True)

        sleep(0.5)

GPIO.output(LED_1, False)
        GPIO.output(LED_2, False)
        GPIO.output(LED_3, False)
        GPIO.output(LED_4, False)
        GPIO.output(LED_5, False)
        GPIO.output(LED_6, False)
        GPIO.output(LED_7, False)
        GPIO.output(LED_8, False)

        sleep(0.5)

        loop += 1

print "FIN"

This is the start of my python programming and Raspberry Pi hardware fun.....