Dapa
Posts: 44
Joined: Sat Jan 21, 2012 7:02 pm

Problem lighting LED on GPIO pins

Wed May 23, 2012 12:17 pm

I’m trying out the basic example of lighting an LED from the GPIO pins. I’ve got a circuit ready to go, but for the moment I’m having problems switching a voltage between two of the pins. I’m following this guide, which uses Python to turn an LED on and off :-
http://www.doctormonk.com/2012/05/gpio- ... slice.html

The only pre-requisite is that because I’m using a double connector to the pins, the two pins need to be adjacent.
With this in mind, my experiment is using P1-01 (3v3 power) => P1-03 (GPIO 0?). I’m trying to measure a change of voltage across these pins. I can get the commands GPIO.setup(11, GPIO.OUT) and GPIO.output(11, True) to run without complaint, but I’m not getting any volts. Is there anything else I need to consider? Does 12C0 SDA need to be reconfigured beforehand to become GPIO 0? Can I use the ground pin in place of 3v3?

User avatar
croston
Posts: 705
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 12:26 pm

The code you gave switches pin 11 on the RPi board. The GPIO nn notation on the wiki is very confusing which is why the python module uses board pin numbers.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12665
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 12:31 pm

Not sure what you are trying to do here, as the link doesn't work.

The GPIO pins can drive a (high efficiency) LED with a few mA, either to ground or from 3V3. Obviously you will need a current limitation resistor (of a few hundred ohms) in series with the LED.
The "drive strength" of a GPIO can be programmed, so that can be a factor.
If you are trying to drive a bi-color led (two LEDs anti-parallel) in between two GPIO pins (so you can determine the direction of the current flow), then yes that is possible too, with driving one output high and the other low.

If you are using a GPIO that is assigned a "special fuction", the pin will be programmed as default for that special function, (I2C, SPI, UART etc) and if you want it to function as a normal GPIO you need to override the default setting.

Dapa
Posts: 44
Joined: Sat Jan 21, 2012 7:02 pm

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 12:33 pm

croston wrote:The code you gave switches pin 11 on the RPi board. The GPIO nn notation on the wiki is very confusing which is why the python module uses board pin numbers.
There does seem to be a fair amount of confusion on the exact references, but this text from the article linked above seems suggest the library 11 switches GIPO 0?

Code: Select all

You may have noticed that the LED is connected to pin GPIO0 and not 11 as we are using in Python. The library uses different pin numbers to the names on the Pi. I'm not sure why. But anyway, I mapped a few of them as shown below.

library name     Pi name
11               0
12               1
13               2

Dapa
Posts: 44
Joined: Sat Jan 21, 2012 7:02 pm

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 12:38 pm

mahjongg wrote:Not sure what you are trying to do here, as the link doesn't work.

The GPIO pins can drive a (high efficiency) LED with a few mA, either to ground or from 3V3. Obviously you will need a current limitation resistor (of a few hundred ohms) in series with the LED.
The "drive strength" of a GPIO can be programmed, so that can be a factor.
If you are trying to drive a bi-color led (two LEDs anti-parallel) in between two GPIO pins (so you can determine the direction of the current flow), then yes that is possible too, with driving one output high and the other low.

If you are using a GPIO that is assigned a "special fuction", the pin will be programmed as default for that special function, (I2C, SPI, UART etc) and if you want it to function as a normal GPIO you need to override the default setting.
Thanks for the advice. I have a circuit with a single, normal LED, with an appropriate resister. How does one override the default function to use GPIO 0? I did search for any guide to this, but drew a blank.

User avatar
croston
Posts: 705
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:07 pm

Just use the python library and it will operate as a GPIO pin, regardless of any special function that the pin is also capable of.

Dapa
Posts: 44
Joined: Sat Jan 21, 2012 7:02 pm

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:13 pm

croston wrote:Just use the python library and it will operate as a GPIO pin, regardless of any special function that the pin is also capable of.
Is that this library? http://pypi.python.org/pypi/RPi.GPIO

As that's what I currently have installed, along with using these commands in Python :-

Code: Select all

import RPi.GPIO as GPIO
GPIO.setup(11, GPIO.OUT)


Which, everything being equal, should switch a supply between 3v3 power and GPIO 0?

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:15 pm

All this discussion about GPIO pins is double Dutch to me. All the postings assume the reader knows at least something about the subject. Can someone point me to a real introduction to the subject; perhaps aimed at Primary school level pupils being introduced to the pins for the first time?

domesday
Posts: 258
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:23 pm

grumpyoldgit wrote:All this discussion about GPIO pins is double Dutch to me. All the postings assume the reader knows at least something about the subject. Can someone point me to a real introduction to the subject; perhaps aimed at Primary school level pupils being introduced to the pins for the first time?
There will be an introduction article in the next issue of the MagPi magazine, you can read some of it by looking at the draft copy http://issuu.com/themagpi/docs/issue2draft

