72 lines
1.4 KiB
Markdown
72 lines
1.4 KiB
Markdown
# Arcade Button Wiring - Pi 4
|
|
|
|
## Components
|
|
- Arcade Button 33mm illuminated (bastelgarage.ch)
|
|
- Raspberry Pi 4 Model B
|
|
|
|
## GPIO Header Pinout
|
|
|
|
```
|
|
3.3V (1) (2) 5V
|
|
GPIO 2 (3) (4) 5V
|
|
GPIO 3 (5) (6) GND
|
|
GPIO 4 (7) (8) GPIO 14
|
|
GND (9) (10) GPIO 15
|
|
GPIO 17 (11) (12) GPIO 18
|
|
GPIO 27 (13) (14) GND ← LED
|
|
GND (15) (16) GPIO 23
|
|
...
|
|
```
|
|
|
|
## Circuit (without transistor)
|
|
|
|
### LED (GPIO controlled)
|
|
```
|
|
3.3V (Pin 1) ─── LED + (from button)
|
|
│
|
|
LED -
|
|
│
|
|
GPIO 27 (Pin 13) ───┘
|
|
```
|
|
|
|
### Button
|
|
```
|
|
GPIO 17 (Pin 11) ─── Button Contact 1
|
|
Button Contact 2 ─── GND (Pin 6)
|
|
```
|
|
|
|
## Logic
|
|
| GPIO 27 | LED |
|
|
|---------|------|
|
|
| HIGH | OFF |
|
|
| LOW | ON |
|
|
|
|
## LED Specs (resistor already included)
|
|
- Operating voltage: 5V to 12V
|
|
- At 3.3V: slightly less bright, but works
|
|
|
|
## Next Steps
|
|
1. Verify wiring
|
|
2. Python script for testing:
|
|
```python
|
|
import RPi.GPIO as GPIO
|
|
import time
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
# LED on GPIO 27
|
|
GPIO.setup(27, GPIO.OUT)
|
|
|
|
# Button on GPIO 17
|
|
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
|
|
try:
|
|
while True:
|
|
if GPIO.input(17) == False: # Button pressed
|
|
GPIO.output(27, GPIO.LOW) # LED ON
|
|
else:
|
|
GPIO.output(27, GPIO.HIGH) # LED OFF
|
|
time.sleep(0.1)
|
|
except KeyboardInterrupt:
|
|
GPIO.cleanup()
|
|
``` |