Find fresh tutorials related to Arduino, Raspberry Pi, 555 Timer and many more microcontrollers. Learn something new everyday!



Saturday 20 December 2014

Blinking an LED (An intro to Raspberry Pi) [RPI]



OK. So, let's discuss something about the Rpi. Many of you might know what it is. Many might not.

According to Wikipedia,

The Raspberry Pi is a credit card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.

According to me,

It's the bigger brother of Arduino, in terms of memory and performance but in a certain context
Although the RPi functions a lot as a computer(which it is!), it has also got the 40 GPIO pins, much similar to the digital pins of the Arduino. To be frank, there are lots of differences between them too. But, since we are more interested in the application of both the MCU's in sensing the environment and manipulating them, we'll confine ourselves to the input/output capabilities.

That's enough talk about RPi. For more info, you may simply search for "Raspberry Pi" on Google and you'll be saturated with information! :P


So, let's begin.

What this project does?
Blink an LED 20 times using the RPi.


Let's know the basics!
Well, you should be knowing what an LED is and what minimum current should pass through it. For me, it was around 20 mA. Do refer to your LED Datasheet for more info. Also, keep in mind that messing up even a little bit can damage your RPi, which is a little more heavier on the pocket as compared to the Arduino!

NOTE:
This is the arangement of the pins. Please keep this in mind. 1 is the PIN No.1.


NOTE:
The GPIO Pins on the RPi, can be fully controlled via Python. So, it's recommended that you play around with some Python code and get acquainted with the Python environment.
Here are some sites to get you started if you have no or zero knowledge of the Python environment.




Materials Required:
1. An LED
2. Raspberry Pi and accessories. (Including monitor, keyboard and mouse)
3. Jumpers
4. One 330 OHM resistor
5. Breadboard


Procedure:
1. Start up RPi and open LeafPad.

2. Type in the code(scroll down to find the code) and save the file with the name: "blink,py".
    Save this file in the root folder, i.e, [/home/pi]

3. Connect all the components as shown below:



Connect:
  • GPIO PIN17 [PIN No.11] to the LED's +ve pin 
  • GPIO GND[PIN No. 6] to the LED's -ve pin via resistor.
NOTE: To see the pin layout on Raspberry Pi model B+, check out the attachment in the downloads section.


4. Open LXTerminal and type the command:

sudo python blink.py

and press enter.

5. You should see the LED flash. After blinking 20 times, the GPIO pins return to normal state.


Python Code:

#Code by electro.nitishdash.com
import RPi.GPIO as GPIO
import time
def blink(pin):
        GPIO.output(pin,GPIO.HIGH)
        time.sleep(1)
        GPIO.output(pin,GPIO.LOW)
        time.sleep(1)
        return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output pin
GPIO.setup(11, GPIO.OUT)
#to blink GPIO17 20 times
for i in range(0,20):
        blink(11)
GPIO.cleanup() 



Video:
Coming soon.....


Downloads:
1. blink.py
2. Breadboard schematics
3. Pin layout (Model B+)


Homework for you!
1. Try adding 3 leds of different colours and light them up one by one after a small interval.


2 comments:

  1. Wow! That works amazingly.... Nobody would have ever thought that the world would see that small a computer!

    Good Work. Will surely share all your articles with my circles and friends.
    Have a good day!

    -John

    ReplyDelete
    Replies
    1. Thanks a lot for your comment John. I am really happy that you liked it.
      Yes, the RPi is a beautiful tiny computer. I'd recommend you to check out other MCUs like Beaglebone, etc.

      Sharing is caring bro! Thanks.

      Delete

Leave your valuable feedback and suggestions.

Upcoming projects!

1. Programming ESP8266 using NodeMCU and LUA Scripts

2. IoT Applications

3. NRF42L01 2.4 GhZ module interfacing with arduino

4. ESP8266 - Everything cool about it!

Language ain't any barrier!

Get Updates!

Enter your email address:


Get the latest projects delivered into your inbox, hot!