Page 1 of 1

GPIO Pin Numbering

Posted: Thu Nov 02, 2017 2:07 am
by beatsal
I have a PI 3B; confused about relationship between GPIO pin # and physical pin numbering . Any help appreciated.

Re: GPIO Pin Numbering

Posted: Thu Nov 02, 2017 2:16 am
by KLL
at terminal type
pinout

for more info about pin function see here

Re: GPIO Pin Numbering

Posted: Thu Nov 02, 2017 5:44 am
by rpdom
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

Posted: Thu Nov 02, 2017 11:37 am
by pcmanbob
And for quick reference I have this on the wall above my bench.

Image

Re: GPIO Pin Numbering

Posted: Thu Nov 02, 2017 9:13 pm
by FTrevorGowen
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

Re: GPIO Pin Numbering

Posted: Thu Nov 02, 2017 11:18 pm
by HawaiianPi
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 36847 times

Re: GPIO Pin Numbering

Posted: Fri Nov 03, 2017 11:06 am
by Burngate
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 36818 times
I like it because it's smaller than other images, sits on my desktop without taking up valuable real-estate.

Re: GPIO Pin Numbering

Posted: Sat Nov 11, 2017 7:37 pm
by beatsal
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)

Re: GPIO Pin Numbering

Posted: Sat Nov 11, 2017 7:59 pm
by pcmanbob
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

Re: GPIO Pin Numbering

Posted: Sun Nov 12, 2017 1:31 am
by AllanGH
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.

Re: GPIO Pin Numbering

Posted: Sun Nov 12, 2017 1:57 am
by DougieLawson
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).

Re: GPIO Pin Numbering

Posted: Sat Nov 25, 2017 9:48 pm
by beatsal

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.

Re: GPIO Pin Numbering

Posted: Sat Nov 25, 2017 10:26 pm
by pcmanbob
Your code suggests you have you motor controller connected like this.

Image

I suspect you might have a wire connected wrong.

Re: GPIO Pin Numbering

Posted: Sat Nov 25, 2017 11:10 pm
by beatsal
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

Posted: Sat Nov 25, 2017 11:15 pm
by pcmanbob
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.

Re: GPIO Pin Numbering

Posted: Sun Nov 26, 2017 1:19 am
by beatsal
Thanks, works fine now.

Re: GPIO Pin Numbering

Posted: Sun Dec 10, 2017 2:39 pm
by beatsal
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

Posted: Sun Dec 10, 2017 2:44 pm
by pcmanbob
? Not sure what you are asking.
5v and 3.3v pins are just there to supply the relevant voltages you can't control them.

Re: GPIO Pin Numbering

Posted: Sun Dec 10, 2017 3:30 pm
by beatsal
Well from your post I gather that I need two supplies 5V and 3.3V?

Re: GPIO Pin Numbering

Posted: Sun Dec 10, 2017 3:56 pm
by mahjongg
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).

Re: GPIO Pin Numbering

Posted: Sun Dec 10, 2017 4:03 pm
by beatsal
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?

Re: GPIO Pin Numbering

Posted: Sun Dec 10, 2017 6:47 pm
by pcmanbob
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.