Sharing GPIO pins

Hi All.

I’m a bit of a newbie, so please forgive my ignorance on all stuff pi.

I have just got a rPi zero and a Speaker pHat. I’ve actually not successfully managed to get the Speaker pHat running, but that’s the subject of another post.

I have just configured a power button on pins 5 and 6 as per https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi to wake and the shut down the pi.

It works well, but I’ve not yet added the Speaker pHat and that also uses pin 5.

Can the power switch and the Speaker pHat SHARE pin 5, or would that be a disaster?

Thank you in advance!

I think I’m right in saying that they couldn’t share that pin in this situation.

The long answer

Pin 5 (also known as BCM3) is the I2C clock pin (SCL) and it’s used to control the LEDs on Speaker pHAT. Normally, the two I2C pins (BCM2 and BCM3) can have multiple devices attached with the gotcha that they have to be talking the I2C protocol to the Pi. If you have that pin configured to read a button state, then it won’t also be able to be talking I2C to the LEDs, I think.

The short answer

Switch your button to another pin. :-)