Chasing LEDs Raspberry Pi and PiFace

5 May

Tonight, my dad an I decided to do a chasing LED.  I want to do an LED cube, but it was too close to my bedtime.  We got the basic instructions from this instructables.  Here’s what you’ll need to complete the project:

Raspberry Pi with accessories


LEDs, breadboard, resistors, and wires


The circuit is set up basically by having each of the positive legs of the LEDs (the longer leg) in one of the rails of the breadboard that go all the way from one end to the other.  The positive 5 Volts from the PiFace is connected to the rail next to that one and then a resistor connects the two rails so that the 5 volts must pass through the resistor to get to the LEDs.  I used a 180 ohm resistor because that’s what came with the Raspberry Pi CanaKit.  I ended up adding a second resistor for the video because the LEDs were too bright.

Then, each short leg of the LED goes to its own row on the breadboard and is connected to a different output on the PiFace from LED0 to LED7.

Here’s a picture of the code:


Here’s what each line does:

Lines 1 and two import libraries to be used later.  Line 3 is blank.  Line 4 shortens that long code into shorter pfd.  Line 5 makes sure that all of the LEDs are turned off.  Line 6 is going to make the entire sequence run 5 times.  Lines 7 to 11 is the loop that sequentially turns each LED on and then back off again after waiting .o2 seconds.  Lines 12 to 16 is the loop that reverses the sequence and turns the LEDs on and off from the other end.  The last line just once again makes sure that all of the LEDs are turned off before ending the program.

I did one new thing tonight.  I normally use VIM to type my programs into the terminal window but I keep forgetting the commands.  So, tonight, I used nano.  To run nano, just type “sudo nano” at the command prompt.  Then you use ctrl and the “O” key to save the file and ctrl and the “X” key to exit nano.  Then to run the program from the command line, I just type “sudo python” (my program’s name was

Here’s a video of the LEDs working.




5 Responses to “Chasing LEDs Raspberry Pi and PiFace”

  1. John May 8, 2014 at 2:30 am #

    For writing programs, there is a lightweight IDE (Integrated Development Environment) that runs pretty good on the Pi called Geany. You can install it with:

    sudo apt-get install geany

    Although if your Dad has you using VIM for writing programs he might get mad I told you about IDEs 🙂

    • krystal92586 May 8, 2014 at 6:19 am #

      Thanks for the tip. I’ll check it out.
      I told the story in a previous blog post that my uncle who hires computer programmers for his company says that he would never hire a programmer who doesn’t use VIM (he just calls it VI). That’s the reason I started using it. I’ve been working on the Harvard CS50x course and they have us using Gedit to write our programs and there’s a terminal window at the bottom where we can “make” and run them. It looks very similar to geany. Do you know if they have Gedit for Raspberry Pi?

      • John May 8, 2014 at 7:07 am #

        Software developers generally fall into 2 camps – those that use text editors (usually VIM or EMACS) to write programs and those that use IDEs (Eclipse and PyCharm are the biggest for Python), and it’s really just a matter of what you’re most comfortable with. For a lot of people, what they are most comfortable with is frequently whichever one they learned on first. There are definite advantages to each one though and knowing how to use *both* would be best 🙂
        Personally I like to use an IDE for bigger projects with lots of files, but I use a text editor for smaller single file programs. Because I don’t use the text editor as much though, I’m more likely to use IDLE or nano rather than VIM because VIM takes a while to really get good at using. If you take the time to really learn it though it is very powerful.

        VIM is an expanded version of VI that does things like text highlighting of keywords and can be used in places where VI can’t. Vi is a turbo text editor that has been around a LONG time. I learned how to program in C using VI.

        In theory I think gedit can be installed on the Pi. Gedit is the default general text editor for the gnome desktop, kind of like leafpad is on Raspbian (though a bit fancier). Since the Pi uses the LXDE desktop instead of gnome, you will have to install a bunch of gnome libraries that gedit is dependent on though which can take up a lot of space on the SD card. It can be kind of a pain to do, but would be a good exercise if you just want to see if you can get it to work. I like to keep a spare SD card laying around for doing “experimental” installations like that so if things go really wrong I can just wipe it out and start over without messing up the SD card I use on projects.

  2. AIMEE2080DUBLIN September 5, 2014 at 11:10 am #

    thanks for the tips you people commented


  1. Chasing LEDs Raspberry Pi and PiFace | Raspberry World - May 5, 2014

    […] By krystal92586 […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: