Professional Documents
Culture Documents
I
was designing a little box with some inputs I was hoping to use as well as are very sophisticated, well-designed
joysticks and a few buttons to control a heap of other buttons and features and robust pieces of equipment that
a project of mine one day when it far beyond what I needed. And they are ideal for using as an interface for
occurred to me that it looked familiar. were cheaper than the small handful of mechatronics projects. Even though the
I suddenly asked myself why I was components I was going to need to buy PlayStation 2 game console is now a
trying to build what was essentially to make my own. rather outdated piece of equipment, the
a game controller from scratch when There has been millions of dollars PlayStation 2 controller clones are still
there were perfectly good game poured into the development of the made and can be purchased through
controllers around that included the PlayStation controllers and so they Trade Me extraordinarily cheaply.
Connecting the
Data
GND
Clock
3.3V
controller
There are two options for connecting
the controller to the Arduino. The
method for masochists is to cut off the The example
connector and connect the wires into sketch included with
a row of terminal headers or directly the library is a great
solder them to some other plug. demonstration of the
The wire colours in the PlayStation capabilities of the library and
diagram may help you identify which makes use of all of the features
wire is which (the 7V-9V rumble motor of the PlayStation 2 controller. The
supply wire is often grey in colour). A demonstration that is outlined in this
better option is to retain the plug and The software side article is not quite as sophisticated but
find a suitable socket. In stark contrast Thanks to one Bill Porter an easy-to- covers the essentials needed to use
to the ease of purchasing a controller, use library is available which will allow a PlayStation 2 controller to actuate
finding sockets is much harder. It users to use a PlayStation 2 controller motors, servos and switch things on
is possible to purchase sockets and (or even a Guitar Hero controller) with and off.
breakout boards from the Robotshop an Arduino. You can find it through To use the library in an Arduino
(http://w w w.robotshop.com/en/ Bill Porter's website: “The Mind of Bill Sketch, it needs to be called using the
ps2-connector.html) in America. Porter”—http://www.billporter.info/. following commands:
Unfortunately there are no local More specifically here is the link to his #include <PS2X_lib.h>
suppliers. The cheaper alternative page with links to his library—http:// PS2X ps2x;
PSB_L2 PSB_R2
PSB_L1 Lower Button PSB_R1 Lower Button
Upper Button Upper Button
PSB_PAD_RIGHT PSB_START
4 1 2 3
PSB_PAD_LEFT PSB_RED
PSB_PAD_DOWN ANALOG
PSB_BLUE
PSS_LX PSS_RX
PSS_LY PSS_RY
PSB_L3 PSB_R3
Press on Left Stick Press on Right Stick
Electronic Speed
Controller (ESC)
470μF
Battery
Servo 2
Servo 1 7.2V NiCd or 11.1V LiPo
Steering Servo to Suit ESC
Transistor
BD681
E C B
1k Ω
5V from Arduino
1k Ω 1k Ω
3.3V from Arduino
Data
Command
GND
3.3V DC
Attention
Clock
4 1 2 3
ANALOG
3.3V output to PS2 red pin int PlyStnRStickUpDn = 0; //Value read off
5V output to 1K ohm pull up resistors for the PS2 Right Stick up/down.
PS2. int PlyStnRStickLtRt = 0; //Value read off
Pin D02 to PS2 brown pin (data) the PS2 Right Stick left/right
Pin D03 to PS2 yellow pin (attention) int PlyStnLStickUpDn = 0; //Value read off
Pin D04 to PS2 orange pin (command) the PS2 Left Stick up/down
Pin D05 to PS2 blue pin (clock) int PlyStnLStickLtRt = 0; // Value read off
the PS2 Left Stick left/right
Pin D06 to ESC Signal Pin
Pin D07 to Steering Servo Signal pin int ESCSetting = 90; //Setting for the ESC
Pin D08 to Servo 1 Signal pin (degrees).
Pin D09 to Servo 2 Signal pin int StrServoSetting = 90; //Setting for the
Steering Servo
Pin D13 to LED Transistor Base int ServoN1Setting = 90; //Setting for the
Servo 1
The ESC servo connection supplies 5.6V to int ServoN2Setting = 90; //Setting for the
the servos. Servo 2
void setup()
The coding pulls on the PS2X library developed by {
Bill Porter. ps2x.config_gamepad(5,4,3,2, false, false);
See www.billporter.info for the latest from Bill Porter //setup pins and settings: GamePad (clock,
and to download the library. command, attention, data, Pressures, Rumble)
//We have disabled the pressure sensitivity
The controls used for this sketch are: and rumble in this instance.
Right Stick - X-axis = Steering Servo left/ pinMode(LEDpin, OUTPUT); //Sets the LEDpin
right, Y-axis = ESC forward/backward to output
Left Stick - X-axis = Servo 2 left/right,
Y-axis = Servo 1 left/right LEDHdlts = false; //Sets the Headlights
Triangle = Toggle the LED to off
SteeringServo.attach(7);// attaches the
*/ Steering Servo to pin 7
ServoN1.attach(8);// attaches the Servo 1
#include <Servo.h> //For driving the ESCs to pin 8
and Servos ServoN2.attach(9);// attaches the Servo 2
#include <PS2X_lib.h> // Bill Porter's PS2 to pin 9
Library ESCcontrol.attach(6,150,2250);// attaches
the ESC to pin 6
PS2X ps2x; //The PS2 Controller Class //The ESC attachment command above also
Servo SteeringServo; //Create servo object includes the signal settings
representing SteeringServo //for the maximum and minimum that the ESC
All things going well, when you neutral position. The ESCcontrol. then you should not have any problems.
connect this up and connect in the write(90); line in the Setup routine
battery, you should be able to push the sets the throttle to neutral to allow Final remark
triangle button to light the LED and the ESC to initialise. If you are using With an input device as sophisticated
move the joysticks to move the servos a Radio Control Aircraft ESC you will as the PlayStation 2 controller there
and run the motor. need to initialise it at 0 degrees. are a wealth of different mechatronics
If it does not automatically go into Depending on the quality of the projects that they can interface with.
Analog Mode (as indicated by the read Arduino you are using you may The PS2X library makes it very easy
light on the controller), press the Analog need to have the USB connected to to access the full range of functions
button. This will enable the joysticks on the computer to power the Arduino. available from the PlayStation 2
the controller and set things going. Ordinarily the Arduino should be able controller. Why reinvent the wheel
The circuit and sketch are designed to run on the 7.2v being supplied from when there are already ultra-high
with a car ESC in mind. This means a the NiCad battery. If you have an 11.1V performance mags available for cheaper
servo command of 90 degrees is the LiPo battery and ESC designed to suit it prices than a couple of components.