Trying to use the PS2X library

Status
Not open for further replies.
FYI - I am using my own fork of Bill Porters PS2X library on Teensy 3.1. I have tried it out with V2 and V3 of the Lynxmotion PS2 controllers. I am using 1.18 on Windows 7 64 bit.
If you wish to take a look at my fork, it is up at:
https://github.com/KurtE/Arduino-PS2X


Thank's for your alternative that works pretty well when it connect with my teensy 3.2 and a wireless game pad PS2X style from Joy-it ( https://joy-it.net/en/products/SBC-WLGamepad)

The starting connection is random to me. Maybe it come from the remote receiver not the code, I have to try with an orther devise to figure it out.
But when it works it works nice.
NewButtonState is very welcome to me as a noob coder.
 
This Arduino-PS2X library form KurtE also works great on teensy 3.5 !

A little add to the library if KurtE come through here.
Code:
----------------------------------------------------------------------
                            PS2 CONNECTOR
________________________________________________________________________
\     1      2      3   |   4      5      6    |   7      8      9     /
 \    o      o      o   |   o      o      o    |   o      o      o    /
  \_brown__orange__grey_|_black___red___yellow_|_blue___white__green_/
     MISO   MOSI          Ground  3.3v   CS 0     SCK

*/
 
And other contribution for beginner like me:


If your PS2X controler doesn't connect well/randomly (just a guess : propably those who are wireless as mine):
I don't know if I'm right but the code seems to try only once to connect to the gamepad before to tell which one is it or give an error.
I though that maybe it just needed more time or try, and this solve it
This code will force waiting for a controler. In other words it will read again and again the signal until it recognize it as intended. So doing this will never return any error as it kind of by pass error case.
In the SETUP:
Code:
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 [B]while( error != 0){
  Serial.println("Waiting");
  error = ps2x.config_gamepad(13,11,10,12, true, true);
  delay(100);[/B]
    Serial.println("Waiting *");
  error = ps2x.config_gamepad(13,11,10,12, true, true);
  delay(100);
    Serial.println("Waiting **");
  error = ps2x.config_gamepad(13,11,10,12, true, true);
  delay(100);
    Serial.println("Waiting ***");
  error = ps2x.config_gamepad(13,11,10,12, true, true);
  delay(100);
    Serial.println("Waiting **");
  error = ps2x.config_gamepad(13,11,10,12, true, true);
  delay(100);
    Serial.println("Waiting *");
  error = ps2x.config_gamepad(13,11,10,12, true, true);
  delay(100); 
 [B]}[/B]

Only the bolded line is need, others are just here to make the Serial.println more funky and visible in the monitor.

RUMBLE WHEN PAIRING : to know the controler is well paired without using serial monitor:
Before to solve my previous problem and because it was uncertain, I wanted a way to know when it is paired or not in my real final use without connection to PC and the serial monitor.
My first idea was to light a led when OK.
But I finally found so more natural to simply use the rumble when the remote is paired ! Here the code to do it !
Code:
if(error == 0){
   Serial.println("Found Controller, configured successful");
   Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
   Serial.println("holding L1 or R1 will print out the analog stick values.");
   Serial.println("Go to www.billporter.info for updates and to report bugs.");
   [B]for(int i = 0; i < 100; i++){
        ps2x.read_gamepad(false, vibrate);
        vibrate = 255;
        delay(10);
        }[/B]
 }
 
Status
Not open for further replies.
Back
Top