Putting robotics at your service™

Free shipping on orders over $200

Wired PS2 Controller Works, Wireless Controller Does Not

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 4 posts ]

New ( offline )
Posts: 1
Posted: 2010-02-18 19:18 
Hello,
I have very successfully controlled by robot with an official PS2 controller, but when I connect a wireless controller, it doesn't work. My setup is as follows:
Microcontroller: OX2 by pololu (with ATmega644 programmed in C) at http://www.pololu.com/catalog/product/738
Wired controller: Official Sony PS2 controller
Wireless controller: Official PS2 controller (licensed by Sony to Katana) and Logitec PS2 controller

Relevant wiring diagram section


I can't figure out why the wired controller would work by the wireless one will not. Any help would be greatly appreciated!

Code:
//**********************************************************

//Define pins
//PD0 and PD1 are reserved for USART
#define PS2_DATA   PA0   //data
#define PS2_CMD   PA1   //command
#define PS2_ATT   PA2   //attention
#define PS2_CLK   PA3   //clock

//Define constants for PS2 communication
#define PS2_START_CMD      0x01
#define PS2_REQUEST_DATA   0x42
#define PS2_CONFIG_MODE      0x43
#define PS2_CONFIG_MODE2   0x01
#define PS2_CONFIG_ANALOG   0x44
#define PS2_CONFIG_EXIT      0x00
#define PS2_SET_ANALOG      0x01
#define PS2_LOCK_ANALOG      0x03
#define PS2_DIGITAL_MODE   0x41
#define PS2_ANALOG_MODE      0x73
#define PS2_NO_CMD      0x00
//Define the locations of the different buttons in the data bytes

//Data byte 1 (PS2CMD1)
#define PS2_SELECT   0
#define PS2_L3      1
#define PS2_R3      2
#define PS2_START      3
#define PS2_UP      4
#define PS2_RIGHT      5
#define PS2_DOWN      6
#define PS2_LEFT      7
//Data byte 2 (PS2CMD2)
#define PS2_L2      0
#define PS2_R2      1
#define PS2_L1      2
#define PS2_R1      3
#define PS2_TRIANGLE   4
#define PS2_CIRCLE   5
#define PS2_X      6
#define PS2_SQUARE   7

//function prototypes
void PS2Init(void);
void PS2Get(void);
static unsigned char PS2ReadSend(unsigned char command);

//variables
   unsigned char PS2TEMP = 0x00;
   unsigned char PS2ID   = 0xFF;
   unsigned char PS2CMD1 = 0x00;
   unsigned char PS2CMD2 = 0x00;
   int RightHorizontal = 0x00;
   int RightVertical = 0x00;
   int LeftHorizontal = 0x00;
   int LeftVertical = 0x00;


//Function definitions


//*********************************************************************
//BEGIN PS2Init()   
//Purpose: Initializes the pins for PS2 communication and sets the
//controller into analog mode and locks it   
//Input: NONE
//Output: NONE
//*********************************************************************

void PS2Init(void)
{
   DDRA  |= (1<<PS2_CLK)|(1<<PS2_ATT)|(1<<PS2_CMD);
//set pins as outputs
   PORTA |= (1<<PS2_CLK)|(1<<PS2_ATT)|(1<<PS2_DATA);   
//start clock, attention high, pull up resistor on DATA

while(PS2ID == 0xFF)   //loop until controller present
{
   PORTA &= ~(1<<PS2_ATT);   //pull attention low
   PS2TEMP =    PS2ReadSend(PS2_START_CMD);
   PS2ID   =    PS2ReadSend(PS2_NO_CMD); //check for controller ID
   PORTA |= (1<<PS2_CLK);          //clock high
   PORTA |= (1<<PS2_ATT);          //attention high
}

//go into command mode
   PORTA &= ~(1<<PS2_ATT);         //pull attention low
   PS2TEMP =    PS2ReadSend(PS2_START_CMD);
   PS2TEMP =    PS2ReadSend(PS2_CONFIG_MODE);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PS2TEMP =    PS2ReadSend(PS2_CONFIG_MODE2);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PORTA |= (1<<PS2_CLK);         //clock high
   PORTA |= (1<<PS2_ATT);         //attention high


//set controller to analog mode and lock
   PORTA &= ~(1<<PS2_ATT);         //pull attention low
   PS2TEMP =    PS2ReadSend(PS2_START_CMD);
   PS2TEMP =    PS2ReadSend(PS2_CONFIG_ANALOG);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PS2TEMP =    PS2ReadSend(PS2_SET_ANALOG);
   PS2TEMP =    PS2ReadSend(PS2_LOCK_ANALOG);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PORTA |= (1<<PS2_CLK);         //clock high
   PORTA |= (1<<PS2_ATT);         //attention high


//exit configuration mode
   PORTA &= ~(1<<PS2_ATT);         //pull attention low
   PS2TEMP =    PS2ReadSend(PS2_START_CMD);
   PS2TEMP =    PS2ReadSend(PS2_CONFIG_MODE);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);
   PS2TEMP =    PS2ReadSend(PS2_NO_CMD);      
   PS2TEMP =    PS2ReadSend(0x5A);   
   PS2TEMP =    PS2ReadSend(0x5A);
   PS2TEMP =    PS2ReadSend(0x5A);
   PS2TEMP =    PS2ReadSend(0x5A);
   PS2TEMP =    PS2ReadSend(0x5A);
   PORTA |= (1<<PS2_CLK);         //clock high
   PORTA |= (1<<PS2_ATT);         //attention high

} // END PS2Init()
//*********************************************************************
//BEGIN PS2Get()
//Purpose: Gets the PS2 controller configuration. Returns (as a global
//variable) the joystick positions as a value from -255 to +255
//Input: NONE
//Output: NONE
//*********************************************************************
void PS2Get(void)
{
   PORTA &= ~(1<<PS2_ATT);            //pull attention low
   PS2TEMP =    PS2ReadSend(PS2_START_CMD);
   PS2ID   =    PS2ReadSend(PS2_REQUEST_DATA);
   PS2TEMP =   PS2ReadSend(PS2_NO_CMD);
   PS2CMD1 =    ~PS2ReadSend(PS2_NO_CMD);   //invert output so high
//means button pressed
   PS2CMD2 =    ~PS2ReadSend(PS2_NO_CMD);   //invert output so high
//means button pressed
   RightHorizontal =    PS2ReadSend(PS2_NO_CMD);
   RightVertical    =    PS2ReadSend(PS2_NO_CMD);
   LeftHorizontal  =    PS2ReadSend(PS2_NO_CMD);
   LeftVertical   =    PS2ReadSend(PS2_NO_CMD);
   PORTA |= (1<<PS2_CLK);            //clock high
   PORTA |= (1<<PS2_ATT);            //attention high

} //END PS2Get()

