RPi.GPIO BCM and BOARD numbering on a Raspberry Pi 4
RPi.GPIO on a Raspberry Pi 4 with GPIO.setmode(GPIO.BOARD): two LEDs on header pins 11 and 13, which are GPIO17 and GPIO27 in BCM numbers. The whole build, a Raspberry Pi 4 and 4 more parts, runs here in your browser on the Python below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $58. On Mokxi they're free.
The code
The Python exactly as the editor opens it. Change a line there and press Run: the board runs main.py in a Python engine in the page, with gpiozero and RPi.GPIO, and nothing to compile.
# RPi.GPIO with BOARD numbering: pins by their place on the header.
# Header pin 11 is GPIO17 and pin 13 is GPIO27. With GPIO.setmode(GPIO.BCM)
# the same two LEDs would be 17 and 27.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
LEDS = [11, 13]
GPIO.setup(LEDS, GPIO.OUT, initial=GPIO.LOW)
try:
while True:
for pin in LEDS:
GPIO.output(pin, GPIO.HIGH)
print("header pin", pin, "on")
time.sleep(0.5)
GPIO.output(pin, GPIO.LOW)
finally:
GPIO.cleanup()
Parts list
6 parts, plus the jumper wires. They retail for about $58; on Mokxi they're free.
- 1 × Raspberry Pi 4 Model B
- 1 × Half breadboard
- 2 × Resistor, 330 Ω
- 1 × LED, red
- 1 × LED, yellow
How it is wired
6 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Raspberry Pi 4 Model B pin GND; LED, red pin C
- Raspberry Pi 4 Model B pin GPIO17; Resistor, 330 Ω (1) pin 1
- Raspberry Pi 4 Model B pin GPIO27; Resistor, 330 Ω (2) pin 1
- Ground: Raspberry Pi 4 Model B pin GND; LED, yellow pin C
- Resistor, 330 Ω (1) pin 2; LED, red pin A
- Resistor, 330 Ω (2) pin 2; LED, yellow pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.