QUOTE: Life is tough, but so are you.

Tinkering with GPIO for Raspberry Pi 3B

Cheatsheets and references for commonly used GPIO components.

08. Jun 2024 toc: disabled view: slim

Examples

I wrote a custom library for the BCM2835 in C called libbcm2835.

Toggle LED

// [ GPIO17 ] ----> [ R220 ] ----> [ LED ] ----> [ GND ]

#include <libbcm2835.h>

#define PIN_OUT 17

int main(void) {
  if (bcm_init() < 0) {
    return 1;
  }
  bcm_fsel(PIN_OUT, FSEL_OUT);
  bcm_write(PIN_OUT, HIGH);
  usleep(500 * 1000);
  bcm_write(PIN_OUT, LOW);
  return 0;
}

Cheatsheets

BCM2835 ARM Peripherals

      3V3 Power  *---[ 01 | 02 ]---*  5V Power
    GPIO2 (SDA)  *---[ 03 | 04 ]---*  5V Power
    GPIO3 (SCL)  *---[ 05 | 06 ]---*  Ground
 GPIO4 (GPCLK0)  *---[ 07 | 08 ]---*  GPIO14 (TXD)
         Ground  *---[ 09 | 10 ]---*  GPIO15 (RXD)
         GPIO17  *---[ 11 | 12 ]---*  GPIO18 (PCM_CLK)
         GPIO27  *---[ 13 | 14 ]---*  Ground
         GPIO22  *---[ 15 | 16 ]---*  GPIO23
      3V3 Power  *---[ 17 | 18 ]---*  GPIO24
  GPIO10 (MOSI)  *---[ 19 | 20 ]---*  Ground
   GPIO9 (MISO)  *---[ 21 | 22 ]---*  GPIO25
  GPIO11 (SCLK)  *---[ 23 | 24 ]---*  GPIO8 (CE0)
         Ground  *---[ 25 | 26 ]---*  GPIO7 (CE1)
  GPIO0 (ID_SD)  *---[ 27 | 28 ]---*  GPIO1 (ID_SC)
          GPIO5  *---[ 29 | 30 ]---*  Ground
          GPIO6  *---[ 31 | 32 ]---*  GPIO12 (PWM0)
  GPIO13 (PWM1)  *---[ 33 | 34 ]---*  Ground
GPIO19 (PCM_FS)  *---[ 35 | 36 ]---*  GPIO16
         GPIO26  *---[ 37 | 38 ]---*  GPIO20 (PCM_DIN)
         Ground  *---[ 39 | 40 ]---*  GPIO21 (PCM_DOUT)


gpiochip0 - 54 lines:

---------------------   ---------------------   ---------------------
line 00: ID_SDA         line 18: GPIO18         line 36: SD1_DATA0
line 01: ID_SCL         line 19: GPIO19         line 37: SD1_DATA1
line 02: GPIO2          line 20: GPIO20         line 38: SD1_DATA2
line 03: GPIO3          line 21: GPIO21         line 39: SD1_DATA3
line 04: GPIO4          line 22: GPIO22         line 40: PWM0_OUT
line 05: GPIO5          line 23: GPIO23         line 41: PWM1_OUT
line 06: GPIO6          line 24: GPIO24         line 42: ETH_CLK
line 07: GPIO7          line 25: GPIO25         line 43: WIFI_CLK
line 08: GPIO8          line 26: GPIO26         line 44: SDA0
line 09: GPIO9          line 27: GPIO27         line 45: SCL0
line 10: GPIO10         line 28: NC             line 46: SMPS_SCL
line 11: GPIO11         line 29: LAN_RUN_BOOT   line 47: SMPS_SDA
line 12: GPIO12         line 30: CTS0           line 48: SD_CLK_R
line 13: GPIO13         line 31: RTS0           line 49: SD_CMD_R
line 14: GPIO14         line 32: TXD0           line 50: SD_DATA0_R
line 15: GPIO15         line 33: RXD0           line 51: SD_DATA1_R
line 16: GPIO16         line 34: SD1_CLK        line 52: SD_DATA2_R
line 17: GPIO17         line 35: SD1_CMD        line 53: SD_DATA3_R
---------------------   ---------------------   ---------------------

5161AS 7-Segment Display

   G F + A B
10 * * * * * 06
   | | | | |
 +-----------+
 |  ---A---  |
 | |       | |
 | F       B |
 | |       | |
 |  ---G---
 | |       | |
 | E       C |
 | |       | |
 |  ---D---. |
 +-----------+
   | | | | |
01 * * * * * 05
   E D - C .

74HC595 Chip

       [   \_/   ]              VCC    = 5V Power (Operation voltage)
 QB *--[ 01 | 16 ]--* VCC       SER    = GPIO17   (Input)
 QC *--[ 02 | 15 ]--* QA        !OE    = Ground   (Disable output)
 QD *--[ 03 | 14 ]--* SER       RCLK   = GPIO18   (Refresh output)
 QE *--[ 04 | 13 ]--* !OE       SRCLK  = GPIO27   (Clock)
 QF *--[ 05 | 12 ]--* RCLK      !SRLCR = 5V Power (Retain info)
 QG *--[ 06 | 11 ]--* SRCLK     QH'    = None     (Daisychaining output)
 QH *--[ 07 | 10 ]--* !SRCLR    QA-QH  = Output
GND *--[ 08 | 09 ]--* QH'       GND    = Ground
       [   ___   ]

References