Raspberry GPIO


Primeiramente gostaria de salientar que não sou o autor principal do conteúdo deste artigo. A minha intenção é de mostrar o que outros autores tem realizado (referenciando links para o conteúdo original) neste blog até como um guia pessoal para uso próprio e ainda compartilhar minhas anotações e pequenas modificações que realizo no conteúdo, desejando que possa ajudar mais alguém em algum lugar.
First and foremost, I take no credit for any of this post’s content. I am really just taking what others have done (which I have links to bellow) and am putting it on my blog for a personal reference and hopefully the small changes that I made to their guides will help someone somewhere.


link: http://wiringpi.com/pins/special-pin-functions/

Special Pin Functions

WiringPi defines 17 pins, (21 on a Rev. 2 board) but some of them and the functions we can use may potentially cause problems with other parts of the Raspberry Pi Linux system.

  • Pins 0 through 6 (BCM_GPIO 17, 18,  21, 22, 23, 24, 25 respectively, substitute 27 for 21 on a Rev. 2 board): These are safe to use at any time and can be set to input or output with or without the internal pull-up or pull-down resistors enabled.
  • Pin 7 (BCM_GPIO 4) This is normally OK to use, however it is used by the 1-Wire kernel driver and it can optionally be connected to a GPIO clock source.
  • PWM: You can change the function of pin 1 (BCM_GPIPO 18) to be PWM output, however if you are currently playing music or using the audio system via the 3.5mm jack socket, then you’ll find one channel of audio PWM coming through the pin! If you are not using the audio at all, (or the audio is going via the HDMI cable), then this pin is free to be used in PWM mode.
  • Pins 8 and 9 (BCM GPIO 0 and 1 on a Rev. 1 board, 2 and 3 on a Rev. 2 board): These are the I2C pins. You may use them for digital IO if you are not using any I2C drivers which use these pins, however note that they have on-board 1.8KΩ resistors pulling the signals to the 3v3 supply. This feature does make them handy for switch inputs where the switch simply shorts the pin to ground without having to enable the internal pull-up resistors
  • Pins 10, 11, 12, 13 and 14 (GPIO 8, 7, 10, 9 and 11 respectively): These are used for the SPI interface. Like the I2C interface, if you are not using it, then you can freely use them for your own purposes. Unlike I2C, these pins do not have any external pull up (or pull down) resistors.
  • Pins 15 and 16 (GPIO 14 and 15): These are used by the UART for Tx and Rx respectively. If you want to use these pins as general purpose I/O pins then you need to make sure that you reboot your Pi with the serial console disabled. See the file /boot/cmdline.txt and edit it appropriately.
  • Pins 17, 18, 19 and 20: (BCM_GPIO 28, 29, 30 and 31) These are additional GPIO pins on the Rev. 2 board.

 Remember: The Raspberry Pi is a 3.3 volt device! Attempting to directly connect to any 5V logic system will very likely result in tears…



The following tables give the mapping of the Raspberry Pi GPIO Pins to the GPIO connector in relation to the pin numbers and the physical location on the connector. This is a representation of the GPIO connector as viewed looking at the board from above, with the USB power at the top and the GPIO to the top-right of the board.

If using the connector pin numbering, then note that Pin 1 on the connector is the 3.3v supply. Pin 2 is the 5V supply, and pin 26 is marked SPI CE1 below.

P1: The Main GPIO connector:

wiringPi
Pin
BCM
GPIO
Name Header Name BCM
GPIO
wiringPi
Pin
3.3v 1 | 2 5v
8 R1:0/R2:2 SDA 3 | 4 5v
9 R1:1/R2:3 SCL 5 | 6 0v
7 4 GPIO7 7 | 8 TxD 14 15
0v 9 | 10 RxD 15 16
0 17 GPIO0 11 | 12 GPIO1 18 1
2 R1:21/R2:27 GPIO2 13 | 14 0v
3 22 GPIO3 15 | 16 GPIO4 23 4
3.3v 17 | 18 GPIO5 24 5
12 10 MOSI 19 | 20 0v
13 9 MISO 21 | 22 GPIO6 25 6
14 11 SCLK 23 | 24 CE0 8 10
0v 25 | 26 CE1 7 11
wiringPi
Pin
BCM
GPIO
Name Header Name BCM
GPIO
wiringPi
Pin
  • Board Revisions: Please note the differences between board revisions 1 and 2 (R1 and R2 above)

P5: The auxilliary GPIO connector present on Rev. 2 boards only:

wiringPi Pin BCM GPIO Name Header Name BCM GPIO wiringPi Pin
5v 1 | 2 3.3v
17 28 GPIO8 3 | 4 GPIO9 29 18
19 30 GPIO10 5 | 6 GPIO11 31 20
0v 7 | 8 0v
wiringPi
Pin
BCM
GPIO
Name Header Name BCM
GPIO
wiringPi
Pin

Note also that the P5 connector is designed to be used from the underside of the Pi – ie. you solder on the top of the Pi board to install the connector! If you are using it from the top, then you need to mirror the diagram above.

Each side has three columns. The outermost column, headed wiringPi Pin refers to the pin number in the wiring Pi code. The middle one, headed BCM GPIO refers to the pin number of the BCM2835 chip, an this is the pin number used when addressing the GPIO using the /sys/class/gpio interface. The innermost column, Name is the name of the function of the pin.

The central column contains the pin numbers on the header on the board. Pin 1 is the 3.3v power supply on the P1 connector (Rev. 1 and Rev. 2 boards), and Pin 1 is the 5v power supply on the P5 connector on Rev. 2 boards only.




Comments