Cherokey 4WD and Arduino Mega 2560

Hello,

I have bought a DFRobot Cherokey 4WD to connect to my Arduino mega 2560 and all commands are ok (backward, turn left, turn right) except forward (M1 HIGH and M2 HIGH at the same time).
Could you help me in resolving this trouble ?

Regards,

Frank

[code]int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control

void stop(void) //Stop
{
digitalWrite(E1,0);
digitalWrite(M1,LOW);
digitalWrite(E2,0);
digitalWrite(M2,LOW);
}
void avance (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}

void recule (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void gauche (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void droite (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}

void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
Serial.begin(19200); //Set Baud Rate
Serial.println(“Run keyboard control”);
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);

}

void loop(void)
{
if(Serial.available()){
char val = Serial.read();
if(val != -1)
{
switch(val)
{
case ‘f’://Move Forward
avance (255,255); //move forward in max speed
break;
case ‘r’://Move Backward
recule (255,255); //move back in max speed
break;
case ‘g’://Turn Left
gauche (100,100);
break;
case ‘d’://Turn Right
droite (100,100);
break;
case ‘p’:
Serial.println(“Hello”);
break;
case ‘x’:
stop();
break;
}
}
else stop();
}

}[/code]

Just switch the motor wires :slight_smile: Reversing the two motor wires makes the motor run in the opposite direction.

Hello and thank’s for your response.

OK but if i switch the wires it can go forward and never backward…

Why i can go backward for one motor (M1 or M2 and without switching the wires) but never go backward with the two motors at the same time ?

Frank

Not sure what you mean. The two motors on the left should be connected to one terminal and the two on the right connected to the other terminal. Each terminal should give you control over speed and direction. You don’t have control over individual motors.
robotshop.com/en/cherokey-4w … tform.html

M1 is in one side and M2 is on the other side.
See this link :
dfrobot.com/wiki/index.php/C … ROB0102%29
I have deconnected M3 and M4 in order to simplify my configuration and solve my problem

M1 can go forward or backward when M2 is off
M2 cxan go forward and backard when M1 is off
M1 and M2 can go backward (at the same time)
but M1 and M2 can never go forward

(Sorry for my poor english, i’m living in France)

Thank’s

I don’t know this setup at all, but if it were me, I would first put something under the rover such that the wheels are off of the ground.

I would then try it again:
If you say do reverse do all of the wheels go in reverse.
If you say to go left do two wheels spin in one direction and the others spin in opposite direction?
Likewise for turn right, except which wheels go in which direction is swapped?
If you say do foreword, what do the four wheels do?

Kurt

Yesterday i found the solulion.

I have to plug the two motors on one side (for example left) at the opposite of the two others in the other side.
So when i transmitte the same code i writed before to the Arduino :

analogWrite (E1,255); //speed control digitalWrite(M1,HIGH); analogWrite (E2,255); //speed control digitalWrite(M2,HIGH);
instead of rotate in the same direction the couples of wheels turn in inverse rotation
those lines of codes that were never operated (that was my problem), will cause the robot to turn left or right.
So i reviewed all the code and my robot go backward, go forward, turn left and right !

Thank you for help me.

Frank

Happy to hear it’s working!