Internet of Things: Raspberry PI GPIO

Introduction

 
The main difference between a Raspberry Pi (little computer) and other computers is the GPIO pins. In contrast to other computers, Raspberry Pi uses these GPIO pins to perform input and output.

The GPIO pins, the function of each pin on the Pi board, and GPIO numeration are presented in this chapter.
 

Raspberry Pi GPIO

 
 
Fig. 1
 
Desktop computers are UBIQUITOUS i.e. they have a standard input and output (files, keyboard, mouse, touch, print, screen, etc.) and they take information from the fixed input, process it, and give the results back to the standard output. This means a normal computer/machine does not have an interface to connect with electronic devices like sensors and actuators. This is where Raspberry Pi (tiny computers) GPIO pins play an important role and make Raspberry Pi different from the other computers.
 
The Pi has GPIO pins that stick out from the top of the board. These pins act as an interface between Raspberry Pi and the physical world. These pins are used to communicate (both input/output) with other circuitry such as sensors, actuators, extension boards, and custom circuits.
 
Understanding the Pins
 
The GPIO pins, shown below vary, based on the Raspberry Pi model. The previous models have 26 pins and the latest models - Raspberry Pi 2 Model B and Raspberry Pi 3 Model B both have 40 Pins.
 
 
Fig. 2
 
To maintain backward compatibility, the first 26 pins from the previous models still have the same functionality in the new Raspberry Pi models, as shown below.
 
 
Fig. 3
 
As shown below, each pin on Raspberry Pi has a function to do, and also an alternate function is assigned. You can consider these pins like switches, which have a function. An alternate function can be turned on or off. Apart from the regular function/ standard I/O pins (GPIO), in alternate functions, these pins have GND (Ground), SPI (Serial Peripheral Interface Bus), I2C (Inter-Integrated Circuits), power pins and UART (Universal Asynchronous Receiver/Transmitter) pins.
 
 
Fig.4
 
GPIO numbering
 
As shown above, the GPIO pins diagram seems to be pretty complex and confusing and there is no easy way to remember each of the pins. You need to keep a printed reference sheet on top while using them.
 
There is a solution to this problem and in the Raspberry Pi world, there are two different numbering schemes used when referencing Pins.
  1. Using the BCM
     
    Broadcom chip-specific pin number – example GPIO 10, GPIO23, GPIO24 etc.
     
  2. Physical numbering
     
    In it, each number is based on the physical position of the pin. (Hold the Raspberry Pi up facing you; vertically with the pins on the right side then followed by counting from top left as pin 1 and next pin as 2 on the first row and the pin below 1 as 3 and below 2 as 4 and so on).
     
     
    Fig, 5
     
     
    Fig. 6
Note
 
You are free to use any of the above GPIO numbering systems while invoking the GPIO pins in programs ( like python or C # ). Your code should reference one of the numbering systems which you are going to use. Example: In a Python program – the code looks, as shown below.
 
 
GPIO.BOARD is the physical numbering system and GPIO.BCM is the Broadcom numbering system. Don’t worry if you don’t understand the above code. We will learn all about in future articles.
 
Important Warning
 
You have to be careful when connecting devices and the GPIO pins directly with wires (called jumper cables) -- if these wires are connected to the wrong pins, it might damage the Pi board, so please read the instructions carefully before connecting wires directly to the pins.
 
I would highly recommend, using a Breadboard – where you can create the dummy circuits on the breadboard and then connect only to the required pins on the Pi. I would also recommend using a “breakout circuit” to connect the Raspberry Pi with the breadboard. One end of the breakout board is connected to the Raspberry Pi and the other end into the breadboard.
 
That’s all for this chapter. I hope you enjoyed reading!!
Author
Hussain Patel
1048 1.3k 419.2k
Next » Internet of Things: Setting Up Raspberry PI