Pages: [1]   Go Down
Author Topic: Do I need to hook any PlayStation 2 Controller pins to PWM pins?  (Read 883 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm planning on buying this adapter for a PS2 controller so I can hook it up to my Arduino: http://www.lynxmotion.com/p-73-ps2-controller-cable.aspx. I will then use this library to interface with it: http://www.billporter.info/playstation-2-controller-arduino-library-v1-0/

In the example code that came with the library, some of the pins are hooked up to digital IO pins that support PWM. Here is the line:

Code:
ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

On the Uno, pins 10 and 11 support PWM.

Upon doing a little more research, I found this other guide: http://www.wegmuller.org/arduino/Arduino-Playstation_gameport.html. The author hooks up 'command' to a PWM pin, but 'attention' to a non-PWM pin.

Is it just a coincidence that 'command' and 'attention' are plugged into PWM pins in the first example? My best guess is 'yes', since I doubt that the PS2 controller communicates with an analog signal. I ask this question because I'm creating my own Arduino shield for a special project, and I want to get it right the first time.

Thank you in advance,
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It appears to me that the PS2 controller uses SPI.  The hardware SPI pins are:

10 SS (Slave Select) -> ATT (Chip select)
11 MOSI (Master Out Slave In) -> Command
12 MISO (Master In / Slave Out) <- Data
13 SCK (Serial Clock) -> Clock

Hooking things up this way will allow you to use the SPI library and get very fast speeds.  Even if you use the other hardware SPI pins you can use any digital output pin for the Slave Select / ATT signal.  The only requirement is that Pin 10 be set as an output.   

If you don't need high speeds it is possible to do "Software SPI" using any four digital pins.  You'd have to look around for example code.  It's not much more complex than using a shift register.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, how could I have missed that!

I'm going to assume that the PS2X library uses software SPI. Reading through the source code (way over my head), it doesn't import the SPI library but it does a lot of operations with registers.

Thanks for your help!
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just looked at the library code and it appears that it does do software SPI so any four I/O pins should work.  Shouldn't need to use the PWM pins if you want to save those for something else.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: