If you are the one facing the same problem, then this article will help you develop a complete understanding of BCM in Raspberry Pi.
What is BCM, and Why is it Used in Raspberry Pi
BCM is an abbreviation for the “Broadcom SOC channel; In Raspberry Pi, there are two ways to refer to the Raspberry Pi board pins: one is the BCM and the other is BOARD. The lower-level pins on the board that are defined by the Broadcom chip are the BCM pins, and the BCM number is different from the board/chip pin numbers because in the initial boards of Raspberry Pi, there was a lesser number of pins. As new boards have launched, more pins are added, and the BCM number remains the same due to which the overall alignment of pin numbers gets disturbed.
Pins Configuration of Raspberry Pi Board
The image below shows the pin configuration of the latest Raspberry Pi boards which has 40 pins. The pin names mentioned in the colored rectangles are the BCM number of pins and the numbers mentioned inside the circles represent the BOARD number of pins.
For the ease of users, Raspberry Pi supports both the usage of BCM and BOARD numbers. Users just must refer to them in the code before coding the pins.
To refer to the numbers present inside the circles (1,2,3,4,…) the GPIO.BOARD configuration will be used inside the Python script:
Whereas, to refer to the pins inside coloured rectangles (GPIO10, GPIO11, GPIO12,…) the GPIO.BCM is used:
How to Use BCM in Python Scripts in Raspberry Pi?
Let’s understand this with an example, If I have to use pin 11 of the board (GPIO17, BCM), to toggle an LED then I will use it in the Python code as stated below:
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
for i in range(15):
GPIO.output(17, GPIO.HIGH)
time.sleep(2)
GPIO.output(17, GPIO.LOW)
time.sleep(2)
In the code to set the pin mode, I have defined the BCM pin configuration at the start, after which I have used GPIO17 pin instead of 11 (BOARD number).
Circuit For Python Code
The hardware circuit for the above code is shown in the below image, where I have highlighted the GPIO 17 pin (BCM).
The LED will blink 15 times with 2 seconds delay between each on and off state.
Conclusion
BCM is a Broadcom channel on Raspberry Pi, which is used to configure Raspberry Pi pins by using the Broadcom channel numbers. The BCM number of pins is different from the BOARD number. These numbers are used while programming the GPIO pins, the user has to define the GPIO.setmode at the start. After which the pins can be used accordingly in the code.