I am trying to set up a test to connect the PSX (older digital only version) to Arduino and have it turn on LEDs depending on what is pressed. Part of it is working, directional and start button. The 4 action buttons are not doing anything.
I used serial.println to read the data, the buttons on controller are working and is being read so I know it is not a problem with the controller. But for some reason the 4 buttons are not turning on the LEDs. The number value for the 4 buttons are correct yet I am wondering if I missed something somewhere.
Here's the code:
/* PSX Controller Decoder Library (Psx.pde)
Written by: Kevin Ahrendt June 22nd, 2008
Controller protocol implemented using Andrew J McCubbin's analysis.
http://www.gamesx.com/controldata/psxcont/psxcont.htm
Shift command is based on tutorial examples for ShiftIn and ShiftOut
functions both written by Carlyn Maw and Tom Igoe
http://www.arduino.cc/en/Tutorial/ShiftIn
http://www.arduino.cc/en/Tutorial/ShiftOut
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Psx.h> // Includes the Psx Library
/* controller pinouts are:
1 2 3 4 5 6 7 8 9
-------------------------------
| o o o | o o o | o o o | (at the Controller)
\_____________________________/
1 DATA 5 Vcc
2 CMD 6 ATT
3 motor V+ 7 CLK
4 ground 9 ACK
3 motor v+ (rumble) is not used, 8 has no connection, and 9 ACK is not needed. 5 Vcc is intended to be 3.3v but 5v will be fine
*/
#define dataPin 2
#define cmndPin 3
#define attPin 4
#define clockPin 5
#define Up 0x0008
#define Down 0x0002
#define Left 0x0001
#define Right 0x0004
#define PsxSqr 0x0100
#define PsxTri 0x0800
#define PsxX 0x0200
#define PsxCrl 0x0400
#define Start 0x0010
/* not implemented yet
#define psxStrt 0x0010
#define psxR1 0x1000
#define psxL1 0x2000
#define psxR2 0x4000
#define psxL2 0x8000
*/
Psx Psx; // Initializes the library
unsigned int data = 0; // data stores the controller response
void setup()
{
Serial.begin(9600); // for monitoring within arduino, disable if not needed
Psx.setupPins(dataPin, cmndPin, attPin, clockPin, 10); // Defines what each pin is used
// (Data Pin #, Cmnd Pin #, Att Pin #, Clk Pin #, Delay)
// Delay measures how long the clock remains at each state,
// measured in microseconds. 10 is fine.
pinMode(A0, OUTPUT); //not enough digital out, using analog out as digital
//can set output for A1-A5 to handle Select, L+R buttons.
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT); // Establishes all 8 digital Pin 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
{
digitalWrite(6, data & Up );
digitalWrite(7, data & Down );
digitalWrite(8, data & Left );
digitalWrite(9, data & Right );
digitalWrite(10, data & PsxSqr );
digitalWrite(11, data & PsxTri );
digitalWrite(12, data & PsxX );
digitalWrite(13, data & PsxCrl );
digitalWrite(A0, data & Start );
//next 3 lines are for monitoring with arduino, to check if it's working or not
if (data>0) {
Serial.println(data);
}
}
}
The wiring are as:
Playstation Vcc and Ground are connected to common v and g, the 4 lines (described in the code box above) from controller to digital pin 2, 3, 4, and 5. Digital pins 6-13 and analog pin A0 are set as output, goes to anode lead of a LED. Cathode lead goes through a resistor to ground.