As for the original post the WIKI is a nightmare of confusion, if you see the thread titled GPIO 0 in this forum you will see what I mean. But basically if you are using the python library then the number relates to the pin number, ignore any other numbers. So if you set 11 as an output it is literally pin 11 on the header.

Dapa
Posts: 44
Joined: Sat Jan 21, 2012 7:02 pm

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:39 pm

domesday wrote: As for the original post the WIKI is a nightmare of confusion, if you see the thread titled GPIO 0 in this forum you will see what I mean. But basically if you are using the python library then the number relates to the pin number, ignore any other numbers. So if you set 11 as an output it is literally pin 11 on the header.
Thank you - I have used 3 as the value passed to the function and we have 3.25v across the pins now :D

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:45 pm

I don't know who wrote the Python GPIO library, but it is a bad idea to refer to 'board' pins or even 'package' pins. The pins on a connector will change from board to board.
Package pins can change too but not as frequent as board pins. However you will see that manufacturers are more and more re-using existing silicon IP. So the same internal registers will refer to the same set of I/O pins but they may be on different package pins. (See all of the micro controllers: PIC, ATMel, etc.) What changes the least is the register set which controls the pins and you will find those registers will refer to the pins always with the same name (In this case GPIO0...GPIOn).
I strongly suggest to change the Python library ASAP to use the GPIO names from the data sheet to follow the above 'rule of best practice'.

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: Problem lighting LED on GPIO pins

Wed May 23, 2012 1:56 pm

domesday wrote:
grumpyoldgit wrote:All this discussion about GPIO pins is double Dutch to me. All the postings assume the reader knows at least something about the subject. Can someone point me to a real introduction to the subject; perhaps aimed at Primary school level pupils being introduced to the pins for the first time?
There will be an introduction article in the next issue of the MagPi magazine, you can read some of it by looking at the draft copy http://issuu.com/themagpi/docs/issue2draft

As for the original post the WIKI is a nightmare of confusion, if you see the thread titled GPIO 0 in this forum you will see what I mean. But basically if you are using the python library then the number relates to the pin number, ignore any other numbers. So if you set 11 as an output it is literally pin 11 on the header.
Thanks for that. I've subscribed so I don't miss anything. There is so much to bookmark at the moment!

DavidMS
Posts: 139
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: Problem lighting LED on GPIO pins

Sun Jun 03, 2012 9:03 am

Does anyone know what happened to the GPIO / Robot article in Magpi - it was cut down to a single introduction page in the final version ? - kicking myself for not downloading the draft
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

domesday
Posts: 258
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK

Re: Problem lighting LED on GPIO pins

Sun Jun 03, 2012 9:12 am

Which article do you mean, when I look at http://issuu.com/themagpi/docs/the_magpi_issue_2_final there is a 5 page article about interfacing.

DavidMS
Posts: 139
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: Problem lighting LED on GPIO pins

Mon Jun 04, 2012 8:07 am

Yes, you are correct. I suspect the learning point here is that it is better not to try downloading things when you have had almost no sleep the night before - I 'might' have downloaded issue 1 (again) in error and not noticed......
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

User avatar
Grumpy Mike
Posts: 931
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Problem lighting LED on GPIO pins

Sat Jun 09, 2012 11:07 am

I have just posted about a buffer board I made that will light LEDs.
The code is in C thought.
http://www.thebox.myzen.co.uk/Raspberry ... Board.html

DavidMS
Posts: 139
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: Problem lighting LED on GPIO pins

Mon Jun 11, 2012 9:55 pm

After a couple of hours going around in circles last night I managed to get some LED's to flash, the real pain was not the GPIO but trying to workout the permissions so Python would run RPi.GPIO correctly.

And here is the picture posted by my wife on her blog http://www.cd-vision.co.uk/?page_id=207, I used the ULN2003 driver chip to isolate the board ports as suggested in Grumpy Mike's last post.
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Problem lighting LED on GPIO pins

Wed Jun 13, 2012 5:55 pm

DavidMS wrote:After a couple of hours going around in circles last night I managed to get some LED's to flash, the real pain was not the GPIO but trying to workout the permissions so Python would run RPi.GPIO correctly.

And here is the picture posted by my wife on her blog http://www.cd-vision.co.uk/?page_id=207, I used the ULN2003 driver chip to isolate the board ports as suggested in Grumpy Mike's last post.
I'm guessing you mean you had to use sudo to run your stuff, or did you find a way to let the basic user run it?
Dear forum: Play nice ;-)

DavidMS
Posts: 139
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: Problem lighting LED on GPIO pins

Wed Jun 13, 2012 10:10 pm

Yes I used Sudo and sorry I have not found any other way to run it - it is even harder with the new alpha image as the permissions seem to be setup differently
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

Return to “Interfacing (DSI, CSI, I2C, etc.)”