//*********************************************************************
//BEGIN PS2ReadSend()
//Purpose: The bitwise send command and read data function. This
//function is only to be called by the functions PS2Init() and PS2Get()
//and should never be called directly from the DRA code
//Input: PS2 commands
//Output: PS2 data
//*********************************************************************
unsigned char PS2ReadSend(unsigned char command)
//clock must be high before calling
{
   unsigned char PS2Data = 0x00;
   for(int i=0;i<8;i++)
   {
      PORTA &= ~(1<<PS2_CLK);      //set clock low      
      if(bit_is_set(command, i))   //is PS2 command bit i set?
         PORTA |= (1<<PS2_CMD);   //if yes set PS2_CMD bit
      else   
         PORTA &= ~(1<<PS2_CMD);   //if no clear PS2_CMD bit
      _delay_us(60);   //wait for PS2 controller to set data bit
      PORTA |= (1<<PS2_CLK);   //set clock high. Controller sets
                  //and reads on clock change
      if(bit_is_set(PINA, PS2_DATA)) //is PS2_DATA bit set?
         PS2Data |= (1<<i);   //if yes set PS2Data bit i
      else
         PS2Data &= ~(1<<i);   //if no clear PS2Data bit i
      _delay_us(60);                     //wait for PS2 controller to
   }
   _delay_us(300);   //wait for PS2 controller to acknowledge
   return PS2Data;
} // END PS2ReadSend()

//*********************************************************************



User avatar
Guru ( offline )
Posts: 4124
Posted: 2010-02-18 20:05 
You might need a pullup resistor on the clock and data lines.

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


User avatar
Guru ( offline )
Posts: 4912
Posted: 2010-02-18 20:28 
Hi Alan, He is enabling the pull-up resistor on the data line, which works fine for me on the Axon2 board which is an AtMega640 using webbotlib. Some in other thread: viewtopic.php?f=7&t=5876

I also have it working on the Atom Pro on IO pins 0-3 using the built-in as well, using H8 built in pull-up resistor.

I did not see anything obvious in the code. I have other code the is in a zip file on my debrat thread in the biped section that is working with the Lynxmotion wireless controller.

Some thoughts:

1) I have tried several different processors and code and languages and have never been able to get a logitech wireless ps2 to work. I have heard this from others as well. Most have luck with Madcatz and Lynxmotion...

2) Some controllers need the higher voltage pin connected. on the lynxmotion PS2 cable it is the green wire. I needed this earlier for the Sector 7 wireless controller.

3) You can have problems if you query the Ps2 controller to fast without a delay between queries. If you query to fast, the PS2 controller receiver does not have time to talk to the remote and the lights will blink and no data is update... Been there!

4) I often look at this site: http://www.curiousinventor.com/guides/ps2 when I am working on PS2 controller stuff.

That is all I can think of for now.


User avatar
Guru ( offline )
Posts: 4124
Posted: 2010-02-18 21:57 
Hi Kurt,

That's true, I missed that when I read his code. You've ran down a few other points, I didn't have time. I've just stuck with the Lynxmotion PS2, and I've already picked up a couple more XCVRS.

Alan KM6VV

kurte wrote:
Hi Alan, He is enabling the pull-up resistor on the data line, which works fine for me on the Axon2 board which is an AtMega640 using webbotlib. Some in other thread: viewtopic.php?f=7&t=5876

I also have it working on the Atom Pro on IO pins 0-3 using the built-in as well, using H8 built in pull-up resistor.

I did not see anything obvious in the code. I have other code the is in a zip file on my debrat thread in the biped section that is working with the Lynxmotion wireless controller.

Some thoughts:

1) I have tried several different processors and code and languages and have never been able to get a logitech wireless ps2 to work. I have heard this from others as well. Most have luck with Madcatz and Lynxmotion...

2) Some controllers need the higher voltage pin connected. on the lynxmotion PS2 cable it is the green wire. I needed this earlier for the Sector 7 wireless controller.

3) You can have problems if you query the Ps2 controller to fast without a delay between queries. If you query to fast, the PS2 controller receiver does not have time to talk to the remote and the lights will blink and no data is update... Been there!

4) I often look at this site: http://www.curiousinventor.com/guides/ps2 when I am working on PS2 controller stuff.

That is all I can think of for now.

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


 

All times are UTC - 5 hours [ DST ]. It is currently 2014-10-20 09:01
Feedback Form
Feedback Form