Arduino Uno with Cytron PS2 and Cytron motor shields

Hi, I purchased these Two Shields to go with the Arduino Uno with the hope of being able to control a couple of motors from a wired PS2 handset.
After a lot of time and nothing achieved I am beginning to wonder If it’s even possible.
At the moment all I can do is to get flashing LEDs on the PS2 shield when I press buttons.
Is there a simple way to do this? please someone help !


1 Like

Hi @mattwilko and welcome to the forum.

Can you provide code from Arduino that you wrote for this project?

I found this that seems very similar to yours: Arduino + PS2 shield + MDDS10 for mobile robot control. I hope it can help you.

Thankyou for your reply igor_X
The link you sent is almost exactly what I am trying to do.
Unfortunately I am very new to Arduino and cannot write code yet.
After months of searching I have finally found a code today which works… (a bit)
It allows just one joystick to move the two motors forward/reverse

Ideally both joysticks will operate both motors , but I am pleased its finally doing something.
Here is the code I have used and thank you again for the link !

/*
PWM input mode with microcontroller (Independent Both), DIP switch 1 0 1 1 0 1 0 0 .
This code is using PS2 shield library and math library.
This code is tested with CT-Uno,Smart Drive Duo 10(MDDS10),PS2 shield and PS2 wireless.
*/
#include <SoftwareSerial.h>
#include <Cytron_PS2Shield.h> //PS2 shield library
Cytron_PS2Shield ps2(2, 3); // SoftwareSerial: Rx and Tx pin
#include<math.h>

int dig1=7; //pin signal for motor left
int dig2=4; //pin signal for motor right
int an1=6; //pin pwm for motor left
int an2=5; //pin pwm for motor right

int ly=0;
int lx=0;
int xaxis=0;
int yaxis=0;
int acc=0;

void setup()
{
ps2.begin(9600); // This baudrate must same with the jumper setting at PS2 shield
ps2.reset(1); //call to reset Shield-PS2
delay(100);
ps2.reset(0);
pinMode(dig1,OUTPUT); //initialize for all the input and output
pinMode(dig2,OUTPUT);
pinMode(an1,INPUT);
pinMode(an2,INPUT);
Serial.begin(9600);
analogWrite(an1,0); //Based on the datasheet, the MDDS10 analog pin should get 0 input upon start
analogWrite(an2,0); //thus we need to send 0 value at the beginning
delay(1000);

}

void loop()
{
//joystick value
ly=ps2.readButton(PS2_JOYSTICK_LEFT_Y_AXIS);
lx=ps2.readButton(PS2_JOYSTICK_LEFT_X_AXIS);
acc=(ps2.readButton(PS2_LEFT_2) == 0);

 if(acc==HIGH)
 {
 Normal();}         //function call for normal speed
 else{
 Acceleration();}   //function call for higher speed
 Movement();

}
//funtion for the movement
void forward(int pwm){
digitalWrite(dig1,HIGH);
digitalWrite(dig2,HIGH);
analogWrite(an1,pwm);
analogWrite(an2,pwm);
Serial.println(pwm);
}
void reverse(int pwm){
digitalWrite(dig1,LOW);
digitalWrite(dig2,LOW);
analogWrite(an1,pwm);
analogWrite(an2,pwm);
Serial.println(pwm);
}
void left(int pwm){
digitalWrite(dig1,HIGH);
digitalWrite(dig2,LOW);
analogWrite(an1,pwm);
analogWrite(an2,pwm);
Serial.println(pwm);
}
void right(int pwm){
digitalWrite(dig1,LOW);
digitalWrite(dig2,HIGH);
analogWrite(an1,pwm);
analogWrite(an2,pwm);
Serial.println(pwm);
}
void Stop(int pwm){
digitalWrite(dig1,LOW);
digitalWrite(dig2,HIGH);
analogWrite(an1,pwm);
analogWrite(an2,pwm);
Serial.println(pwm);
}
void Acceleration(){

yaxis=map(ly,0,255,250,-250); //mapping for the value from the joystick to our desired value
xaxis=map(lx,0,255,-250,250);
}
void Normal(){

yaxis=map(ly,0,255,180,-180);
xaxis=map(lx,0,255,-180,180);
}
//Delete the “//” before the Serial.print to see the output from serial monitor
void Movement(){

if( yaxis>0 && yaxis>xaxis){
forward(yaxis);
//Serial.print(“forward”);

 }      

else if( yaxis<0 && yaxis< abs(xaxis)){
reverse(abs(yaxis));
//Serial.print(“reverse”);
}
else if( xaxis>0 && xaxis>yaxis){
right(xaxis);
//Serial.print(“right”);
}
else if( xaxis<0 && xaxis<abs(yaxis)){
left(abs(xaxis));
//Serial.print(“left”);
}
else if( yaxis==1 && xaxis==0){
Stop(0);
//Serial.print(“Stop”);
}
}

1 Like

Hi @mattwilko !

That is great news that something is working :slight_smile:

You are new to Arduino but you will certainly learn more by creating these projects.

You mentioned two joysticks. Are you using two PS controllers, or you mean two joysticks on one controller?

Thanks igor_X , its a small step into developing a basic small underwater vessel for flooded mine inspection.
Ideally I want to be able to control four motors from one ps2 controller as proof of concept, but I am still struggling to find a a simple code to get the project moving.
I will attach a picture of the Shield to show what I am using.
And thanks again for your reply ! :+1:

1 Like

Thank you for your reply.

I am not sure that you can just “find” already written code for your project, because some projects are similar but still different so the code needs to be changed.

Meaning, you already found some simple code (you mentioned that you managed to make motors move with one joystick) so you need to change and adapt this code for your project.