Page 1 of 1

Arduino Mega 2560 UART with SKPS

PostPosted: Sun Mar 03, 2013 9:21 pm
by Jonathan Law
I'm using Arduino Mega 2560, going to connect with SKPS using UART.
there are TX0,RX0,TX1,RX1,TX2,RX2,TX3,RX3
how will be the UART coding if i want to use TX0 and RX0 to connect with SKPS?
I found this in cytron tutorial but i'm not sure whether suit to my project or not.

CODE: SELECT_ALL_CODE
unsigned char receive_data(void) //Function to wait for a byte receive from UART
{
  unsigned char temp;
  while(!Serial.available()); //Wait until data received
  temp=Serial.read();
  return temp;                    //Return the received data
}

unsigned char skps(unsigned char data) //Function to send out a byte via UART
{
  Serial.write(data); //Send new data
  return receive_data(); //Return received data
}

Re: Arduino Mega 2560 UART with SKPS

PostPosted: Tue Mar 05, 2013 1:04 pm
by yonghui
i think u just try and u will know whther it can be used or not.

Re: Arduino Mega 2560 UART with SKPS

PostPosted: Tue Mar 05, 2013 11:59 pm
by Jonathan Law
I connected PS2 wireless controller with SKPS and would like to establish communication between arduino mega 2560 with SKPS and PS2. Above code cnt working to establish this communication,anyone can help me in UART code??
Thanks

Re: Arduino Mega 2560 UART with SKPS

PostPosted: Wed Mar 06, 2013 7:54 am
by robosang
How is the connection? How do you know it is not working?

Re: Arduino Mega 2560 UART with SKPS

PostPosted: Fri Mar 22, 2013 10:52 pm
by Jonathan Law
I still having problem to work out with Arduino Mega 2560 with SKPS,
I had connect SKPS with 5V and GND from arduino board, SKPS TX pin and RX pin cross connect with Arduino Mega TX3 and RX3 pin
The connection I refer to http://tutorial.cytron.com.my/2012/07/16/interfacing-fd04a-and-skps-with-arduino/
SKPS STATUS led blinking while i press the PS2 controller, this mean SKPS received signal from PS2 controller but didt give me simple lights up led output. please refer my simple testing code below:
CODE: SELECT_ALL_CODE
//skps protocol
#define p_Up       4
#define p_Right       5
#define p_Down       6
#define p_Left       7
#define   p_L2       8
#define   p_R2       9
#define p_L1       10
#define p_R1       11
#define p_Triangle  12
#define p_Circle    13
#define p_Cross       14
#define   p_Square    15

const int rx= 15;
const int tx= 14;

void setup()
{
  Serial.begin(9600);      //Set serial baud rate as 9600
  Serial.flush();          //Waits for the transmission of outgoing serial data to complete.
 
  //Set the mode for each digital pins whether input or output
  pinMode(rx, INPUT);
  pinMode(tx, OUTPUT);
 
  pinMode(53,OUTPUT);
}

void loop ()
{
   if(skps(p_Up)==0)            //Check whether Up button is pressed
  {
    digitalWrite(53,HIGH);               
  }
 
  else if(skps(p_Down)==0)   //Check whether Down button is pressed      
  {   
    digitalWrite(53,LOW);               
  }
}

unsigned char receive_data(void)  //Function to wait for a byte receive from UART
{
  unsigned char temp;
  while(!Serial.available());    //Wait until data received
  temp=Serial.read();
  return temp;                    //Return the received data
}

unsigned char skps(unsigned char data)   //Function to send out a byte via UART
{                              
  Serial.write(data);             //Send new data
  return receive_data();          //Return received data
}
 


I really need help ..

Re: Arduino Mega 2560 UART with SKPS

PostPosted: Mon Mar 25, 2013 8:44 pm
by robosang
I thought pin 14 and 15 is serial3 on Arduino Mega... did you study the page from Arduino.cc?
http://arduino.cc/en/Reference/serial

Re: Arduino Mega 2560 UART with SKPS

PostPosted: Mon Mar 25, 2013 9:14 pm
by shahrul
Jonathan Law WROTE:I still having problem to work out with Arduino Mega 2560 with SKPS,
I had connect SKPS with 5V and GND from arduino board, SKPS TX pin and RX pin cross connect with Arduino Mega TX3 and RX3 pin

Connection to TX3 and RX3, should use Serial3