Lynxmotion PS2 V3 on BotBoarduino

As noted in a few threads, Lynxmotion recently released a new version of the PS2 controller (V3), which appears to have some issues with some of our programs on the BotBoarduino. For some this appeared to be improved by moving the PS2 off of the standard IO pins that we use in our programs (6-9).

Note: These also appear to be more sensitive to having the Buttons/LEDS enabled, so you need to make sure you remove the JA, JB, JC jumpers shown in #5 of the diagram on lynxmotion.com/images/html/build185.htm But you should leave the Pull up Resister jumper (JPU)

When I started testing the new PS2 on the BotBoarduino (and Teensy 3.1) I was seeing some issues where the first byte of the buttons was being slightly corrupted and the bit associated with the select button was coming on and off. This was both confirmed by my test program as well as Logic Analyzer trace. Sure helps to have a Logic Analyzer.

Simple Test Program:

[code]#include <PS2X_lib.h>

#if defined(MK20DX128) || defined(MK20DX256)
// For my testing on Teensy
#define PS2_DAT 2
#define PS2_CMD 3
#define PS2_SEL 4
#define PS2_CLK 5
#else
// Botboarduino…
#define PS2_DAT 6
#define PS2_CMD 7
#define PS2_SEL 8
#define PS2_CLK 9
#endif

PS2X ps2x; // create PS2 Controller Class

void setup()
{
Serial.begin(57600);
delay(5000); // give time to open monitor
int error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT); // Setup gamepad (clock, command, attention, data) pins
Serial.print("PS2 Init: ");
Serial.println(error, DEC);
}

void loop() {
ps2x.read_gamepad(); //read controller and set large motor to spin at ‘vibrate’ speed

Serial.print("PS2 Input: ");

Serial.print(ps2x.ButtonDataByte(), HEX);
Serial.print(":");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(" “);
Serial.print(ps2x.Analog(PSS_LY), DEC);
Serial.print(” “);
Serial.print(ps2x.Analog(PSS_RX), DEC);
Serial.print(” ");
Serial.println(ps2x.Analog(PSS_RY), DEC);
delay(125);

}
[/code]

Today I think I figured it out as a timing issue. I think I was able to solve it :slight_smile:

What you need to do is to edit the header file associated with the PS2 library. In my case it is:
C:\Users\Kurt\Documents\Arduino\libraries\PS2X_lib\PS2X_lib.h and change the line:

#define CTRL_BYTE_DELAY 3

to:

#define CTRL_BYTE_DELAY 4

Note: if your header file has section for AVR versus PIC32, make sure to make the change in the AVR section.

Edit: I also had to change the timings in the 2nd section of the header file in order to get it to work on the Teensy 3.1. Although I have not tested it, the changes I made in this else clause is probably also needed for the Arduino Due and the Chipkit Pic32 processors.

I updated my fork of Bill Porters PS2 library with these changes: github.com/KurtE/Arduino-PS2X

Kurt

Thanks Kurt for the help! We’ll give this a try on our test robots and let you know how it goes!