Tuesday, July 26, 2016

The "Hello World" circuit with Raspberry - Single LED

Probably the "Hello World" of building a simple circuit with Raspberry is a single LED circuit.  So I decided to give it a try.  Not difficult frankly speaking, just to get all the ingredients together and there are plenty of goods tutorial if you spend a minute to google.

This is the official URL that you can first check it out:

The circuit that I've used is exactly the same as the one you can find from the above URL, except that the "switch" is not a physical one, I used the gpio command to control it.

This is how it looks physically.  I've connected the GPIO pin to my breadboard using the female-to-male jumper cable.  Physical pin 11 is used for +ve and physical pin 6 is the ground pin.

Check out this link about breadboard.  An other things about building a circuit.

Some holes (usually the top and bottom rows) are connected in row and some (usually the middle) are in column.  

I've followed this link and used a 330 ohm resistor.  Check your LED spec to decide the correct resistor.  My LED works fine in a 11mA current circuit so 330 ohm resistor is good for my case.

Also check out the above link for LED.  The LED should have 2 legs, the longer leg is +ve and shorter leg is -ve.

One thing that I've spent quite some time is the pinout.  The BCM and physical board pin numbering is a bit confusing.  Say for my case, I've used physical pin 11, and in BCM numbering it is pin 17.  It will spend you hours to troubleshoot if you don't get it right.

You can use the gpio readall command to print out all its number convention and other details.

Another thing is, your physical GPIO pin 11 will be providing 3.3V power and you have to change its mode to OUT.  You can do it with the gpio command below:

gpio -1 means you are referring to the physical pinout numbering.

gpio -g means you are referring to the BCM pinout numbering.

This is a python script to switch on then off the LED light instead of using the gpio command.  You can find a similar script from the link provided above.  The only difference here is I am using GPIO.BOARD which means I'm referring to the physical pin number 11.

If you want to use the BCM numbering, then you can setmode to GPIO.BCM

Hope it will save you some time from troubleshooting layer 1 problem and to build up your first circuit with Raspberry!

No comments: