GPIO Pin Numbering
I have a PI 3B; confused about relationship between GPIO pin # and physical pin numbering . Any help appreciated.
Re: GPIO Pin Numbering
http://pinout.xyz give a view of the GPIO connector and describes the possible functions and BCM numbers of every pin, as well as the WiringPi designations.
Re: GPIO Pin Numbering
And for quick reference I have this on the wall above my bench.


We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
- FTrevorGowen
- Forum Moderator
- Posts: 6813
- Joined: Mon Mar 04, 2013 6:12 pm
- Location: Bristol, U.K.
Re: GPIO Pin Numbering
Also wiringPi's gpio readall provides a "good reminder":
Trev.
More examples here: http://www.cpmspectrepi.uk/raspberry_pi ... adall.html
Code: Select all
pi@raspiP3B16Gb:~ $ uname -a
Linux raspiP3B16Gb 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux
pi@raspiP3B16Gb:~ $ gpio readall
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5V | | |
| 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | ALT5 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT5 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | OUT | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
More examples here: http://www.cpmspectrepi.uk/raspberry_pi ... adall.html
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B, B+, and a A+) but Buster on the P3B+, P4B's & P400. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm
- HawaiianPi
- Posts: 7122
- Joined: Mon Apr 08, 2013 4:53 am
- Location: Aloha, Oregon USA
Re: GPIO Pin Numbering
I like this one better.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups, and where is that annoying music coming from?
lots of pop-ups, and where is that annoying music coming from?
Re: GPIO Pin Numbering
I grabbed a chunk of the B+ schematic, coloured it to my own scheme and added some ^ symbols to the first nine GPIOs (the ones with pull-up enabled by default - the rest have pull-downs enabled)
I like it because it's smaller than other images, sits on my desktop without taking up valuable real-estate.Re: GPIO Pin Numbering
Thanks for the pinout.
I tried some, they are fine, some are intermittent i.e. give warning "This channel is already in use, continuing anyway", some do not work at all especially pin 36 which actually took out my VNC connection!
I tried some, they are fine, some are intermittent i.e. give warning "This channel is already in use, continuing anyway", some do not work at all especially pin 36 which actually took out my VNC connection!
Code: Select all
import RPi.GPIO as GPIO
GPIO.setmode (GPIO.BCM)
GPIO.setup (36,GPIO.OUT)
GPIO.output (36,1)
Re: GPIO Pin Numbering
Well you have managed to confuse BCM and board pin numbering even with all the helpful posts.
In BCM mode gpio only goes up to 27
Were as in board mode it goes up to 40
So pin 36 is actually gpio 16 which is what you should have used in BCM mode
In BCM mode gpio only goes up to 27
Were as in board mode it goes up to 40
So pin 36 is actually gpio 16 which is what you should have used in BCM mode
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
Re: GPIO Pin Numbering
I favor the Element14 graphic, myself, and have that printed out and in one of my reference notebooks, now. Thanks for that one--I missed seeing it when I was on their site.
I did think that this might be worth mentioning:
Over at http://rasp.io/portsplus/ they sell a small scrap of PC board that you can put on your keychain, or hang on a hook in your work area, that you may find to be helpful.

Just £2.00 each.
I did think that this might be worth mentioning:
Over at http://rasp.io/portsplus/ they sell a small scrap of PC board that you can put on your keychain, or hang on a hook in your work area, that you may find to be helpful.

