| PS2 Robot
Control: Establishing Communication.
03.30.04 By Beth Frye. Establishing a fast and reliable connection between a Sony-brand PS2 controller and the Basic Stamp 2 processor. Note, the Basic Stamp 2 processor cannot properly read the left vertical joystick. |
![]() Too cool! |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Step 1.
Plug in the PS2 cable as shown. Be extremely
careful to observe polarity on the power connector. Black is ground and
yellow is +5vdc. The black wire is actually the red/shield with black heat
shrink covering them. Figure 1-1 shows what each of the PS2 cable wires
are.
|
![]() Figure 1-2. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Step 2. Copy & paste the program from below into the editor and program the Basic Stamp 2. After the program is running, choose COM1 (item #1 in Figure 2-1 below). Change the Baud Rate to 9600 (item #2). Note, you will need to turn the controller's Analog mode on. If all is well, you should see numbers similar to the ones shown. Refer to Table 2-1 for a description of the bytes returned by the PS2 controller. Note that items 12 and 13 are the Digital representation of button presses. Refer to Table 2-2 and 2-3 for a Bit representation of button presses. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Table 2-2 and 2-3
illustrate which bits go low when the corresponding button is pressed. The arrow buttons are on what is commonly called the "D-Pad," which is the button pad on the left. L3 and R3 are the little-known Left and Right joystick buttons; trigger these by pressing down on the joysticks. R1, R2, L1, and L2 are the "shoulder buttons," that is, they are located on the controller's "shoulders." |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The
two analog joysticks on a Sony-brand controller will not neatly return to
a middle value of 128. The following value ranges are what the joysticks
have been known to return to.
If you need extreme accuracy with the analog joysticks, go with a Madcatz-brand controller. I've used a wireless Madcatz Lynx controller (coincidence, really!) with perfect analog joystick accuracy. They always returned to the middle value of 128. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Step 3. Code by Jim Frye. This is a demonstration program that will report the push button and joystick information to the debug screen. Note that the green wire on the PS2 controller cable needs to have 7.2 vdc applied for this to work. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||