Archive for April, 2011


>Here we go.Get Sony PS 2 remote for your self. Don’t get afraid,just do it.Take a wire stripper ,cut a wire near by socket and strip it .Before we move foreword and connect this remote control to our ATmega16 or 8 whatever you have,lets have a closer look what each wire is for.

  • Brown :Data
  • Orange:Command
  • Gray:Not used
  • Black:Ground
  • Red:VCC
  • Yellow:ATT
  • Blue:Clock
  • White:Not used
  • Green:Ack

Wondered!! from where did I get this information!!! Well not a big deal.If you really want to find out something Google is always there for you :).
I found
http://www.gamesx.com/controldata/psxcont/psxcont.htm and
http://store.curiousinventor.com/guides/PS2/.
Now we connect ps2 remote control with Atmega16 as shown in following image.

Let me give you brief about how to fetch and send single byte data to PS2 remote control .

This image is taken from curiousinventor.com
Look at the image.It says that First we low the ATT pin to start communication with PS2 remote control.Then we start sending clock to receive and send data to PS2 remote control.we send different set of command using command line and receive data about switch and analog joystick from data line.we are sending and receving data byte wise. At the end of the communication we set ATT pin high. Data is put on the line by ps2 remote on the falling edge of the clock. we read the data on rising edge. If you want more detail check out above link .I don’t want write all that stuff again.
Questions!!! what are these commands ?? what kind of data ?? well answer is look at the protocol.

Analogue Controller in Red Mode
BYTE    CMND    DATA

01     0x01   idle

02     0x42   0x79

03     idle    0x5A    Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7

04     idle    data    SLCT JOYR JOYL STRT UP   RGHT DOWN LEFT

05     idle    data    L2   R2   L1   R1   /\   O    X    |_|

06     idle    data    Right Joy 0x00 = Left  0xFF = Right

07     idle    data    Right Joy 0x00 = Up    0xFF = Down

08     idle    data    Left Joy  0x00 = Left  0xFF = Right

09     idle    data    Left Joy  0x00 = Up    0xFF = Down

we first low the ATT and then we send three synchronization command byte1,byte2,byte3 and then from the 4th byte we start receiving data from ps2 remote control as described in protocol. store these data for latter use.after the 9th byte recevied we again make ATT to high .we process over the stored data and again start looking for new data as described above.

Lets do some coding .I hope You are familiar micro controller coding and have play around it.Here is the code for Atmega16,8.
while(1){
PORTB&=~_BV(alt);
send_cmd(0x1,1); //start
send_cmd(0x42,2); //id
send_cmd(0x00,3); //incoming indication
send_cmd(0x00,4); //get 4th byte
send_cmd(0x00,5); //5th byte
send_cmd(0x00,6); //6th byte
send_cmd(0x00,7); //7th byte
send_cmd(0x00,8); //8th byte
send_cmd(0x00,9); //9 th byte
PORTB |=_BV(alt); //clear alt
....
....
}

Simple aha!!. Before we look at send_cmd function lets see following problem.
int val=0x23;
how do you put 0x23 value serially on any pin of microcontroller.
binary value of 0x23 is 0010 0011.

int mask=1;
for(int i=0;i<8;i++){
mask=1 << i ;
if (mask & val )
setbit(PORT,PIN);
else
clearbit(PORT,PIN);

}

Make Sense!!!

Now its time to jump in to send_cmd function.

void send_cmd(unsigned char ps2cmd,int num)
{
unsigned char mask;
mask=1;
int k;
for(k=0;k<8;k++){

if(ps2cmd&mask){
PORTB |= _BV(cmd);

}else
{
PORTB &=~_BV(cmd);
}
mask <<=1;
PORTB &=~_BV(clk);
_delay_us(6);

PORTB |=_BV(clk);
_delay_us(6);
if(ps2cmd==0x42)
{
if(bit_is_set(PINB,data)){byte2[k]=0;

}
else{
byte2[k]=1;

}

}
if(ps2cmd==0x0) {
switch(num){
case 4:
if(bit_is_set(PINB,data)){byte4[k]=0;

}
else{
byte4[k]=1;

}
break;
case 5:
if(bit_is_set(PINB,data)){byte5[k]=0;}
else{
byte5[k]=1;}
break;
case 6:
if(bit_is_set(PINB,data)){byte6[k]=0;}
else{
byte6[k]=1;}
break;
case 7:
if(bit_is_set(PINB,data)){byte7[k]=0;}
else{
byte7[k]=1;}
break;
case 8:
if(bit_is_set(PINB,data)){byte8[k]=0;}
else{
byte8[k]=1;}
break;

case 9:
if(bit_is_set(PINB,data)){byte9[k]=0;}
else{
byte9[k]=1;}
break;
}

}
}

}

Do You Really Need explanation of the code..No you are smart enough to figure it out. 🙂

>Killing Summer Boredom

>Summer 2008 had been great fun. This year I joined the ROBOCON Team. We(ROBOCON Team of L.D. College of Engineering) went to Pune to participate in the competition. We just came back after the great trip to Pune.While arranging the things back at the ROBOCON office, I found Sony PS2 remote. I used to drive manual robot with Sony PS2 remote in ROBOCON. The idea of using this remote to play the games excited me. The only step left for me was to attach it with my laptop using USB. Believe me, USB is not that simple as it seems to be. It came up as one of the most complicated protocol I have ever come across. Those days I was playing around ATMEL ATmega8,16,32 and that time these were the best controller we could get.After searching for few days , I found V-USB. to implement USB protocol. Don’t get scared but ya this was my first recording…!!

NFS Underground2 gave me enough motivation to make a small device so that it looks compact. After settling all the hardware components in small device, I was ready to give my second shot…!!! Now here It is , final presentation with Prince of Persia….!!!!
http://www.youtube.com/get_player
Please check other post to understand how it works and to download source.