2. Other Projects‎ > ‎Raspberry Pi‎ > ‎Pi Blog‎ > ‎

GPIO pin confusion

posted 8 Dec 2016, 05:13 by Andy Lakin-Hall   [ updated 9 Dec 2016, 00:53 ]

One of the things I've found with using the GPIO pins is getting confused about which pin to use.

Now my bare Pi GPIO looks like this

The thing about that is its tricky to know which pin does what. There are guides to connect things like this one...

but the problem with that is, at the moment I don't have any female ended jump leads which can plug straight on. I've got some on order now, but they've not arrived yet.

So previously I picked up an adapter in the Maplin store which has a nice ribbon cable and handy clips for wires.

But the problem with this is there were no instructions, and the labels don't match anything I understand yet. It didn't even give me a clue about which way round to connect the ribbon onto the Pi. By guesswork I figured it out...

...and the ribbon has to point out from the Pi.

Now to further complicate things, I have a Raspberry Pi FUZE kit.

This encases the Pi and has a handy IO board.

This has GPIO pins 0 to 7 available over on the right. You can plug in fly leads to the breadboard beside, and then program them through FUZE BASIC quite easily.

PINMODE ( 0, 1 )
WAIT( 0.5 )
WAIT ( 0.5 )

And what this does is make an LED on the fuze GPIO pin 0 flash on and off. Simples.

What's floored me is getting Scratch to do the same.

The latest version of Scratch 1.4 on the Pi includes a GPIO server, so you can read and write to the GPIO in Scratch. Which is cool, because I enjoy working in Scratch very much. It make sense to me.

Now in my previous experiment I wrote the following code

And that worked on the bare Pi connected to the Maplin adapter block. I chose gpio17 because that was one I could identify on the block when I couldn't see gpio0 like on the FUZE.

What I hadn't realised is the Pin numbers bear no relation whatsoever to the GPIO numbers, and you need a reference guide to work out which is which. Bu fluke, I'd stumbled on the fact that gpio17 in Scratch is the same as Pin0 in FUZE.

On the back of the FUZE BASIC Reference Guide there is a GPIO Pin layout plan that looks like this...

..which made no sense at all! But then I followed the link to WiringPi which is the Library that FUZE uses, and suddenly I realised that the FUZE plan actually needed to be cut out and pushed over the GPIO pins so that the column on the left go over the right strip of pins, and the column on the right go over the pins on the left!

WiringPi have a better pin guide.


On this table, the physical pins are listed down the centre as HEADER. Then working outward, there's the actual name, the BCM GPIO reference and then the WiringPi code.

So, by accident, the header pin 11 which is connected on my FUZE to GPIO0 is also BCM-GPIO17.

So, for Scratch, if I wanted to connect LEDs to GPIO pins 0, 1, 2 and 3, I'd actually need to use header pins 11, 12, 13 and 15, and (because I've got a Rv2 board), in Scratch that would be gpio17, gpio18, gpio27, and gpio22.

Here's the Scratch code...


...and here's the wiring on the FUZE breadboard...

Now, back to the Maplin connector block.

This, I can now see, make available some of the important GPIO pins.

In fact, the top connector maps header pins 1, 3, 5, 7, 9 and 11, 

 Label Header
 3v3 1
 +GPCLK0 7
 GND 9
 P17 11

and the right connector maps header pins 13, 15, 17, 19, and 21, then goes weird and jumps to header 22, 24 and 26.


Finally the left hand connector, which is mapping the right hand line from the header;

TXD    8
5VO 4

Here it is now labelled up.

GPIO 0-3 test.sb
Andy Lakin-Hall,
9 Dec 2016, 00:52