I also did try the 14M code above, however, may have found why it does not work with our controllers - see below:
I also have an Arduino board, and by following the information at the link below, I was able to interface my controller to control two PWM outputs independently with the Y-axis of each joystick.
http://pspunch.com/pd/article/arduino_lib_gpsx_en.html
(However, there was a issue which I am still trying to sort out, see below.)
Note that he states on his site "Currently, all timings are designed to work only on PS2 controllers. PS1 controllers are designed to run at half the clock speed which I haven't adjusted to yet."
This means that if hippy's code above is only designed to work with PSOne controllers, it may not work with the wired/wireless PS2 controllers we have (as they run twice as fast - perhaps by default) - unless a further additions to the code are made. But I have a feeling it may not be possible to read the PS2 signals with the low-end PICAXEs, as they run too slow (however, I have not confirmed this).
I monitored the clock and data lines on my analogue CRO (could not get a digital one to trigger correctly!) to confirm that the signal I was getting was clean - and it was (data lines where perfect and in sync with the clock - just thinking about it, that confirms that the Arduino was giving accurate clock pulses! I now know where the trouble may be).
Unfortunately, I do not have a PSOne controller to compare the signal against. However, my PS2 wireless controller should work on a PSOne unit, but I am not sure if the clock speed is automatically lowered when this happens. I thought both units would have had the same signal, however, the PS2 can measure button pressure as well, and possibly has more accurate joysticks (from what I read on Wikipedia - which also states they are backwards compatible).
Also note how much more complex the (Arduino library) code is! But it 99% works for me (on some controllers, it may work 100%. Mine was from a (eBay) store in Hong Kong).
Anyway, I think in the end, I will just put a PICAXE 08M in the controller connected to the joystick, and interface that to a wireless Tx module, to send to another PICAXE controlling PWM for a motor. However, I will experiment a bit more with the Arduino before taking things apart.
I will try to get hold of an old PSOne controller and check the signals, when time permits, and post back about my results. Perhaps it would be easier if I was to take a picture of the CRO screen, post it here, and get hippy to confirm it is the same. I will see if I can do that within the next few days.
But for $14 AUD, the controller was good value any way - two joysticks (worth $4.50 AUD each from Little Bird, two motors, and possibly a multi-channel transceiver). I can use the joysticks in many other places.
Hopefully someone will work this out one day - however, I am not sure if it is possible with 4/8MHz parts, because the timings have to be accurate to milli (or nano) seconds.
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
Below is the conversation I had with the author of the Arduino (
http://arduino.cc and
http://arduino.cc/en/Main/ArduinoBoardDuemilanove) library (running at 16MHz):
The first email is at the bottom. Start from there.
----------------------------------------------------------------------------------------
If you look at the end of GPSX.c, you will find two functions,
"psx_cmd" and "psx_read_write_byte".
psx_cmd sends the commands to the controller.
psx_read_write_byte is called from psx_cmd to read one byte of response
from the controller at a time.
--------------
You may know much more about micro processors than me so this may be
redundant...
What goes on is that the controller receives a "clock" signal from the
Arduino which is represented in a form of one of the pins alternating
between high and low.
That is the primary reason you see a series of commands in the following
order.
1. digitalWrite(CLK_PIN, LOW) <-- Generate a clock signal for the
2. digitalWrite(CLK_PIN, HIGH) <-- controller to send the next bit
3. digitalRead(DAT_PIN) <-- Read the bit output from the controller
--------------
Between the two digitalWrite and digitalRead, you will see
delayMicroseconds( clk_half_cycle[psx_type] );
If you open GPSX.c and search for keyword "delayMicroseconds", you will
find other locations where waits are used to adjust timings and waits.
To answer your question on using decimal points rather than whole
numbers, whether it is valid or not depends on what documents on
delayMicroseconds say.
Also note that the wait time is not accurate (usually longer than what
you specify) as there is over head to calling the functions.
I hope this is of some use.
> Hi,
>
> Thanks for your reply.
>
> I used a CRO to check the signal from the wireless receiver, and it is
> fine - when the left joystick is pushed up, it stays constant in value.
>
> However, I think as the Y-axis signal for the left joystick is the last
> one sent, the program in the Arduino may be getting tricked on the last
> clock signal - it is just a matter of nano/milliseconds I think.
>
> You are correct that the best thing to do is to try another controller.
> I did try adjusting the timings, however, this made this worse - the
> joysticks would not respond at all. Can you put number like "1.5" in
> these fields, or whole numbers only? Also, what exactly to these numbers
> control?
>
> From Danny
>-----------------------------------------------------------------------
> > Date: Fri, 26 Mar 2010 13:35:39 +0900
> > From:
> > To:
> > Subject: Re: PS2 Interface For Arduino - Question
> >
> > Hi Danny,
> >
> > It is always a pleasure to know there are ones making use of my work.
> >
> > Unfortunately, I do not have a straight forward answer for you, but I
> > have some hints.
> >
> > The library has some adjustable figures regarding synchronization
> > timings. Default settings were chosen from trial & error rather than
> > measurement. In the process of setting these figures, I've found some
> > controllers returning incorrect values only for specific keys, rather
> > than malfunctioning or not responding at all... this sounds like your
> case.
> > Although I've also suspected noise in the power supply at one point,
> > after all the debugging I have concluded that some controllers are
> > simply more timing critical than others... after all, there are designed
> > only to run perfectly on a hardware with specific specs.
> >
> > I have two things in mind you may want to try.
> > 1)
> > The communication timing can be adjusted by the following line.
> >
> > -- GPSX.c, line 29.
> >
> > static unsigned char clk_half_cycle[] = { 2, 1}; // nsec
> >
> > The values now set to 2 and 1, can be replaced with any figure between 0
> > to 5, or perhaps higher.
> >
> > 2)
> > Simply try another controller.
> >
> > As mentioned, I have a controller (non Sony) which, while works fine on
> > my PS2 up till today, never gave me the desired stability with my
> library.
> >
> > This may be an easier way out.
> >
> > Good luck with your project, and please feel free to share any further
> > discoveries.
> >-----------------------------------------------------------------------
> > > Hi,
> > >
> > > I am using the library on your website (GPSX), to control PWM to two
> > > LEDs, depending on the Y state of the joysticks on my wireless PS2
> > > controller.
> > >
> > > My code is working as expected, however, when I push the left joystick
> > > right up to its top position, rather than outputing a constant value of
> > > 0, it outputs a random value every few seconds (between 0 and 255),
> > > causing the LED to blink randomly depending on the value read (it
> should
> > > stay off at this position). Are you aware of any bugs/issues with your
> > > library? The right joystick is working fine with both X and Y
> positions.
> > > The left joystick is working fine sensing X positions, and the lower Y
> > > range is sensing fine - the problem only occurs at the topmost Y
> > > position. The device I am using is not an official Sony controller,
> just
> > > something I got from eBay. It works with my PS2 well.
> > >
> > > I will attach it to a CRO tomorrow, to see what's going on. I have
> clean
> > > power supply lines, and the board is working as expected - I am using
> > > the Arduino Duemilanove.
> > >
> > > The digital input buttons are all working too.
> > > _
> > > Below is my code:_
> > >
> > > #include <math.h> //if I don't include this, I get a compile error
> > > #include <GPSXClass.h>
> > >
> > > int ledPin = 9;
> > > int ledPin2 = 10;
> > >
> > > void setup()
> > > {
> > > PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_LOCK);
> > > PSX.motorEnable(PSX_PAD1, MOTOR1_ENABLE, MOTOR2_ENABLE);
> > > }
> > >
> > > void loop()
> > > {
> > > PSX.updateState(PSX_PAD1);
> > > analogWrite(ledPin,ANALOG_LEFT_Y(PSX_PAD1));
> > > delay(50);
> > > PSX.updateState(PSX_PAD1);
> > > analogWrite(ledPin2,ANALOG_RIGHT_Y(PSX_PAD1));
> > > delay(50);
> > > }
> > >
> > > Thanks for providing the library; it is the best one I have used so
> far.
> > > From Danny