Example 31: PS2 Joystick
About 1 min
Example 31: PS2 Joystick
Experiment Overview
A PS2 joystick module provides two-axis analog output (X/Y) and one button output (Z-axis press), suitable for game control, pan-tilt control, robotic arm manipulation, and similar scenarios.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| VRx | GPIO34 | X-axis analog output |
| VRy | GPIO35 | Y-axis analog output |
| SW | GPIO4 | Button (LOW when pressed) |
X/Y axes output ~1.65V (ADC ~2048) at center; 0V or 3.3V at full deflection.
JSON Configuration Example
{
"peripherals": [
{
"id": "joystick_x",
"name": "Joystick X-Axis",
"type": 15,
"enabled": false,
"pins": [34],
"params": {}
},
{
"id": "joystick_y",
"name": "Joystick Y-Axis",
"type": 15,
"enabled": false,
"pins": [35],
"params": {}
},
{
"id": "joystick_btn",
"name": "Joystick Button",
"type": 13,
"enabled": false,
"pins": [4],
"params": {}
}
]
}Peripheral Execution Linkage
Scenario: Joystick Servo Control (Timer Trigger + Script)
Feature: Control servo angle (0-180°) via joystick X-axis
Web UI Configuration Steps
Step 1: Ensure Servo Peripheral is Configured
- Peripheral ID:
servo_01 - Type: Servo
Step 2: Create Rule
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Joystick Servo Control - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 3: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Periodic sampling Timer Mode Select Fixed Interval Millisecond interval Interval 100100ms (fast response)
Step 4: Configure Action (Script Conversion)
Click Add Action button
Fill in:
- Action Type: Select Command Script
- Action Parameter:
var x=analogRead('joystick_x'); var angle=Math.round(x*180/4095); servoWrite('servo_01',angle);Click Save button
PS2 Joystick Value Reference
| Status | ADC Value | Description |
|---|---|---|
| Center | ~2048 | Middle position (dead zone ±100) |
| Left/Up Extreme | 0 | Minimum value |
| Right/Down Extreme | 4095 | Maximum value |
Notes
- Dead Zone: Joystick center ADC value is ~2000-2100 (not exactly 2048); set ±100 dead zone
- Pin Selection: Must use ADC-capable pins (GPIO32-39)
- Sampling Rate: 50-100ms sampling interval recommended for control applications
- Calibration: Record center value on first use as offset compensation baseline
