Here is an easy solution for extending your Raspberry Pi’s GPIO capabilities. This is a 40-pin FPC to Right Angle 2×20 IDC Male Plug Header Adapter.
Use this adapter, which will act as an extender for all 40 pins to give you a streeeeetch. Simply insert the plug side into an optional Socket Riser Header to add to the HAT or Bonnet. Then, keeping an eye where Pin 1 is, insert your FPC ribbon cable into the 40-pin flex connector.
You can use any 40-pin 0.5mm FPC with ‘A-B’ connections. If you want to extend the FPC, a 40-pin extender can be snapped on. Finally, you can use a matching adapter board to tack on your HAT or bonnet of choice on the other end.
Note that some HATs, like the Sense HAT or Bonnets with a slim connector on the bottom will need/benefit from adding a socket ‘riser’ / ‘lifter’ to the HAT to give the cable more connector body to grip onto. Take a look at the HAT or accessory you’re trying to extend. If there isn’t a chunky connector on the bottom of the HAT, pick up a riser!