Concept Flow - RPi.GPIO library setup
Import RPi.GPIO as GPIO
Set GPIO Mode (BOARD or BCM)
Setup Pin as Input or Output
Use Pin for Reading or Writing
Cleanup GPIO Pins
This flow shows how to prepare and use GPIO pins on Raspberry Pi step-by-step.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.HIGH) GPIO.cleanup()
| Step | Action | GPIO State | Pin 18 Mode | Pin 18 Output | Notes |
|---|---|---|---|---|---|
| 1 | Import RPi.GPIO as GPIO | Not set | Not set | Not set | Library ready to use |
| 2 | Set mode to BCM | BCM mode | Not set | Not set | Pin numbering uses BCM scheme |
| 3 | Setup pin 18 as output | BCM mode | Output | Not set | Pin 18 ready for output |
| 4 | Set pin 18 output HIGH | BCM mode | Output | HIGH | Pin 18 turned ON |
| 5 | Cleanup GPIO | Reset | Not set | Not set | GPIO pins reset to default |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | After Step 5 |
|---|---|---|---|---|---|
| GPIO Mode | None | BCM | BCM | BCM | None |
| Pin 18 Mode | None | None | Output | Output | None |
| Pin 18 Output | None | None | None | HIGH | None |
RPi.GPIO setup steps: 1. Import library as GPIO 2. Set pin numbering mode (GPIO.setmode) 3. Setup pins as input/output (GPIO.setup) 4. Use pins (GPIO.output/input) 5. Cleanup pins (GPIO.cleanup) to reset Always set mode before setup and cleanup at end.