User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 3:05 pm

Been using the GPIO this afternoon and after a lot of frustration it seems to me that the wiki page on the GPIO is wrong - or at least wildly innacurate! In particular the nice colour image showing the pin-outs, etc.

So I'm wondering if I've missed some change, somewhere along the line... I know there are lots of hits in the forums here about it, but it's hard to do through all of them!

After a bit of probing and programming, I've come up with this table (and note 9 programmable output pins, not 8!)

1 3v3 * * 5v
2 GPIO * * ?
3 GPIO * * 0v
4 ? * * ?
5 ? * * ?
6 GPIO * * GPIO
7 GPIO * * ?
8 GPIO * * GPIO
9 ? * * GPIO
10 ? * * ?
11 ? * * GPIO
12 ? * * ?
13 ? * * ?


So there are 9 pins there which I can set to output and drive LEDs from. Nice that there's a 9th though, although I fear I may be somewaht overzealous and have programmed one of the other pins to be an output rather than I2C/SPI/Serial...

Even when I compare it to this picture on the design spark article, it's differnt there too (although I suspect that photo was just made up)

So where do I start - which GPIO is GPIO 0, which is 7 or 8? Since others already have stuff connected to the GPIO, what are they doing?

Or what vital update have I missed )-:

Cheers,

Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 3:16 pm

Hi GordonH

I don't have my Pi yet but have been doing a lot of research on it's GPIO in the mean time.

I have also found that there are various "versions" of the pin-outs floating around and don't quite know which is the correct one.

Glad to hear that you are having a go at it.

As regards checking which GPIO is 0 and which is 7 (and all the ones in between), have you thought about writing 1,2,4,8,16……etc etc to the port one at a time?

(or setting only one bit at a time if the port is not seen as an 8 bit port).

This way you will easily be able to tell which is the LSB and the MSB.

Just a thought.

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

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 3:39 pm

Download the schematic, it is the ultimate truth.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 3:41 pm

Dave_G_2 said:


Hi GordonH

I don"t have my Pi yet but have been doing a lot of research on it"s GPIO in the mean time.

I have also found that there are various "versions" of the pin-outs floating around and don"t quite know which is the correct one.

Glad to hear that you are having a go at it.

As regards checking which GPIO is 0 and which is 7 (and all the ones in between), have you thought about writing 1,2,4,8,16……etc etc to the port one at a time?

(or setting only one bit at a time if the port is not seen as an 8 bit port).

This way you will easily be able to tell which is the LSB and the MSB.

Just a thought.


Sure - I have the relationship between GPIO number internally and the pin externally, but I meant how to refer to the 9 IO pins - which is zero and which is 8. The image on the Wiki numbered them from GPIO0 through GPIO7 in what looks like a somewhat haphazard manner - I could simply go 0 to 5 on the left, top to bottom  then 6, 7, 8 and 9 on the right from the bottom up, or from the top down or ...

I'm after a "standard" of one exists, so I could (e.g.) produce some fancy hardware and tell the users to connect it to GPIO 0, 1 and 2 - then they'd know which pin on the connector to connect it to... Unless I've missed something (not unusual for me!) then right now, it's anyones guess...

I suppose I could just invent my own and publish it as a new standard, but who'd adopt it... (And how am I going to find out what the other pins are!)

Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 3:41 pm

mahjongg said:


Download the schematic, it is the ultimate truth.



Actually, that's next on my list of things to do. Ta.

Gordon
--
Gordons projects: https://projects.drogon.net/

GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 4:05 pm

Hi Gordon,

Not sure where the confusion is, the coloured GPIO diagram in the wiki is correct as far as I can tell?

Assuming you have the Pi oriented the correct way around, GPIO header is in the top left corner of the board.  Then looking at that header, referred to as P1 on the board, pin2 is in the top left of P1 and should be 5v.

This makes GPIO 1 on the header as the 6th pin from the left on the top row.

You need to be aware that GPIO 1 on the R-Pi board is actually connected to GPIO 18 on the BCM2835.  So in code what you would consider to be GPIO 1 is actually GPIO 18.

I have been playing with this too and earlier today I posted in a different place on this forum, with some sample code which will hopefully make things a bit easier.

See this link for that post:

http://www.raspberrypi.org/for.....ins/page-2

I hope this helps a bit.

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 4:20 pm

I'm still confused.

See attached pic:

http://www.freeimagehosting.net/6kezm

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

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 4:21 pm

When I did the Python library for GPIO, I abandoned the diagram on the wiki page and just went with pin numbers as per the table. In my mind, pins labeled GPIO 0-7 do not make sense when most other pins also work as GPIO pins. I have tested this with a real RPi.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 4:35 pm

GizmoB73 said:


Hi Gordon,

Not sure where the confusion is, the coloured GPIO diagram in the wiki is correct as far as I can tell?

Assuming you have the Pi oriented the correct way around, GPIO header is in the top left corner of the board.  Then looking at that header, referred to as P1 on the board, pin2 is in the top left of P1 and should be 5v.


I can positively identify the +3.3 (P1) and 2 x +5V pins on the connector


This makes GPIO 1 on the header as the 6th pin from the left on the top row.


Yes, I can ID that as a GPIO pin.


You need to be aware that GPIO 1 on the R-Pi board is actually connected to GPIO 18 on the BCM2835.  So in code what you would consider to be GPIO 1 is actually GPIO 18.


That's fine. Not concerend with that mapping for now.


I have been playing with this too and earlier today I posted in a different place on this forum, with some sample code which will hopefully make things a bit easier.

See this link for that post:

http://www.raspberrypi.org/for.....ins/page-2

I hope this helps a bit.


I've checked it.

What I can work out is the other GPIO pins - so according to the Wiki GPIO0 ough to be adjacent to GPIO1 - I check that pin, and it is a GPIO pin (ie. I can make an LED flash) so far so good. Then GPIO7 on the Wiki - I see no activity on that at all.. but then I see activity on the I2C pins - probably because I've programmed them as outputs - may not be the best thing to do now I'm looking deeper.

Actually, I think it's that pin that's thrown me off - as that's the one I started with - all the others seem OK - just don't use GPIO7 on the connector (GPIO4 on the chip - marked GPIO_GCLK on the schematic) In that case I can use 7 IO pins - which might do for now.

Cheers,

Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 4:40 pm

croston said:


When I did the Python library for GPIO, I abandoned the diagram on the wiki page and just went with pin numbers as per the table. In my mind, pins labeled GPIO 0-7 do not make sense when most other pins also work as GPIO pins. I have tested this with a real RPi.



I think I have it now, just no time to read the actual chip datasheet - maybe on the train tomorow - I suspect that GPIO7 is programmed in some ALT mode initially...

I see your in Blackpool - popping down to ucubed on Saturday? (yea, I know it's a bit far to Manchester, but I'm coming up from Devon!)

Gordon
--
Gordons projects: https://projects.drogon.net/

hippy
Posts: 5345
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 4:48 pm

GizmoB73 said:

You need to be aware that GPIO 1 on the R-Pi board is actually connected to GPIO 18 on the BCM2835.  So in code what you would consider to be GPIO 1 is actually GPIO 18.
That's inevitably going to cause some confusion in my opinion as it becomes hard to tell what "GPIO 1" refers to; GPIO 1 or GPIO 18.

It's perhaps clearer to those who can understand schematics and remeber to look at them but it's going to confuse people who have the GPIO label and a SET_GPIO_PIN(n) macro that has to use 18 instead of 1, 22 instead of 2.

And even more confusing when some bright spark decides to add the mapping inside their macro; "Shouldn't that SET_GPIO_PIN(1) be SET_GPIO_PIN(18) ? - No, that 1 sets GPIO 18 which comes out on the GPIO 1 pin.

I'd have personally started with pin B3 of the chip, "GPIO18", labelled the signal to match "GPIO.GEN18", and then labelled the GPIO header pin "GPIO18" or "GPIO.GEN18".

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:02 pm

@hippy

I completely agree and can see plenty of people being caught out by it.

Why was it ever done like that?

Considering that many thousands of Pis have been manufactured that way, I don't see a way for the designers to change it now even if they wanted to.

I think it will forever and a day be known as the dreaded "GPIO_18" bug.

hippy
Posts: 5345
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:14 pm

Dave_G_2 said:

Why was it ever done like that?
I can understand why; "User exposed GPIO 1 comes from physical chip GPIO 18 pin", end of story, simple enough. Standard practice for hardware designers I would suspect, and not confusing at all to people familiar with such practice.

It's the dropping of the important prefixes and creating two classes of "GPIO" which leads to the confusion, ie the decision to label the GPIO header pins as "GPIO x" which is also used with a different meaning on the physical chip, and within software.

I'd suggest naming the GPIO header to match the physical pin GPIO, or at least naming the GPIO pins differently, for example, "I/O 1" ( which is GPIO 18 ), but I suspect people will still call that "GPIO 1" from habit.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:25 pm

hippy said:


Dave_G_2 said:


Why was it ever done like that?


I can understand why; "User exposed GPIO 1 comes from physical chip GPIO 18 pin", end of story, simple enough. Standard practice for hardware designers I would suspect, and not confusing at all to people familiar with such practice.

It's the dropping of the important prefixes and creating two classes of "GPIO" which leads to the confusion, ie the decision to label the GPIO header pins as "GPIO x" which is also used with a different meaning on the physical chip, and within software.

I'd suggest naming the GPIO header to match the physical pin GPIO, or at least naming the GPIO pins differently, for example, "I/O 1" ( which is GPIO 18 ), but I suspect people will still call that "GPIO 1" from habit.



And do you start at 1 or 0... I've just written an arduino compatable "Wiring" type of library (sort of) and to me, pin0 is GPIO0 on the header or GEN0/BCM_GPIO17 on the schematic... Oh well! Arduinos start at 0 (although 0 & 1 are almost always the rx/tx serial port) I wish I could get GPIO7/GCLK/BCM_GPIO4

Anyone got the runes handy to turn GPIO1/BCM_GPIO18 into PWM mode?

Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:30 pm

Not to mention the errors (as I see it)  in the peripherals datasheet.

See page 96 (description of the bits in the GPLEVn register).

See here:

http://www.freeimagehosting.net/diwkk

hippy
Posts: 5345
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:34 pm

Dave_G_2 said:

Considering that many thousands of Pis have been manufactured that way, I don't see a way for the designers to change it now even if they wanted to.
The boards themselves aren't silked screened with GPIO header identification, so it would only need the Wiki diagrams etc updating, and ideally the schematics. It would only really be a documentation change.

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:45 pm

@GordonH

For PWM, something like this?

http://www.freeimagehosting.net/yzt5l

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:51 pm

Dave_G_2 said:


@GordonH

For PWM, something like this?

http://www.freeimagehosting.net/yzt5l



Yes, thanks. I really need to read the chip manual at some point! Other things happenig too fast right now. Haven't had it a week yet... Tonights task is integrate the GPIO into my BASIC in the same way it currently talks to an arduino... Essentially Arduino's Wiring library, although I might skip PWM for now!

Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 5:58 pm

No prob.

Please let us know how you get on with the BASIC.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 7:44 pm

Dave_G_2 said:


No prob.

Please let us know how you get on with the BASIC.



Well, I've integrated the GPIO into the BASIC - well, pin mode setting input or output and DigitalWrite (need to read up on how to read the damn things!) and it's working fine. I have a row of 8 LEDs swinging back & forth cylon/nightrider style...

Still can't get GPIO7 to work, using SDA0 (BCM_GPIO0) instead. Seems OK for now.

Just hacked my arduino test - I'm now reading a pot on the arduino and using it to set the LEDs on the RPI (as well as the LEDs on my Arduino test board)

Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
Dave_G_2
Posts: 196
Joined: Sat Apr 14, 2012 7:04 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 8:18 pm

@GordonH

Nice one with the BASIC.

B.T.W. don't know if you've seen this on the raspberry.org main page:

(I just saw it a few minutes ago).

"Note: developers of expansion boards should not rely on the connection of expansion connector pins 9, 14, 20 and 25 to GND, pin 4 to 5V or pin 17 to 3V3 and should instead treat these pins as DNC (do not connect). They may be used to expose additional GPIO lines on a subsequent revision of the board."

I know that the supply and grounds don't make much diffs to your software, but best keep an eye on this for the possible addition of new GPIOs which might affect your code.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 9:13 pm

Dave_G_2 said:


@GordonH

Nice one with the BASIC.

B.T.W. don"t know if you"ve seen this on the raspberry.org main page:

(I just saw it a few minutes ago).

"Note: developers of expansion boards should not rely on the connection of expansion connector pins 9, 14, 20 and 25 to GND, pin 4 to 5V or pin 17 to 3V3 and should instead treat these pins as DNC (do not connect). They may be used to expose additional GPIO lines on a subsequent revision of the board."

I know that the supply and grounds don't make much diffs to your software, but best keep an eye on this for the possible addition of new GPIOs which might affect your code.



Won't affect the code! However I'm not using any other pins - not even the ground one right now as I'm using spare space on a breadboard with an Arduino on it and ground is carried via the USB...

Gordon
--
Gordons projects: https://projects.drogon.net/

ADAMPOKE111
Posts: 62
Joined: Wed Mar 07, 2012 6:38 pm

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 10:02 pm

Download the schematic, it is the ultimate truth.

Yeah, The schematic is not a lie... *cough* portal 2 the cake is a lie!

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO - Wiki wrong?

Thu Apr 26, 2012 10:16 pm

ADAMPOKE111 said:


Download the schematic, it is the ultimate truth.

Yeah, The schematic is not a lie... *cough* portal 2 the cake is a lie!



I think we're all sorted now - I was initially thrown by starting at GPIO 7 which doesn't appear to work (at least on my Pi - anyone?) I'm suspecting it has to be re-programmed to be used as genera purpose.

Also just realised I posted this in the Absolute Beginners forum rather than troubleshooting... Ah well!

So I'm all happy now - even using the 2 I2C pins as GP IO - handy that they've got a pull-up fitted - makes it easy to stick a switch on them to short to ground...

Enough for one night!

Cheers,

Gordon
--
Gordons projects: https://projects.drogon.net/

GizmoB73
Posts: 80
Joined: Fri Jan 27, 2012 12:51 pm

Re: GPIO - Wiki wrong?

Fri Apr 27, 2012 8:38 am

GordonH said:

I think we're all sorted now - I was initially thrown by starting at GPIO 7 which doesn't appear to work (at least on my Pi - anyone?) I'm suspecting it has to be re-programmed to be used as genera purpose.

If when you are referring to GPIO 7, what you mean is P1-07 then mine works when I refer to it as GPIO4 on the BCM2835.  I have had it happily switching an LED on and off.

Return to “Beginners”