Arduino and LV-DSMC: Cannot select motor properly

Hello – I’m a longtime computer programmer but new to robotics and microcontrollers. I’m trying to get my Arduino Duemilanove to control my Pololu Low Voltage Dual Serial Motor Controller. (The MC is in turn plugged into a pair of tiny Tamiya motors in a Tamiya 70097 gearbox.)

As I understand the MC manual, the code I’ve written ought to rotate one of my two motors forward for five seconds, then pause for five seconds, then repeat. Instead, it rotates both motors forward, not just one of them.

#define ledPin        4
#define motorResetPin 5


void setup(){
  pinMode(ledPin, OUTPUT);
  pinMode(motorResetPin, OUTPUT);
  Serial.begin(1200);   // set baud rate
  motorReset();
}

void loop(){
  digitalWrite(ledPin,HIGH);
  
  Serial.print(0x80,BYTE);   // init command
  Serial.print(0x00,BYTE);   // hello motor controller
  Serial.print(0,BYTE);   // pick a motor
  Serial.print(20,BYTE);  // pick a speed
  
  delay(5000);

  motorReset();
  digitalWrite(ledPin,LOW);
  
  delay(5000);
}

void motorReset(){
  digitalWrite(motorResetPin, LOW);
  delay(10);
  digitalWrite(motorResetPin, HIGH);  
  delay(100);
}

The culprit, as near as I can tell is the line “Serial.print(0,BYTE);”. I’ve tried altering it, with the following results:

  • “Serial.print(1,BYTE);” rotates both motors backwards instead of forwards.
  • Any other value seems to cause the MC to fail to respond in any way

I’m at a loss here- Any advice will be much appreciated! Thanks in advance,

=T=
:smiley:

It sounds like you may have inadvertently switched your LV-DSMC into single-motor mode, which is used to double the power available to a single motor. Were you playing around with the configuration command at some point?

Anyway, to set it back to 2-motor mode with the default motor numbers, you would send this string of bytes

Serial.print(0x80,BYTE); // init command
Serial.print(0x02,BYTE); // configuration command
Serial.print(2,BYTE); //2 motor mode, motors 2 and 3 (all controllers respond to motor numbers 0 and 1)

Does that take care of it?

-Adam

that did it! big thanks.

i hadnt tried the config command before deliberately, but did send a lot of gibberish while trying to get the thing to work initially, so apparently accidentally misconfigured it.

a small followup question: while i’m uploading code into the arduino, the motors spaz out, spinning jerkily in random directions. is this normal? is there a way to avoid this other than disconnecting the control wire during upload? (it will be pretty inconvenient once the motors are going to actual wheels.)

=T=

Glad to hear that did it for you. Actually it could have been programming that set the wrong motor numbers in the first place.

Your Arduino uses the same hardware serial pin to command the motor controller as it does to acknowledge the program data you bootload it with. I think the bootloader sets all other pins to floating inputs while it’s running though, so you could put a pull-down resistor between the motor controller’s reset pin and ground (in addition to the connection to your Arduino pin), which would pull the motor controller into reset during Arduino programming. 1K-5K should do, I’m not sure what value pull-up resistor you’ll be fighting on the motor controller though.

-Adam

I am having this same problem, but adding the configuration code did not solve it. I’ve tried configuring the controller with the following codes:

0x80
0x02
0x02
(as recommended above)

and
0x80
0x02
0x00
(I thought configuring to numbers 0 and 1 would work)

Anyhow, in both cases any command sent to motor ID 0 controls both motors. Any command sent to any other ID does nothing. It makes sense that I’m in single-motor mode, but I can’t understand why it refuses to be reconfigured. I’m resetting for 100ms after configuration.

I do not see the 1 green LED flash that is supposed to accompany reconfiguration.

100ms is an ample reset time, but are you resetting the controller immediately after sending the configuration bytes? Try sending just the bytes, then waiting for the response flashes. You can manually reset the controller once you see them by just cycling the power.

-Adam

Thanks! :smiley: That did it. Inserting a 2s delay before resetting solved the problem. I’m fairly sure 2s is serious overkill, but given that I only have to do this once, it’s not a big deal.

For future seekers, my Arduino code now looks like this:

motorSerial.print(0x80,BYTE); // init command
motorSerial.print(0x02,BYTE); // configuration command
motorSerial.print(2,BYTE); //2 motor mode, motors 2 and 3 
        
delay(2000);   //THIS IS WHAT I WAS MISSING - not sure how long it needs to be
        
// Reset the motor controller (By setting low then high signals to the resetPin)
digitalWrite(resetPin, LOW);
delay(10);
digitalWrite(resetPin, HIGH);
// Pause of the reset
delay(100);