Vadim Tabakman

Getting an LED to Light Up

I'll be the first to admit that it's been many many many years since I've done anything to do with electronics and I can't read the simplest electronics diagram if my life depended on it.  This is actually one of the reasons I'm messing around with the Raspberry Pi.  I want to keep my brain active since learning another language (spoken.. not programming) is beyond my limitations.  "Limitations are the shackles we bind to ourselves".  Who said that??? - I'm showing my grandpa'dness.

Last night I was googling around all over the place to get my head around how to get a simple LED to light up using the Raspberry Pi.  It doesn't sound hard, and it's probably the first thing you should do.  It's like the Hello World of electronics.

Firstly, I should tell you what my set up is.

  • Raspberry Pi 2
  • Breadboard
  • T-Type GPIO expansion board
  • Ribbon cable to connect the expansion board to the Raspberry Pi.
  • Red LED
  • 470ohm Resistor
  • 3 jumper leads (red, white an black)

Those are the minimum that I found was needed to get this to work.  I'm going to try to explain why it plugged in the way it is, but I want you to take note that I'm learning here.  So it's possible I'm doing something wrong (hopefully I won't electrocute myself).  If you see I'm doing something wrong or don't get it, let me know.  I'm keen to understand this stuff better.

Making sure there's Power and Ground to the Breadboard

I'm making this the first part of this post, because this is what I didn't know and I woke up this morning with an epiphany.

Feel free to click on the above image, to get a closer look.

Firstly, when you plug in the T-type expansion board into the breadboard (with the ribbon), I was under the wrong impression that somehow the left and right side of the board now had power and ground all connected up, under the covers.  That was a wrong assumption.

As you can see, I have a White jumper connected to Pin 1 (3v3 power) and it goes to the + (red) column.  That sends power down that column, so you can plug things into it now.

I also have a Red jumper that connects the Gnd (ground) pin to the - (blue) column. This is what I was missing as I thought I didn't need to do this.

LED

The LED you can pretty much put anywhere, as long as it's not on the same row.  The rows, being the number set of holes.  What I mean, is that your LED can't take up pins D35 and E35.  One row needs to be for the positive (anode) and the other for the negative(cathode).I've put my Red LED with the anode on E33 and the cathode on E34.  So now my row 34 is the negative (or ground) and row 33 is the positive (power).

For those who are learning, like me, the anode (+) is the long leg of an LED and the cathode (-) is the shorter leg.

Resistor

I've read a bunch about how you shouldn't plug the LED directly to the power with a resistor, because it will try to drag in as much power as possible and burn itself out.  I actually did connect it up without a resistor and it worked, but I don't recommend this as I did it while I had no idea what I was doing.  Which I still feel is the case :).

I took the 470 ohm resistor that came with my kit, but you can use a smaller one since we are just dealing with an LED.  One of the ends of the resistor is plugged in to the cathode row.  In the picture, it's plugged into A34.  The other end of the resistor is plugged into the - line (to ground it).

GPIO17 pin

The final electronics piece of the puzzle, is connecting the LED to one of the GPIO pins, because I want to write some code to talk to it.

In the image above, I have a Black Jumper connected to the anode part of the LED (pin C33.. it could also be A33, B3 or D33)  The other end of the jumper is connected to B6 which is the GPIO17 pin.

Code to turn the LED on and off

Since I'm running Raspbian (linux) on the Raspberry Pi, the simplest way to communicate with the pins is using Python.  Now I'm not a Python guru.  I'm learning it as I go, so it's not going to be pretty. 

Turning on the LED

import RPi.GPIO as GPIO

pinNum = 17

GPIO.setmode(GPIO.BCM)

GPIO.setwarning(False)

GPIO.setup(pinNum, GPIO.OUT)

GPIO.output(pinNum, GPIO.HIGH)

Turning off the LED

import RPi.GPIO as GPIO

pinNum = 17

GPIO.setmode(GPIO.BCM)

GPIO.setwarning(False)

GPIO.setup(pinNum, GPIO.OUT)

GPIO.output(pinNum, GPIO.LOW)

Conclusion

I don't think this is too complicated, but like I said, I'm still learning and I could be doing something wrong or describing it incorrectly.  Please let me know if either is true as I want to understand this stuff and I also want to put it in a way for other beginners/newbies like myself to learn it easily.

A little addon to this. I installed Ninja-IDE to write my Python.  It seems pretty good for my needs.  That way, I can write the Python code and it gives me an idea if I totally messed something up, like syntax.  Then I save the files, eg ledON.py and ledOFF.py and I can run them with something like this:

python ledON.py

and

python ledOFF.py

Posted by Vadim Tabakman Wednesday, January 4, 2017 7:58:00 AM Categories: Breadboard GPIO GPIO17 Jumpers LED Ninja-IDE Python Raspberry PI Resistor T-Type Expansion

Comments

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register