What will be the output of this Python code snippet using the RPi.GPIO library?
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) print(GPIO.getmode())
Assume the code runs without errors.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) print(GPIO.getmode())
Check the RPi.GPIO documentation for mode constants.
GPIO.BCM mode is represented internally by the integer 11 in RPi.GPIO. So, GPIO.getmode() returns 11 after setting BCM mode.
Which statement correctly describes the difference between BCM and BOARD pin numbering on a Raspberry Pi?
Think about what 'BOARD' and 'BCM' stand for.
BOARD numbering uses the physical pin numbers on the Raspberry Pi header. BCM numbering uses the Broadcom chip's GPIO pin numbers.
What error will this code produce?
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(17, GPIO.OUT) GPIO.output(17, GPIO.HIGH)
Check if pin 17 is valid in BOARD mode.
In BOARD mode, pin numbers refer to physical pins 1-40 on the header. Pin 17 is valid (maps to BCM GPIO0). The code runs without error and sets the pin high.
What will this code print?
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) print(GPIO.gpio_function(18))
Check what gpio_function returns for an unconfigured pin.
GPIO.gpio_function(pin) returns 0 if the pin is set as input (default). Since pin 18 is not configured, it returns 0.
You want to write a Python script using RPi.GPIO that works on different Raspberry Pi models without changing pin numbers. Which pin numbering mode should you use?
Think about physical pin layout consistency.
BOARD mode uses physical pin numbers which remain consistent across Raspberry Pi models with the 40-pin header.