Playstation 2 Controller PS2x
A somewhat capable device. I was surprised to discover that all the play buttons are pressure sensed with and ADC output of 0 - 255 and a vibration motor that could provide useful feedback from the device under remote control.
The current state of all the buttons and joystick positions are read out with the help of the PS2X_lib producing a 20 byte block.
The first 3 bytes returned for my controller is FF795A, followed by 2 bytes that holds the button status, then 4 bytes for joystick position with the remaining bytes representing the ADC button pressure values.
There are cheaply available clones on Ebay and some slightly more expensive Sony branded. They can be had for $5 - $20AUD.
xClient
This WEMOS is configured as both a wifi client and websocks client running a modified version of PS2X_lib (PS2X_esp_lib).
The author experimented with using UDP as a lightweight protocol between the xClient and the xServer but was unable to achieve the desired performance.
websockets however is remarkably robust and fast.
The PS2x to xClient wiring is reasonably straight forward with only 1 pullup resistor.
The xClient attempts to connect to the a second WEMOS (aka xServer) that is acting as an wifi access point and websockets server.
Once wifi is up and the websocket session is established, xClient begins sending the 20 byte blocks of GamePad data to the xServer.
The xServer then outputs this to the serial port. The xServer sends heart beat packets that is used to flash a LED on the xClient to provide
quick status on connection state. If its falshing slowly there is a good chance that all is ok.
The PS2x Gamepad Plug is connected to a WEMOS D1 via a carrier board that has pins (extracted from a female D25 connector) aligned with the PS2x Plug. See Image)
Power consuption for the xClient with the PS2x connected was measured at 5v @ 80mA. The xClient continued to function standalone with 3.8v applied to the 5v input.
3 x AA Energiser or Varta in series batteries may last approx 8 hours.
I suspect this power consumption is poor compared with commercial wireless controllers as the PS2X would not have been optimised and wifi provides
good range at the cost of battery life. (Tests seem to indicate that the controller draws about 10mA which I thought was surprising low)
Future update will include a 20x2 LCD module to provide useful data sent back from the server. It could provide battery levels, temperature level
or other useful diagnostic information.
If desired, the code for the xClient can be modified to send the 20byte blocks to the Serial port that can be processed and sent to a virual joystick driver allowing
the PS2x to be used as a wired PC game controller.
xServer
The xServer is a second WEMOS D1 configured as a wifi Access Point. The default ip addr is 192.168.4.1.
The xServer has several I/O pins which can be configured for PWM etc and controlled as needed from the PS2x. In this example pin D1 is configured as
PWM out which is determined by the pressure applied to the Blue 'X' buuton
Other unused IO can be configured to respond to PS2x button presses.
The xServer also prints the 20byte blocks to the Serial port which can be used for debugging or processed with the python script to send commands to a
virtual joystick. This will allow PSX2 controller to be used as a wireless PC game controller.
The author used Mame running galaga to test the viability and proved to be quite playable.
PS2x as a PC Game Controller
To be used as a PC game controller a Virtual Joystick driver needs to be installed and mechanism to process the raw PS2x 20byte block.
See vJoy and pyvjoy_serial_mapper below.
vJoy Virtual Joystick Driver
vJoy is a virtual joystick driver that comes with a python library and associated dll file to allow joystick data to be easily sent to virtual joystick.
This could be used to automate player movements but here it is used to receive commnds from the PS2x. Various PC games could then be controlled using the PS2x controller
Setup:-
1. Install vJoySetup.exe
2. pip install pyvjoy - it creates C:\Python27\Lib\site-packages\pyvjoy
3. manually mkdir C:\Python27\Lib\site-packages\pyvjoy\utils\x86
4. copy vJoyInterface.dll to C:\Python27\Lib\site-packages\pyvjoy\utils\x86
If it still reports that it is unable to find vJoyInterface then edit _sdk.py line 21 as
sys.exit("Unable to load vJoy SDK DLL. Ensure that {} is present\n{}".format(dll_path, str(e)))
rerun example pyvjoy_example.py and it should report the exact path and filename that may help
Python Glue script
1. See pyvjoy_serial_mapper_v1.py a python script that reads the serial stream from the ESP8266 and converts to the required library calls to send the relevant commands to the Virtual Joystick
The script is based on pyvjoy_example.py and other objects gleaned from looking at the pyvjoy library
2. The script needs to be changed to reflect the comm port that is enumerated when the xServer WEMOS D1 is connected to the PC
PlayStation 2 Controller ESP8266 Library & Code
1.http://www.billporter.info/2010/06/05/playstation-2-controller-arduino-library-v1-0/ was the original libary source.
This project uses a modifed version of PS2X_lib that I called PS2X_esp_lib. I am not Zen with modifying libraries and as such I have done a bad job.
2. The original library I got from https://github.com/madsci1016/Arduino-PS2X