Just £2.00 each.
##########################
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.catb.org/~esr/faqs/smart-questions.html
- DougieLawson
- Posts: 42155
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: GPIO Pin Numbering
The problem with Alex's small 40 pin circuit board is that it blocks off part of the regular sized header pins and makes my dupont wires fall off.
https://mikaelleven.wordpress.com/hardw ... gpio-card/ or https://bit.ly/rpi-gpio-card
Costs £0.00628 + the cost of coloured ink (based on a £3.18 ream of A4 paper) and you can easily replace it when it gets broken. You can also scribble notes on it (in small writing).
https://mikaelleven.wordpress.com/hardw ... gpio-card/ or https://bit.ly/rpi-gpio-card
Costs £0.00628 + the cost of coloured ink (based on a £3.18 ream of A4 paper) and you can easily replace it when it gets broken. You can also scribble notes on it (in small writing).
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: GPIO Pin Numbering
Code: Select all
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(26,GPIO.OUT)
def rForward():
GPIO.output(21,1)
GPIO.output(19,0)
GPIO.output(23,1)
def lForward():
GPIO.output(24,1)
GPIO.output(22,0)
GPIO.output(26,1)
def rBackward():
GPIO.output(21,1)
GPIO.output(19,1)
GPIO.output(23,0)
def lBackward():
GPIO.output(24,1)
GPIO.output(22,1)
GPIO.output(26,0)
def allStop():
GPIO.output(21,0)
GPIO.output(24,0)
rForward()
lForward()
time.sleep(2)
allStop()
time.sleep(0.5)
rBackward()
lBackward()
time.sleep(2)
allStop()
Re: GPIO Pin Numbering
Your code suggests you have you motor controller connected like this.

I suspect you might have a wire connected wrong.

I suspect you might have a wire connected wrong.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
Re: GPIO Pin Numbering
Thanks. Confused - i.e. GPIO.output(24,1) I thought it means GPIO 24 which is equiv to pin 18 is hence connected to pin18, but your diagram shows it different.
Re: GPIO Pin Numbering
looks like you are still confusing board and bcm modes.
your code uses
Code: Select all
GPIO.setmode(GPIO.BOARD)
if you wish to use gpio numbers those that are coloured yellow , orange etc
then you need to use
Code: Select all
GPIO.setmode(GPIO.BCM)
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
Re: GPIO Pin Numbering
Thanks, works fine now.
Re: GPIO Pin Numbering
The pinout shows 5V on 2,4; 3.3V on 1,17. This means I need 3.3V on 1,17 OR 5V on 2,4?
Re: GPIO Pin Numbering
? Not sure what you are asking.
5v and 3.3v pins are just there to supply the relevant voltages you can't control them.
5v and 3.3v pins are just there to supply the relevant voltages you can't control them.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
Re: GPIO Pin Numbering
Well from your post I gather that I need two supplies 5V and 3.3V?
- mahjongg
- Forum Moderator
- Posts: 14480
- Joined: Sun Mar 11, 2012 12:19 am
- Location: South Holland, The Netherlands
Re: GPIO Pin Numbering
NO
power pins on the GPIO header are *outputs*, the only real power input is the (5 Volt) micro-USB input.
3V3 is made by the PI, and the 5V is simply the 5V from the micro-USB input *after* passing the polyfuse (except on the RPI zero (w) which has no polyfuse).

power pins on the GPIO header are *outputs*, the only real power input is the (5 Volt) micro-USB input.
3V3 is made by the PI, and the 5V is simply the 5V from the micro-USB input *after* passing the polyfuse (except on the RPI zero (w) which has no polyfuse).
Re: GPIO Pin Numbering
Thanks.
My problem is: I am building a robot and am stuck for space/weight. I already have a L298H on board which has a 5V regulator output. I want to use this 5V to power my PI, so I won't need a separate power unit. Can I do so?
My problem is: I am building a robot and am stuck for space/weight. I already have a L298H on board which has a 5V regulator output. I want to use this 5V to power my PI, so I won't need a separate power unit. Can I do so?
Re: GPIO Pin Numbering
A couple of things to be aware of if you use the on board 5v regulator on you motor control board.
Most use a 7805 regulator that will only supply 1A which if you are using a pi 2 or 3 may not be enough if it has other things attached to the gpio.
The 7805 requires a minimum of 7v input to get a 5v output if you battery drops below 7v due to a heavy motor load or you battery running down you will loose the 5v from the 7805.
Most use a 7805 regulator that will only supply 1A which if you are using a pi 2 or 3 may not be enough if it has other things attached to the gpio.
The 7805 requires a minimum of 7v input to get a 5v output if you battery drops below 7v due to a heavy motor load or you battery running down you will loose the 5v from the 7805.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported