beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

GPIO Pin Numbering

Thu Nov 02, 2017 2:07 am

I have a PI 3B; confused about relationship between GPIO pin # and physical pin numbering . Any help appreciated.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: GPIO Pin Numbering

Thu Nov 02, 2017 2:16 am

at terminal type
pinout

for more info about pin function see here

User avatar
rpdom
Posts: 19530
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO Pin Numbering

Thu Nov 02, 2017 5:44 am

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.

pcmanbob
Posts: 12198
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO Pin Numbering

Thu Nov 02, 2017 11:37 am

And for quick reference I have this on the wall above my bench.

Image
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 6696
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: GPIO Pin Numbering

Thu Nov 02, 2017 9:13 pm

Also wiringPi's gpio readall provides a "good reminder":

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---+---+------+---------+-----+-----+
Trev.
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

User avatar
HawaiianPi
Posts: 6834
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: GPIO Pin Numbering

Thu Nov 02, 2017 11:18 pm

pcmanbob wrote:
Thu Nov 02, 2017 11:37 am
And for quick reference I have this on the wall above my bench.
...
I like this one better.
pi3_gpio.png
pi3_gpio.png (240.32 KiB) Viewed 43256 times
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?

User avatar
Burngate
Posts: 6501
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: GPIO Pin Numbering

Fri Nov 03, 2017 11:06 am

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)
GPIO-B+.png
GPIO-B+.png (21.85 KiB) Viewed 43227 times
I like it because it's smaller than other images, sits on my desktop without taking up valuable real-estate.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sat Nov 11, 2017 7:37 pm

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!

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode (GPIO.BCM)
GPIO.setup (36,GPIO.OUT)
GPIO.output (36,1)

pcmanbob
Posts: 12198
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO Pin Numbering

Sat Nov 11, 2017 7:59 pm

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
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
AllanGH
Posts: 29
Joined: Wed Oct 25, 2017 8:09 am
Location: 34.033909, -117.313616

Re: GPIO Pin Numbering

Sun Nov 12, 2017 1:31 am

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.

Image
Just £2.00 each.
##########################

http://www.catb.org/~esr/faqs/smart-questions.html

User avatar
DougieLawson
Posts: 41961
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO Pin Numbering

Sun Nov 12, 2017 1:57 am

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).
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sat Nov 25, 2017 9:48 pm

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()
The above code controls 2 motors left and right. It is taken from a maker book so should be bugfree. However, works only on one side i.e. one motor turns on (enable pin 21) but the other (enable pin 24)does not. When I connect the enable pin of this motor to the enable of the other, both motors work!Looks like enable pin 24 does not get a 1 but 21 does and hence it turns.

pcmanbob
Posts: 12198
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO Pin Numbering

Sat Nov 25, 2017 10:26 pm

Your code suggests you have you motor controller connected like this.

Image

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

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sat Nov 25, 2017 11:10 pm

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.

pcmanbob
Posts: 12198
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO Pin Numbering

Sat Nov 25, 2017 11:15 pm

beatsal wrote:
Sat Nov 25, 2017 11:10 pm
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.
looks like you are still confusing board and bcm modes.

your code uses

Code: Select all

 GPIO.setmode(GPIO.BOARD)
which means you need to use the pin numbers in black down the middle of the posted image.

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)
in your code.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sun Nov 26, 2017 1:19 am

Thanks, works fine now.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sun Dec 10, 2017 2:39 pm

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?

pcmanbob
Posts: 12198
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO Pin Numbering

Sun Dec 10, 2017 2:44 pm

? Not sure what you are asking.
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

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sun Dec 10, 2017 3:30 pm

Well from your post I gather that I need two supplies 5V and 3.3V?

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

Re: GPIO Pin Numbering

Sun Dec 10, 2017 3:56 pm

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).

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: GPIO Pin Numbering

Sun Dec 10, 2017 4:03 pm

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?

pcmanbob
Posts: 12198
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO Pin Numbering

Sun Dec 10, 2017 6:47 pm

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.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Beginners”