GPIO Expansion + PiHATs + Ribbon Cable


Hi All

I have a B+ with an expansion board (3 GPIO connectors), which when I plug a PiHat directly onto either of the three GPIO expansions works fine.

Trouble is I need to take the Hats off board as I’m building a temp display system, so I need to mount the Hats into a case away from the Pi.

I’ve got some 40Pin Ribbon cable, but when I connect it to the Hats (no matter which way round) it don’t work.

My Hats have a Female IDC connector underneath for direct connection to the Pi, I though a M-M ping convertor into a F-F standard GPIO cable (which came with the Pi) would do the trick, but no joy.

Is there a different Ribbon Cable for connecting Hats to the Pi / Expansion that I’m not aware of?

Am guessing it’s all to do with the direction of the ribbon / pins and gender…

Any help gratefully received.



What’s likely happening is flipping one end of the ribbon cable 180, the connector pointing up, when it should be pointing down, is reversing the pins. Pin 1 is going to Pin 2 and Pin 2 to Pin 1. If you have an ohm meter you can confirm it. If you put a male GPIO header on top of the pHat or Hat pointing up, (like it is on the Pi) and then plug that into the Pi’s GPIO (or expansion board) with the ribbon cable. Pin 1 will match up with Pin 1. That’s not ideal though if you don’t want to give up the space, like if its a display board. A 90 male will still work, mounted on top of the pHat or Hat.


I’m going to try and explain it better. ;)
If you hold the ribbon cable in your hands. One connector in each hand pointing down and the stripe closest to you the pins are like this
12–stripe-- 12
Turn one connector so its pointing up and it changes to this
12–stripe-- 21


Thanks so much for the reply, I sorta see that it’s a complete reverse, used to working with Ribbon cables from years gone by (Printers of old!!), so have even done the odd cable mode, removing the header and reversing it, in my time.

Have ordered some M-F cables so I can just try and jump the hat on the correct pins, I believe looking at the docs this needs just 3 pins (4 including ground), so will give that a whirl.

I really need space above the hat as it will be mounted in a front display, so can’t put the ribbon header on that side (connections have to go underneath)

Thanks for explaining in such great detail.



I’ve worked in electronics all my adult life. And with Pi related stuff for a few years now.
That’s one of those things that’s not so easy to explain in plain text. Especially if the other person doesn’t have any electronics background. Here you usually don’t know if they do unless you ask or somebody tells you.
Tinkerers come from all walks of life.
If it doesn’t work, keep connecting grounds, one may not be enough. They might not all be linked together on the pHat itself and rely on the fact that they are all common on the Pi. .


Thanks a mill! For all the advice all gratefully received. I have just connected the pins directly and viola! perfect all works beautiful, now I can put it in its box!! This is really great stuff, I love it.


Luckily you didn’t damage anything, that can happen when you get the GPIO reversed like that. 5V goes where its not supposed too etc. Your pHat only using a few pins is likely what saved any damage. The 5V and 3.3v went to Pins that weren’t connected to anything.
Anyway, have some fun now. That’s one thing with stuff like this, there is usually several different ways to do things. I’ve used female to female jumpers for breakout boards in several of my projects. Male headers at both ends in that situation. I haven’t used any for pHat or Hats, not yet anyway. I haven’t had to use a ribbon cable ether for a pHat or Hat. Blind luck or good planning, you be the judge, lol. These are my projects if you want to have a look.!AjOYwiwlwDtpgUMsp2qnevKpGEHb May as well use OneDrive for something useful. Makes it easy linking to pictures instead of uploading a bunch and cluttering things up.