In this guide, we're using the Raspberry Pi 3B+. Before diving into programming with the GPIO Zero library, let's take a closer look at the pins on the Raspberry Pi. In the diagram, you'll notice that there are plenty of 'GPIO' pins. These GPIO pins are integrated into the circuit board of the Raspberry Pi. As noted before, their behaviour can be controlled to interface with the physical world whether by reading data from sensors, or using components such as LEDs and displays.
Older models of the Raspberry Pi had 26 GPIO pins, while the newer models have 40.
If you are using a different model of Raspberry Pi, please note that its pinout may differ.
Let's start with the power pins. The Raspberry Pi 3B+ can provide both 5V (pins 2 and 4) and 3.3V power (pins 1 and 17)
Ground are the pins you use to ground your devices. They are all connected to the same line, so you can use any of them to ground your devices.
A large number of sensors and other peripherals can be attached to the Raspberry Pi through the I2C (Inter-Integrated Circuit) protocol. For these electronic devices to communicate with one another, they need to speak the same language; in electronics, these languages are called communication protocols.
The I2C communication protocol is a commonly used standard that enables one chip to talk to another. In this instance, it lets the Raspberry Pi communicate with a variety of other I2C capable chips or modules.
To physically connect peripherals to the Raspberry Pi, we need to use only four wires: Ground, VCC, SDA, and SCL.
SDA (Serial Data Line) can be accessed on Pin 3
SCL (Serial Clock Line) can be accessed on Pin 5
SPI known as Serial Peripheral Interface is another communication protocol that is similar to I2C. However, there are several differences:
It operates at a higher speed and is often used for devices that require continuous transfer of large amounts of data i.e. displays and audio. That is to say, it is good for high data rate full-duplex connections, the simultaneous sending and receiving of data.
There is one master on the bus, this role is usually taken by the microcontroller and in this case, the Raspberry Pi. The 'slave' devices may be the sensors that are attached, and they require the use of at least six pins for communication. Aside from VCC and Ground, it requires another 4 pins for communication:
MOSI (master-out-slave-in) - Sends information from the 'Master' device to 'Slave' device, and can be accessed on Pin 19 (SPI0 bus) or Pin 38 (if using the SPI1 bus).
MISO (master-in-slave-out) - Sends information in the reverse direction, and can be accessed on Pin 21 (SPI0 bus) or Pin 35 (if using SPI1 bus)
SCLK (clock) - Line for the clock signal, and can be accessed on Pin 23 (SPI0 bus) or Pin 40 (if using the SPI1 bus)
CS (chip select) - Line for the 'master' device to select which 'slave' device to send data to, and can be accessed on Pin 24 (CE 0) and Pin 26 (CE 1)
SCLK, MISO, and MOSI lines can be shared among many slaves, but each slave requires its individual CS line.
UART also known as universal asynchronous receiver-transmitter, is used for serial communication and allows the Raspberry Pi to communicate with other serial devices.
It uses the RX line and TX line, as well as a fixed baudrate. Common devices that use UART include MIDI interfaces, thermal printers, GPS modules, etc.
The UART system can be accessed on pins 8 (TXD) and 10 (RXD).
Finally, you may notice that there is also a pair of odd pins, ID_SD and ID_SC.
These must only be used for attaching a compatible ID EEPROM. EEPROMS are a type of non-volatile memory, and are used by Raspberry Pi HATS.