Interfacing Joystick Module with Raspberry Pi 3 ๐ฎ
A joystick module is a fun way to capture directional input using two potentiometers and a switch. With Raspberry Pi 3, it’s great for games, robot control, and UI navigation! ๐น️
๐ง Components Required
Component | Quantity |
---|---|
Raspberry Pi 3 | 1 |
Joystick Module (Analog) | 1 |
ADC MCP3008 | 1 |
Jumper Wires | Multiple |
๐ Pin Connections
The joystick gives analog values. Since RPi doesn't support analog input, we use MCP3008 ADC.
MCP3008 Pin | RPi Pin | Joystick Channel |
---|---|---|
CH0 | Joystick VRx | X-axis |
CH1 | Joystick VRy | Y-axis |
DOUT | GPIO 9 (MISO) | - |
DIN | GPIO 10 (MOSI) | - |
CLK | GPIO 11 (SCLK) | - |
CS | GPIO 8 (CE0) | - |
VDD/VREF | 3.3V | - |
AGND/DGND | GND | - |

Figure: Joystick interfaced using MCP3008 to Raspberry Pi 3
๐ป Python Code
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
try:
while True:
x_pos = read_channel(0)
y_pos = read_channel(1)
print(f"X: {x_pos}, Y: {y_pos}")
time.sleep(0.5)
except KeyboardInterrupt:
spi.close()
๐ Summary
This project helps bring joystick input to Raspberry Pi. It’s useful for gaming, movement control in robots, and graphical navigation. ๐
Raspberry Pi 3 เคธเคน Joystick Module เคตाเคชเคฐเคฃे ๐ฎ (เคฎเคฐाเค ी)
Joystick เคตाเคชเคฐूเคจ เคเคชเคฃ เคตाเคชเคฐเคเคฐ्เคค्เคฏाเคा เคฆिเคถाเคค्เคฎเค เคเคจเคชुเค เคฎिเคณเคตू เคถเคเคคो. เคเคฒा Raspberry Pi 3 เคธोเคฌเคค เคนे เคोเคกूเคฏा!
๐ง เคฒाเคเคฃाเคฐे เคธाเคนिเคค्เคฏ
เคธाเคนिเคค्เคฏ | เคช्เคฐเคฎाเคฃ |
---|---|
Raspberry Pi 3 | 1 |
Joystick Module | 1 |
MCP3008 (ADC) | 1 |
เคंเคชเคฐ เคตाเคฏเคฐ | เค เคจेเค |
๐ เคตाเคฏเคฐिंเค เคोเคกเคฃी
Joystick เคा เคเคเคเคชुเค analog เค เคธเคคो, เคฎ्เคนเคฃूเคจ MCP3008 เคตाเคชเคฐเคคो.
MCP3008 เคชिเคจ | RPi เคชिเคจ | Joystick เคॅเคจेเคฒ |
---|---|---|
CH0 | Joystick VRx | X-เค เค्เคท |
CH1 | Joystick VRy | Y-เค เค्เคท |
DOUT | GPIO 9 (MISO) | - |
DIN | GPIO 10 (MOSI) | - |
CLK | GPIO 11 (SCLK) | - |
CS | GPIO 8 (CE0) | - |
VDD/VREF | 3.3V | - |
AGND/DGND | GND | - |
๐ป Python เคोเคก
# เคตเคฐीเคฒ เคंเค्เคฐเคी เคोเคก เคตाเคชเคฐा
๐ เคธाเคฐांเคถ
เคนा เคช्เคฐोเคेเค्เค เคेเคณ, เคฐोเคฌोเค เคจिเคฏंเคค्เคฐเคฃ เคเคฃि GUI เคฎเคง्เคฏे เคตाเคชเคฐเคเคฐ्เคคा เคเคจเคชुเคเคธाเค ी เคเคชเคฏुเค्เคค เคเคนे. ๐ฏ
Comments