Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent Visit Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

Sunday, December 22, 2013

Raspberry pi LED Blinker

Ever since I came to Malaysia my inventive side is becoming more and more sharper. Mainly because of the Electronic components available easily in Malaysia for affordable prices. I bought a myself a Raspberry pi Model B with a Transparent casing + 8 Gb SSD Card with Preloaded Noobs for just MYR 199 (USD 60.53).

Furthermore I went to an area called Jalan Pasar in Pudu where there are lots and lots of Electronic shops which sells all sorts of components. I am waiting to do more hacks and hobby projects in the future but to start off I did a small LED Blinker project using Raspberry pi.

The following steps needs to be carried out to Run the LED Blinker in Raspberry pi.
  • Login to Raspberry pi
  • Open a LXTerminal window
  • Download the python GPIO library

  • Untar the Tar file

  • tar zxvf RPi.GPIO-0.4.1a.tar.gz

  • Go into untared directory

  • cd RPi.GPIO-0.4.1a

  • Install GPIO for python

  • sudo python install

    If you get errors during the installation process then you must first do the following

    source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
    Compilation terminated.
    error: command 'gcc' failed with exit status 1
    • Run apt-get update
    sudo apt-get update
    • The install python dev (Debian)
    sudo apt-get install python-dev

    • Pidora 

    sudo yum -y install python-devel

    After that do the following wiring where an LED ground is connected using a 1K Resistor to the Raspberry pi GND pin 6. And pin 7 GPIO 4 is connected to the LED Positive.

    Then copy the following code to a text editor and save it as

    import RPi.GPIO as GPIO 
    import time 
    import threading
    GPIO.setup(7, GPIO.OUT) 
    class Blinker(threading.Thread):
        def __init__(self, speed, times):    
            self.speed = speed;    
            self.times = times;
        def run(self):
            for i in range(0,self.times):
                print "Time : %d" % ((i+1))
            print "Blinking Complete!" 
    blinker = Blinker(1, 10)
    • Finally close the LXTerminal and open a new one and execute the following
    sudo python

    Everything working together


      No comments: