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

GPIO 0

Sat May 19, 2012 2:49 pm

Am I right in thinking that P1-11 (GPIO 00) has a permanent 1.8KΩ pull-up resistor on the Pi ?

If that is the case that means when using it as an input it will always be read as high until it is pulled low.
That seems to suggest that by convention it would make sense to use a pull-up design on all GPIOs so they all default to high, there even seems to be the option of enabling an on-chip pull-up resistor for each GPIO.

The problem then is that with GPIO 00 and 01 having the permanent pull-up resistors in place makes them impractical without using a buffer as we can not insert a series current limiting resistor because of the low 1.8KΩ pull-up resistor. We would have to use such a low value resistor to bring the line level to below the threshold level. If my calculations are correct the max resistor we could reasonably get away with is about 800Ω.

Does anybody know the value of the on-chip pull-up resistors ?

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIO 0

Sat May 19, 2012 5:49 pm

Found this thread:
http://www.raspberrypi.org/phpBB3/viewt ... f=5&t=4876

And this wiki:
http://elinux.org/RPi_Low-level_peripherals

On the subject. But I'm still at a loss too -
The diagram on that wiki lists pins "GPIO 0" to "GPIO 7", but the table, based on the chipset, lists pins 3 & 5 as being "GPIO01" and "GPIO02". On the connector, these two are marked as "SDA0" and "SCL0", and designated as I2C connections with the 1K8 pull-up resistors.

And yet Gert, in his posting, refers to them as "/sys/class/gpio/gpio0", so just what are they?

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

Re: GPIO 0

Sat May 19, 2012 8:47 pm

The WIKI authors started numbering the GPIOs on the connector without knowing about the 'real' device numbering. So there are now two numbering schemes out there cause a great amount of confusion. I always use the number taken from the data sheet. you will find that numbering also the Gertboard silkscreen.

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

Re: GPIO 0

Sat May 19, 2012 9:58 pm

ou are right the Wiki is very confusing there seems to be 3 different numbers for the same Pin.

There is the physical Pin number i.e P1-03
The pin has two possible labels as well SDA0 and GPIO0

So in fact am I correct in thinking that Pins 03 and 05 are the ones with a permanent 1k8Ω Pull-up.

Pin 11 on the other hand labeled as GPIO but in fact GPIO17 from the Broadcom datasheet has no pull-up ?

So for the sake of Clarity are all of the following pins floating as default, and can be set as pul-up and pull-down with a register ?

P1-1 GPIO 0 - (AKA BCM2835 GPIO17)
P1-12 GPIO 1 - (AKA BCM2835 GPIO18)
P1-13 GPIO 2 - (AKA BCM2835 GPIO21)
P1-15 GPIO 3 - (AKA BCM2835 GPIO22)
P1-16 GPIO 4 - (AKA BCM2835 GPIO23)
P1-18 GPIO 5 - (AKA BCM2835 GPIO24)
P1-22 GPIO 6 - (AKA BCM2835 GPIO25)
P1-7 GPIO 7 - (AKA BCM2835 GPIO04)

May I suggest to stop the confusion perhaps the labels should use a different naming scheme such as D0-D7 as used on the old BBC Micro user port or maybe just shorten it to IO0-IO7 so that the GPIO name is reserved for the official BCM2835 numbers ?

I think it is important that we find a good solution to the problem because if people like us who have experience in interfacing get confused then a young person trying to learn is going to get really flummoxed.

By the way, unless the labels have changed the Gertboard is even more confusing as the P1-22 seems to be labeled GP23, so it doesn't seem to match any of the numbers on the WIKI. :?

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

Re: GPIO 0

Sun May 20, 2012 9:55 pm

domesday wrote:ou are right the Wiki is very confusing there seems to be 3 different numbers for the same Pin.

......
By the way, unless the labels have changed the Gertboard is even more confusing as the P1-22 seems to be labeled GP23, so it doesn't seem to match any of the numbers on the WIKI. :?
A printed circuit board has only limited space. So I had to short the names, making then fit in the space available but still tried to make them understandable.
The reason why I prefer the data sheet numbers is simple: Any I/O you want to do, you need to know the real physical pin that you drive. The registers are laid out linear so the control for pin n are accessed as: 1<<n for pins 0-31 and 1<<(n-32) for all other pins. None of the other pin numbers map on that.

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIO 0

Sun May 20, 2012 11:11 pm

So, from that Wiki, we should be ignoring all the labelling except for the pin number and the GPIOnn reference in the 'Alternative Functions' column?

So Pin P1-03 is GPIO00, P1-07 is GPIO04 etc.? And that's the way the low-level commands like 'cat /sys/class/gpio/gpio0/value' understand it?

Is that right?

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

Re: GPIO 0

Sun May 20, 2012 11:33 pm

Perhaps I should be putting this in the Gertboard forum but it would seem there are already 3 different ways the GPIO's are labelled and the Gertboard introduces a 4th. Admittedly I am looking at an old PCB layout but this Is what I can see ...

Code: Select all

Raspberry Pi Pin# :         WIKI:                Broadcom SOC           Gertboard
---------------------------------------------------------------------------------
P1-11                       GPIO 0               GPIO17                 GP17
P1-12                       GPIO 1               GPIO18                 GP18
P1-13                       GPIO 2               GPIO21                 GP19
P1-15                       GPIO 3               GPIO22                 GP20
P1-16                       GPIO 4               GPIO23                 GP21 
P1-18                       GPIO 5               GPIO24                 GP22
P1-22                       GPIO 6               GPIO25                 GP23
P1-7                        GPIO 7               GPIO04                 GP4

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

Re: GPIO 0

Mon May 21, 2012 7:19 am

domesday wrote:Perhaps I should be putting this in the Gertboard forum but it would seem there are already 3 different ways the GPIO's are labelled and the Gertboard introduces a 4th. Admittedly I am looking at an old PCB layout but this Is what I can see ...

Code: Select all

Raspberry Pi Pin# :         WIKI:                Broadcom SOC           Gertboard
---------------------------------------------------------------------------------
P1-11                       GPIO 0               GPIO17                 GP17
P1-12                       GPIO 1               GPIO18                 GP18
P1-13                       GPIO 2               GPIO21                 GP19
P1-15                       GPIO 3               GPIO22                 GP20
P1-16                       GPIO 4               GPIO23                 GP21 
P1-18                       GPIO 5               GPIO24                 GP22
P1-22                       GPIO 6               GPIO25                 GP23
P1-7                        GPIO 7               GPIO04                 GP4
Sorry but that was an old version of the board (And it was wrong) The Gertboard which comes out (rev 3) follows the Broadcom SOC number one-on-one.
What happened is that I was involved in the first stages of the Raspberry-Pi board design and I had the schematics of the first revisions. Then a number of late changes where made to make the layout easier. But I never got those. So my first board design was based on an old schematic.

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

Re: GPIO 0

Mon May 21, 2012 8:29 am

Gert van Loo wrote:Sorry but that was an old version of the board (And it was wrong)
Ah that is a relief. I'm not sure who would be responsible for the documentation/wiki but I think where the big confusion arises is the way that the WIKI and the Broadcom numbers both start with GPIO. I think if the WIKI names were changed it would solve a lot of confusion, for example ...

Code: Select all

Raspberry Pi Pin# :         WIKI:            Broadcom SOC
---------------------------------------------------------
P1-11                       D0               GPIO17
P1-12                       D1               GPIO18
P1-13                       D2               GPIO21
P1-15                       D3               GPIO22
P1-16                       D4               GPIO23 
P1-18                       D5               GPIO24
P1-22                       D6               GPIO25
P1-7                        D7               GPIO04
It is the conflict of both the WIKI and Broadcom names starting with GPIO that is causing the most confusion for people.

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIO 0

Mon May 21, 2012 9:41 am

Why does the Wiki even need to renumber the GPIO lines?
If they're not referred to by those 8 data-line numbers anywhere in the official documentation or at the API level then why do they exist at all?
domesday, if you get it, could you please fix the Wiki?

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

Re: GPIO 0

Mon May 21, 2012 11:09 am

I think the reason the pins are renumbered is to describe the default function of the pins.

In the case of the SPI pins for example it makes more sense to label pin 25 SPI CE1 than it does GPIO08. The idea that you have essentially 4 groups of signals 'UART, 8bit PIO, SPI & I2C)

Perhaps what it should be is like this ...

Code: Select all

Raspberry Pi Pin# :       Signal:                Default Function
-----------------------------------------------------------------
P1-1                      3.3V                   3.3V DC Power
P1-2                      5V                     5V DC Power
P1-3                      GPIO00                 I2C0_SDA
P1-4                      --                     No Connection
P1-5                      GPIO01                 I2C0_SCL
P1-6                      0V                     0V
P1-7                      GPIO04                 D7
P1-8                      GPIO14                 UART TX
P1-9                      --                     No Connection
P1-10                     GPIO15                 UART RX
P1-11                     GPIO17                 D0
P1-12                     GPIO18                 D1
P1-13                     GPIO21                 D2
P1-14                     --                     No Connection
P1-15                     GPIO22                 D3
P1-16                     GPIO23                 D4
P1-17                     --                     No Connection
P1-18                     GPIO24                 D5
P1-19                     GPIO10                 SPI MOSI
P1-20                     --                     No Connection
P1-21                     GPIO09                 SPI MISO
P1-22                     GPIO25                 D6
P1-23                     GPIO11                 SPI SCLK
P1-24                     GPIO08                 SPI CE0 N
P1-25                     --                     No Connection
P1-26                     GPIO07                 SPI CE1 N
I think the key here though is to STOP using the GPIO label in two places.

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIO 0

Thu May 24, 2012 11:20 am

Where do these 'default behaviours' come from, anyway? Who needs them? Every example I've seen sets the pin modes explicitly, which I seriously hope is considered best practise.

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

Re: GPIO 0

Thu May 24, 2012 1:09 pm

New release of Python module now allows to you to use both board pin numbers and Broadcom GPIO numbers.

Michael
Posts: 340
Joined: Sat Jul 30, 2011 6:05 pm

Re: GPIO 0

Sun Jun 03, 2012 6:33 pm

domesday wrote:Perhaps I should be putting this in the Gertboard forum but it would seem there are already 3 different ways the GPIO's are labelled and the Gertboard introduces a 4th. Admittedly I am looking at an old PCB layout but this Is what I can see ...

Code: Select all

Raspberry Pi Pin# :         WIKI:                Broadcom SOC           Gertboard
---------------------------------------------------------------------------------
P1-11                       GPIO 0               GPIO17                 GP17
P1-12                       GPIO 1               GPIO18                 GP18
P1-13                       GPIO 2               GPIO21                 GP19
P1-15                       GPIO 3               GPIO22                 GP20
P1-16                       GPIO 4               GPIO23                 GP21 
P1-18                       GPIO 5               GPIO24                 GP22
P1-22                       GPIO 6               GPIO25                 GP23
P1-7                        GPIO 7               GPIO04                 GP4

I thought I had scrubbed the wiki pages to remove the names in the wiki column of the table above, so that only the Raspberry Pi Pin# and Broadcom SOC names are used. Additionally, where the default function is not a GPIO fuction but something else (SPI, I2C or UART) then that name is used instead. That is certainly what is in the pin diagram and the table towards the top of this document.

If anyone has suggestions to make this complicated feature clearer in documentation, please do comment.

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

Re: GPIO 0

Sat Jun 09, 2012 6:57 am

Michael wrote:
domesday wrote: If anyone has suggestions to make this complicated feature clearer in documentation, please do comment.
I would forget about the alternative functions and just use GPIO numbers. You only need the alternative functions names when you want to use that function, then a simple table listing what these functions are will suffice, just like they do in the data sheet.
I believe the GPIO numbers are the fundamental anchor in interfacing.
See my page on it here:- http://www.thebox.myzen.co.uk/Raspberry ... Board.html

Michael
Posts: 340
Joined: Sat Jul 30, 2011 6:05 pm

Re: GPIO 0

Sat Jun 09, 2012 9:04 am

I would forget about the alternative functions and just use GPIO numbers. You only need the alternative functions names when you want to use that function.
I think that would be confusing, as GPIO is the alternative function in the case of, for instance, pins 3 & 5 (default function: I2C) and pins 8 & 10 (default function: uart serial).

However, I could possibly be pursuaded. What is the general opinion from others?

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

Re: GPIO 0

Sat Jun 09, 2012 10:02 am

I think now the WIKI illustration has been changed that has resolved the biggest confusion where the prefix GPIO was being used with two numbering schemes so now we are left with a much clearer table.

It does however leave one slightly confusing thing for the less technical user, that is by using the Braodcom internal numbering scheme the numbers are seemingly random. GPIO17,18,21,22,23,24,25,04.

The majority of users are likely to leave the default functions unchanged and it seems very sensible to do what the WIKI authors were trying to do in the first place that is basically have an 8bit parallel IO. It is possible that in future revisions of the Raspberry Pi that the signals from the Broadcom chip that are used to make up this set of 8 GPIO's may change from the ones used but the pin assignment stay the same. As a result it would seem a good idea to have a set of identifiers that are abstracted from the internal hardware workings. That is why I suggested using the labels D0-D7 that way if for example in the next revision GPIO04 is replaced with GPIO19 to drive pin P1-7 then the driver could deal with the change rather than the user having to change for example their python program. So in my python program I would be able to use something like 'input = GPIO.input(D0)' and regardless of how any internal signals have changed in the PCB layout my program will always work as the driver will re-direct that request to whatever the underlying signal is.

I feel this should be the default behaviour to provide consistency across future revisions of the Pi for the less technical user. The more technical user would be able to do something like 'GPIO.setmode(GPIO.BCM)' to access the RAW GPIO numbers to re-configure their functions.

Michael
Posts: 340
Joined: Sat Jul 30, 2011 6:05 pm

Re: GPIO 0

Sat Jun 09, 2012 10:21 am

It is possible that in future revisions of the Raspberry Pi that the signals from the Broadcom chip that are used to make up this set of 8 GPIO's may change from the ones used but the pin assignment stay the same... That is why I suggested using the labels D0-D7
Arguably, one could achieve something similar by instead using the actual pin name:

input = GPIO.input(P1_13);

However, I think it is pertty unlikely that the designers will change the function of the existing, in-use, pins.
It does however leave one slightly confusing thing for the less technical user, that is by using the Braodcom internal numbering scheme the numbers are seemingly random. GPIO17,18,21,22,23,24,25,04.
Actually, I quite like that. It leads to the questions, why do the GPIOs have those numbers, and what happened to the other ones? This then leads to a better understanding of the relationship between the Broadcom SoC and its integration to the Raspberry Pi board; and to the alternative functions that each pin supports. Curious users will then discover that some of the other pins can be re-configured to provide additional GPIO - up to 17 of them. I can certainly picture the "Aha!" moment the 8-year-old me would have had following that particular rabbit hole down :D Afterall, aren't self-education and a better understanding of computer technology two of the key goals of the project ?

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

Re: GPIO 0

Sat Jun 09, 2012 10:28 am

domesday wrote:Braodcom internal numbering scheme the numbers are seemingly random. GPIO17,18,21,22,23,24,25,04.

The majority of users are likely to leave the default functions unchanged
I would strongly disagree with this. Even if you do use the default functions what is wrong with saying that the I2C pin is on GPIO pins 0 and 1?
The pin numbering is not random, what is random is the order they were tracked out by the Pi's PCB designer. There are understandable reasons for this:-
1) Some GPIO pins are used in the normal operation of the Pi, like the SD card interface.
2) It is tricky if not imposable to track all the pins out on a low cost board.
. As a result it would seem a good idea to have a set of identifiers that are abstracted from the internal hardware workings. That is why I suggested using the labels D0-D7 that way if for example in the next revision GPIO04 is replaced with GPIO19 to drive pin P1-7 then the driver could deal with the change rather than the user having to change for example their python program.
No the point is that GPIO 04 is always going to be GPIO 04 no matter what anyone does with PCB tracking and the pins. It might be on a new board revision GPIO 04 appears on a different pin but you would not have to change any software and you would not have to change any library. You just need to change the pin you have wired your interface to, and as the connector is likely to change you are going to have to do that anyway. If the connector is the same you say to a beginner on issue 1 the pin is this one on issue 2 it is that one.

A level of abstraction like you propose is more confusing to beginners for three reasons:-
1) It is another thing to learn.
2) Not everyone is going to use that convention and that IS confusing.
3) It is arbitrary with no logic behind the abstraction. A beginner will ask, "how can I work out that GPIO04 is D0"?

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

Re: GPIO 0

Sat Jun 09, 2012 10:36 am

Michael wrote:Afterall, aren't self-education and a better understanding of computer technology two of the key goals of the project ?
Yes, but there does need to be a certain amount of simplicity that makes it accessible in the first instance. I can't tell you the number of technologies that I have given up on because the learning curve is to steep to get started and yet others that I have got going with quickly only to later dismantle them and get deep in to the workings to fully understand them. I learnt to understand binary using the user port on a BBC micro, it is so easy to explain that computers start with the number zero when you have a set of parallel IO pins marked 0-7 and attach some LEDs to them to illustrate how binary counting works.

So you start out sending the decimal number 3 to the IO port and watch the first two LEDs light up, really simple. Then once that has grabbed your attention and you understand the binary system you can start addressing each individual LED by controlling the state of HIGH or LOW for each data line. Finally you dig deeper to find that these data lines are in fact nothing more than memory addresses and so you can start accessing them at a low level in machine code by flipping that address location in machine code.

The point being there has to be an easy way in, I don't think that is how it will end up though as Raspberry Pi is designed by engineers. Engineers always find it difficult to see how complex something is to people who have yet to learn the basics.

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

Re: GPIO 0

Sat Jun 09, 2012 11:16 am

Engineers always find it difficult to see how complex something is to people who have yet to learn the basics.
That might be true, but I am an engineer and an educator. I also had a great deal of experience with the BBC computer, I wrote the Body Build and Run the Rsic articles. I have got years of experience in teaching people how to do things. I have found that levels of abstraction designed to make things easy only confuse beginners. They disrupt the confidence of a beginner.
Using real GPIO numbers is not a steep learning curve, just the opposite.

User avatar
rew
Posts: 435
Joined: Fri Aug 26, 2011 3:25 pm

Re: GPIO 0

Sat Jun 09, 2012 7:39 pm

Grumpy Mike wrote: Even if you do use the default functions what is wrong with saying that the I2C pin is on GPIO pins 0 and 1?
What is "default"? When the 'PI boots up all pins like SDA, SCL, MOSI, MISO are configured as inputs. The Uart pins are changed by the serial driver to do what they are supposed to do (according to the uart driver).
Check out our raspberry pi addons: https://www.bitwizard.nl/shop/

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

Re: GPIO 0

Sat Jun 09, 2012 9:09 pm

rew wrote:What is "default"?
Default is the GPIO register, it is the background over which other functions are switched in over the top. It is what is used when there are no alternative functions.
The Broadcom data sheet say that, that is why all the other functions are referred to as alternative functions. The opposite of alternative IS default.

Michael
Posts: 340
Joined: Sat Jul 30, 2011 6:05 pm

Re: GPIO 0

Sat Jun 09, 2012 9:25 pm

Grumpy Mike wrote:
rew wrote:What is "default"?
Default is the GPIO register, it is the background over which other functions are switched in over the top. It is what is used when there are no alternative functions.
The Broadcom data sheet say that, that is why all the other functions are referred to as alternative functions. The opposite of alternative IS default.

I would suggest that default is what the OS configures the pin to be by default. What the datasheet says is default is irrelevent if the OS always configures them a different way. This (the OS defaults) is what is captured on the wiki page. P1-08 is not configured by the OS as GPIO14 by default - any program that wants to use P1-08 as a GPIO pin is going to have to do quite a lot of work to achieve that. It is going to have to stop serial services and reconfigure the pin for GPIO.

Conversely, any program that wants to use P1-12 as GPIO18 can just go ahead and start using it. P1-12 is configured by the OS as GPIO18 by default.

--
Michael

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

Re: GPIO 0

Sat Jun 09, 2012 9:38 pm

Michael wrote:I would suggest that default is what the OS configures the pin to be by default. What the datasheet says is default is irrelevent if the OS always configures them a different way.
I would suggest that you haven't got a clue about what you are saying. This is just soft software tosh.
The software OS can do what it wants and can be changed at any time. The hardware is your only fixed point of reference.

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