Interfacing PS2 Wireless Controller With a PIC Microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by daveb850, Oct 24, 2018.

  1. daveb850

    Thread Starter New Member

    Oct 24, 2018
    1
    2
    I've posted this thread because I recently completed a robotics project that used the Wireless PS2 Controller with a PIC Microcontroller. When I looked online, I found it surprisingly difficult to find any reliable code. There are examples using an Arduino but very little that work for the Wireless PS2 controller with a PIC MCU.

    Kok Chee Khean produced an excellent example for a Wired PS2 controller.

    Unfortunately despite saying in its title wired and wireless, it does not work for the wireless PS2. The reason is because the timing is not tight enough, the wireless controller will time out if its not interfaced with quickly enough. Also another reason is because you need to take the CLK line low AFTER setting CMD. You can get away with it with a wired controller, but not for wireless.

    Anyway after much hair pulling and late evenings, I eventually figured it out and got the code working correctly. I thought I'd share this online, hopefully saving someone else the hassle I had in getting it to work.

    This code is based on Kok's, but with the necessary changes to make it work with a Wireless (and Wired) PS2 controller.

    I've used a PIC16F1717 MCU, but you could adapt this for any PIC or other MCU if needed. The compiler used is Microchips XC8.

    The PIC is connected to LED's which light if a button is pressed on the PS2 controller. There are also connections to the controller receiver. See the circuit diagram.

    See also the connector and its wires. Note that some third party PS2 controllers may use different wire colors.

    The grey vibration power supply wire, and the white (unknown) wire are not used. If you were using a wired controller the grey vibration wire would need power for the PS2 motors to work.

    Wires used are:

    Brown DATA wire is connected to a PIC Input, and pulled up to VCC via a 10k resistor.
    Orange COMMAND wire is connected to a PIC Output.
    Black is the ground wire.
    Red is the power wire. This should ideally be 3.3V but my project used 5V and it caused no damage.
    Yellow ATTENTION wire is connected to a PIC Output.
    Blue CLOCK wire is connected to a PIC Output.
    Green ACKNOWLEDGE wire is not connected to the PIC but straight to VCC via a 10k pull up resistor.

    The attached code is heavily commented, making it easy to follow.
     
    nsaspook and DNA Robotics like this.
Loading...