Raspberry Pi Adventures – Chapter 2: GPIOs and LED

In the previous post, we looked at accessing the Raspberry Pi Compute Module via another computer through SSH. The Pi can do a gazillion things. It depends on how imaginative and creative you are.  For now, I want to show you something simple; lighting up three LEDs through the Pi using the GPIO (General Purpose Input Output). Since the Raspberry Pi Compute module is a bootstrapped version of the normal Raspberry Pi, we will use the CMIO’s GPIO pins.

For further explanation on GPIO, read this article.

What’s in the Cooking Pot?

Basically, we’re sending two signals to the 3 LED to go on and off 10 times in a sequence. What do I need to achieve this?

  1. Breadboard
  2. Wires
  3. Three LEDs
  4. 3 resistors of 330 ohms
  5. Raspberry Pi compute module
  6. Compute module input output board
  7. USB cable
  8. Ethernet cable
  9. USB-Ethernet adapter (if your computer does not have an Ethernet port)

Let’s Cook

I first setup a circuit to test if the LED will work with the Raspbery Pi when connected to GPIOs pins for 3.3V and 0V. This is just a basic circuit and no programming involved:

Raspberry Pi Circui
Initial circuit to test functionality of LED

The final setup should look like this:

raspberry pi led setup
The complete setup

Now that the setup is complete, we’ll need to write the code that will light up the lights.

LEDs light up
BOOM! And the LEDs light up

In summary the code does the following:

  • Export GPIO pin to the file system (lines 17,21,25); a new directory will appear in the file system that corresponds to the pin number
  • Give the I/O direction that the GPIO will respond to when activated (lines 18,22,26). In this case its output i.e. the pin becomes an output entity
  • Sets the pin value high (3.3V) or low (0V) by echoing one or zero (lines 36 – 56). This is a digital logic system hence high and low do not correspond to 1 or 0 binary values respectively; they allow for current flow in the pins
  • Light up the LEDs one after the other 9 times using a while loop

Of importance, the script should be run as root for it to execute.




Please follow and like us:

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

May 27, 2016

Posted In: Information Technology


Leave a Comment