Programming HB-25 Motor Controller for Cyborg, issues w/ code

Hello -

Am trying to use a Parallax HB-25 Motor Controller. it is being used in this project - http://www.vishtauroborg.blogspot.com/
(i should add that i'm not being paid for this work, i'm the sound designer in the project and the robotics work turned into a collaboration, now i'm learning how to program on the fly)

Here is it's documentation -
http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/HB-25MotorController-V1.2.pdf

i've got it moving, the problem is it is inconsistent in how far it turns, and doesn't respond to certain pulse patterns.

for example - it needs a pulse of 1.0 ms to go foward, 1.5ms to stop, and 2.0ms to go in reverse.

The problem is, when i give it code like this -

void loop()
{  digitalWrite(PulsePort, HIGH);
   delay(0.5);                    // forward, for some reason it responds to 0.5 better than 1.0)
   digitalWrite(PulsePort, LOW);
   delay(200);
   
   digitalWrite(PulsePort, HIGH);
   delay(1.5);       // STOP
   digitalWrite(PulsePort, LOW);
   delay(20);
   
   digitalWrite(PulsePort, HIGH); 
   delay(2.0); // reverse
   digitalWrite(PulsePort, LOW);
   delay(200); 
   
   digitalWrite(PulsePort, HIGH);
   delay(1.5);    // STOP
   digitalWrite(PulsePort, LOW);
   delay(20);
     
   }

it just goes one direction.

Then, if i take out that last stop command, like this -

void loop()
{  digitalWrite(PulsePort, HIGH);
   delay(0.5);                    // forward, for some reason it responds to 0.5 better than 1.0)
   digitalWrite(PulsePort, LOW);
   delay(200);
   
   digitalWrite(PulsePort, HIGH);
   delay(1.5);       // STOP
   digitalWrite(PulsePort, LOW);
   delay(20);
   
   digitalWrite(PulsePort, HIGH); 
   delay(2.0); // reverse
   digitalWrite(PulsePort, LOW);
   delay(200); 
  
     }

it does go back and forth between directions, but goes one way a little bit longer than the other, so it ends up rotating all the
way around eventually (which can't happen, it would rip out my air tubes).

there are a bunch of other weird things happening too, like when i change the delay at the end of the stop command to 200, it just goes one direction.

am i missing something here? has anyone used this controller before? can i take a glimpse at your code?

here is my FULL code -

#define PulsePort 18

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

}

void loop()
{  digitalWrite(PulsePort, HIGH);
   delay(0.5);
   digitalWrite(PulsePort, LOW);
   delay(200);
   
   digitalWrite(PulsePort, HIGH);
   delay(1.5);
   digitalWrite(PulsePort, LOW);
   delay(20);
   
   digitalWrite(PulsePort, HIGH); 
   delay(2);
   digitalWrite(PulsePort, LOW);
   delay(200);
     
   }

I looked at the data sheet, and it appears like the controller should be treated as if it is a servo (probably designed such that it can be connected to an RC receiver). Below is some servo test code you can try to see if you get better results.

// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(2000); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(1);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray); 
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  } 
}

Hey, thanks.

That code is making to motor spin in one direction. If I want to send it different pulses, to go a different direction, should i insert them into where it says "myservo.writeMicroseconds(n); // for microseconds", in place of "n"?

I tried switching up it, up the motor still spins the same direction.

Sorry, I didn't even know what a servo was until your reply. THANKS!

I would expect the motor to be stopped at a writeMicroseconds value of ~1500, the motor should be stopped. As the writeMicroseconds value is increased greater than ~1500, the motor should increase in speed in that direction. As the writeMicroseconds value is decreased below ~1500 writeMicroseconds the motor should increase in speed in the other direction.

Anyone have any updated arduino/parallax HB-25 code? I'm trying to control two motors but cant seem to get the signals or timing right. I can make them both move in the same direction, fwd or rev, fast or slow. But I can't make one move and not the other.

I'm attempting to attach some sample code...

// Begin sample code
String readString;
#include <Servo.h>
Servo myServo;  // create servo object to control a servo

int fwdPulse = 0;
int revPulse = 0;
int stopPulse = 1500;

void setup() {
/* Milliseconds to Microseconds
0.8 ms = 800 us (Full Rev)
1.1 ms = 1100 us (Pause between pulses for M1 & M2)
1.5 ms = 1500 us (Full Stop)
2.2 ms = 2200 us (Full Fwd)
5.25 ms = 5250 us (Pause after M2 pulse)
*/

int servoPin = 13;
pinMode(servoPin, OUTPUT);
digitalWrite(servoPin, LOW); // Initialize the HB25
myServo.attach(13); //the pin for the servo control
delay(750);
Serial.begin(9600);
myServo.writeMicroseconds(stopPulse); // Full stop
delay(1.1);
myServo.writeMicroseconds(stopPulse); // Full stop
Serial.println("servo-test-1"); // so I can keep track of what is loaded
delay(1000);


// Ramp M2 to full FWD. Keep M1 stopped
Serial.println("Ramp M2 to full FWD. Keep M1 stopped"); 
for (int i=0; i < 650; i++){

 fwdPulse = stopPulse + i;
 revPulse = stopPulse - i;

 myServo.writeMicroseconds(stopPulse);  // Send FWD pulse to M1 
 delay(1.1);
 myServo.writeMicroseconds(fwdPulse);  // Send FWD pulse to M2
 delay(5.25);

}
 
// Stop both
myServo.writeMicroseconds(stopPulse);  // Send FWD pulse to M1 
delay(1.1);
myServo.writeMicroseconds(stopPulse);  // Send FWD pulse to M2
delay(5.25);

}

void loop() {

}

You have your HB25s set up for "dual mode"
http://www.robotshop.com/media/files/pdf/hb-25-motor-controller-documentation-v1.2-29144.pdf
see "Figure 3" [note the arrangement of those jumper blocks]