RobotShop Rover Sample Program - motorstop() code fails after call to motorforward()

Can someone please help me identify what is wrong with the following code.

motorforward() works…! However, motorstop() doesn’t. Whats going on?

I am following the code sample in here:
robotshop.com/content/PDF/sample-code-robotshop-rover-arduino.pdf

Code:

int motor_reset = 2; //digital pin 2 assigned to motor reset

void setup()
{
  pinMode(motor_reset, OUTPUT);
  
  Serial.begin(9600);

  digitalWrite(motor_reset, LOW);
  delay(50);
  digitalWrite(motor_reset, HIGH);
  delay(50);

}

void loop()
{
  motorforward();
  delay(2000);
  motorstop();

}

//subroutine motor forward
void motorforward()
{
  //left motor
  unsigned char buff1[4];
  buff1[0]=0x80; //start byte - do not change
  buff1[1]=0x00; //Device type byte
  buff1[2]=0x01; //Motor number and direction byte; motor one =00,01
  buff1[3]=0x45; //Motor speed "0 to 128" (ex 100 is 64 in hex)
  Serial.write(buff1, 4);
  
  //right motor
  unsigned char buff2[4];
  buff2[0]=0x80; //start byte - do not change
  buff2[1]=0x00; //Device type byte
  buff2[2]=0x03; //Motor number and direction byte; motor two=02,03
  buff2[3]=0x45; //Motor speed "0 to 128" (ex 100 is 64 in hex)
  Serial.write(buff2, 4);
}

//Motor all stop
void motorstop()
{
  //left motor
  unsigned char buff3[4];
  buff3[0]=0x80; //start byte - do not change
  buff3[1]=0x00; //Device type byte
  buff3[2]=0x00; //Motor number and direction byte; motor one =00,01
  buff3[3]=0x00; //Motor speed "0 to 128" (ex 100 is 64 in hex)
  Serial.write(buff3, 4);
  
  //right motor
  unsigned char buff4[4];
  buff4[0]=0x80; //start byte - do not change
  buff4[1]=0x00; //Device type byte
  buff4[2]=0x02; //Motor number and direction byte; motor two=02,03
  buff4[3]=0x00; //Motor speed "0 to 128" (ex 100 is 64 in hex)
  Serial.write(buff4, 4);
}

fml

Problem solved, check code in this post…

However: I am still not quite sure why the code in my initial post would not stop. In case anyone else is having problems with the RobotShop code I have included the basic controls to get you up and running. **Stop time needs to be set long enough to reset the signals I think? **

Note, the following code will perform stop, forward, reverse, rotateccw:

[code]
/* RoverShop Rover Basic Movement controls demo
** So easy a dad could do it…
*/
int motor_reset = 2; //digital pin 2 assigned to motor reset

void setup()
{
pinMode(motor_reset, OUTPUT);

Serial.begin(9600);

digitalWrite(motor_reset, LOW);
delay(50);
digitalWrite(motor_reset, HIGH);
delay(50);

}

void loop()
{
Forward(1000);

Stop(1000);

RotateCounterClockWise(3000);

Stop(3000);

Reverse(1000);

Stop(1000);

}

/* setMotorspeed(int speed)
** This function was ripped from:
** pololu.com/docs/0J44/6.7.1
** I am planning to use the libraries to control final versions of my bot’s movements, left this as a placeholder for others to get started with the same, will share code once I get it done.
**/
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
if (speed == 0)
{
motorstop();
}
else if (speed < 0)
{
}
else
{
}
}

void Forward(int time)
{
motorforward(0x80);
delay(time);
}

void Stop(int time)
{
setMotorSpeed(0);
delay(time);
}

void Reverse(int time)
{
motorreverse();
delay(time);
}

void RotateCounterClockWise(int time)
{
rotateccw();
delay(time);
}

void rotateccw()
{
//left motor
unsigned char buff1[4];
buff1[0]=0x80; //start byte - do not change
buff1[1]=0x00; //Device type byte
buff1[2]=0x01; //Motor number and direction byte; motor one =00,01
buff1[3]=0x40; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff1, 4);

//right motor
unsigned char buff2[4];
buff2[0]=0x80; //start byte - do not change
buff2[1]=0x00; //Device type byte
buff2[2]=0x02; //Motor number and direction byte; motor two=02,03
buff2[3]=0x40; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff2, 4);
}

//subroutine motor forward
void motorforward(unsigned char speedValue)
{
//left motor
unsigned char buff1[4];
buff1[0]=0x80; //start byte - do not change
buff1[1]=0x00; //Device type byte
buff1[2]=0x01; //Motor number and direction byte; motor one =00,01
buff1[3]=0x45; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff1, 4);

//right motor
unsigned char buff2[4];
buff2[0]=0x80; //start byte - do not change
buff2[1]=0x00; //Device type byte
buff2[2]=0x03; //Motor number and direction byte; motor two=02,03
buff2[3]=0x45; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff2, 4);
}

//subroutine reverse at half speedd
void motorreverse()
{
//left motor
unsigned char buff3[4];
buff3[0]=0x80; //start byte - do not change
buff3[1]=0x00; //Device type byte
buff3[2]=0x00; //Motor number and direction byte; motor one =00,01
buff3[3]=0x45; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff3, 4);

//right motor
unsigned char buff4[4];
buff4[0]=0x80; //start byte - do not change
buff4[1]=0x00; //Device type byte
buff4[2]=0x02; //Motor number and direction byte; motor two=02,03
buff4[3]=0x45; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff4, 4);
}

//Motor all stop
void motorstop()
{
digitalWrite(motor_reset, LOW);
delay(50);
digitalWrite(motor_reset, HIGH);
delay(50);
}

//Motor all stop v2
void motorstop2()
{
//left motor
unsigned char buff3[4];
buff3[0]=0x80; //start byte - do not change
buff3[1]=0x00; //Device type byte
buff3[2]=0x00; //Motor number and direction byte; motor one =00,01
buff3[3]=0x00; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff3, 4);

//right motor
unsigned char buff4[4];
buff4[0]=0x80; //start byte - do not change
buff4[1]=0x00; //Device type byte
buff4[2]=0x02; //Motor number and direction byte; motor two=02,03
buff4[3]=0x00; //Motor speed “0 to 128” (ex 100 is 64 in hex)
Serial.write(buff4, 4);
}[/code]

The rover is currently powered by a honking power bank I normally use for electronics on the airplane:
amazon.com/Tenergy-10000mAh-10AH-Portable-Power/dp/B009AZXHT2

I plan on replacing this with a battery that accommodates the chasis’ dimensions.

Check it:
[video=youtube;ZU0E0zlTyd4]http://www.youtube.com/watch?v=ZU0E0zlTyd4
Cheers!

Videos are always appreciated - looking forward to seeing it on the ground!

Added code to github, will be managing updates to code RobotShop Rover code through this repository.
github.com/saadaziz/arduino-rover-bot/blob/master/pololu_demo