I need to establish communication between arduino mega 2560 with external serial device called SKPS( Cytron.io - Simplifying Digital Making)
Actually my project is about to control arduino output via PS2 wireless controller, SKPS used as communication bridge between PS2 controller with arduino. SKPS consist of TX,RX,5V,GND and RESET pin that should cross connect to TX and RX pin of arduino.
This is the sample code i done but didt works
//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= 19;
const int tx= 18;
void setup()
{
Serial1.begin(9600); //Set serial baud rate as 9600
//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(!Serial1.available()); //Wait until data received
temp=Serial1.read();
return temp; //Return the received data
}
unsigned char skps(unsigned char data) //Function to send out a byte via UART
{
Serial1.write(data); //Send new data
return receive_data(); //Return received data
}
appreciate if someone can help in this