Do anybody ever managed to interface a PS2 joypad?

Hi everibody, I'm (still) trying to interface a Ps2 controller to the arduino; I would like the idea of using a wireless one, that allows to build RC robots 'for free' (only one arduino, no xBee needed, ecc.).

I posted a 'request for help' (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253363499) quite long time ago, but I got no replies at all... Now i see another guy (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254971312) is getting in the same troubles as mine, there are videos on youtube that demonstrates it can be done, may I am just stupid?

First - the setup: Mac OS X 10.5.8, Arduino2009/168 or Roboduino nano/168, either with the same results. Various versions of the IDE, with various results.

Second - the libraries: both the PSX Library (Arduino Playground - PSXLibrary) and PSX Analog (Arduino Playground - AnalogPSXLibrary) from the playground won't compile under arduino-0017, giving the errors explained in the previous posts; sounds like something is wrong in the file stdio.h. I managed to compile them under arduino-0011, that is quite obsolete aniway. I also tried to compile the libraries on arduino-0017 on a Windows XP machine with the same errors.

What sounds strange to me is that the author of PSX Analog has posted the code on his site (http://www.kieranlevin.com/index.php?option=com_content&view=article&id=50:ex-1pantilt&catid=35:projects&Itemid=54) - but not the schematic - on 10 March 2009. (?)

Third - the hardware: the playground pages doesn't give any information or schematic. Sounds like this (http://www.curiousinventor.com/guides/ps2) is the most credited source, and as of I can understand no extra hardware is needed, just a pull-up resistor on the 'data' line. I tried several values with no success. Wandering on google, I found another page (http://www.wegmuller.org/arduino/Arduino-Playstation_gameport.html), with some 'working' (at least, it compiles) code, but a completely different hardware setup!

I'm starting to get confused, and I don't know where the problem could be...

I got it to compile for me. here is how

Seems i was getting an error in math.h not stlib.h. (same error almost)

I commented out. double round in math.h and it compiles. I wont be able to test it to make sure till my ps2 controller get here(its in the mail).

But it seems the Arduino ide has round as a key word and that is interfering with the compiling of this.

I just managed to compile the library. I used mac's spotlight to search in the package, and there are few files with the same name spreaded around the package contents...

By the way, I had to comment out:

extern int abs(int __i) __ATTR_CONST__; ->from stdlib.h and
double round (double __x) __ATTR_CONST__; -> from math.h

both located in: Arduino/Contents/Resources/Java/hardware/tools/avr/avr/include

Just the time for a coffee and I'm going to reconnect the joypad.

edit: the modification oh the standars .h files seems to not affect the functionality of abs() and round() functions. I tested the instruction

Serial.print(abs(round(-5.3)));

and it prints '5' as expected.

thats cool. Now i wait to see if the pad works then we are in business.

I tried again, with no sucess.

This time seems that sort of communication happens, but only from arduino to the joypad. The Psx.initcontroller(psxAnalog); instruction in the setup() is supposed to lock the joypad in 'red' mode (analog led on) an in fact it locks, but off. I can change the status of the LED by holding down reset on the arduino and pressing the button on the joypad. If the joypad was on when the sketch starts it stays locked on and vice versa. I couldn't retrieve any value in both modes.

I tried with or without the pull-up resistor on data pin, and looking at the code sounds like the Psx.setupPins function activates the internal pull-up aniway.

That's the schematic I used:

D08 (AtMega pin 14) - Data Pin - Brown Wire
D09 (AtMega pin 15) - Command - Orange Wire
D10 (AtMega pin 16) - ATT pin - Yellow wire
D11 (AtMega pin 17) - Clock pin - blue wire
GND - Black wire
+5V - Red wire

PS2 Controll Pins are hard coded in the library and i dont
see a need to change them for my use but you need to change to this:
Digital Pin 3 to PS2 9 (green) acknowledge
Digital Pin 4 to PS2 7 (blue) clock
Digital Pin 5 to PS2 6 (yellow) attention
Digital Pin 6 to PS2 2 (orange) command
Digital Pin 7 to PS2 1 (brown) data

or edit the .cpp for the values

IT WORKS!

Blame ingenuity!!! The pin numbers in the example sketch does not refer to AtMega pins, just arduino pins!!! analog0 to analog3! WOW!

No extra hardware, and no pull-up resistor needed.

Edit: i changed the motor values in PsxAnalog.cpp and they work!! I'll add a function for settting them from the sketch and share an how-to soon. Bye!!

Edit 2: The bytes for feedback control are already available: Psx.Motorsmall and Psx.Motorlarge. Just write the desired values, and at next call of Psx.poll() they will be sent to the joypad.

I got my controller and it also works.. no issues.. awesome.

Hi,
I´m new here, and I tried to read the data of a Playstations2 Controller with the Arduino but didint work. I tried your code and it dosen´t work. I dont know what I am doing wrong. Did you used some IC, our you just plugged the controller directly in to the arduino? Do you have some schematic to use whith this code? I will be glad for your answer.

in the first post are some links they show the wiring layout.

I used the GPSX library and it worked for me and i just plug it right into the board.

Hi,
I tried the PSX.zip example and the AnalogPSX example and I didn´t get it.
I´m trinng to print in the screen with the Serial.print and always returns 0.
Can you sand me the code that you used with this pins?PS2 Controll Pins are hard coded in the library and i dont
see a need to change them for my use but you need to change to this:
Digital Pin 3 to PS2 9 (green) acknowledge
Digital Pin 4 to PS2 7 (blue) clock
Digital Pin 5 to PS2 6 (yellow) attention
Digital Pin 6 to PS2 2 (orange) command
Digital Pin 7 to PS2 1 (brown) data

I tried this code:
#include <stdlib.h>
#include <math.h>
#include <Psx.h> // Includes the Psx Library

#define dataPin 2
#define cmndPin 3
#define attPin 4
#define clockPin 5

#define LEDPin 13

Psx Psx; // Initializes the library

unsigned int data = 0; // data stores the controller response

void setup()
{
Psx.setupPins(dataPin, cmndPin, attPin, clockPin, 10); // Defines what each pin is used
Serial.begin(9600); // (Data Pin #, Cmnd Pin #, Att Pin #, Clk Pin #, Delay)
// Delay measures how long the clock remains at each state,
// measured in microseconds.

pinMode(LEDPin, OUTPUT); // Establishes LEDPin as an output so the LED can be seen
}

void loop()
{
data = Psx.read(); // Psx.read() initiates the PSX controller and returns
// the button data

Serial.println(data);
if (data & psxR2) // If the data anded with a button's hex value is true,
// it signifies the button is pressed. Hex values for each
// button can be found in Psx.h
{
digitalWrite(LEDPin, HIGH); // If button is pressed, turn on the LED
}
else
{
digitalWrite(LEDPin, LOW); // If the button isn't pressed, turn off the LED
}
}