I’m trying to get my small treaded robot up and running, but the Pololu Low Voltage Dual Serial Motor Controller keeps shutting off suddenly after a few seconds of operation and will not accept any further commands until reset.
My setup:
Tamiya dual motor gearbox with stock motors
Pololu Low Voltage Dual Serial Motor Controller in 2-motor mode.
Arduino Diecimila sending serial commands
Arduino powered by 9V battery
VMOT power provided by 4 AA batteries (nominal 6V)
Wiring on the DSMC:
VMOT->4AA battery holder + terminal
GND->4AA battery holder - terminal and Arduino GND terminal
VCC-> Arduino 5V terminal
SER-> Arduino digital pin 6
RST->Arduino digital pin 7
M0,M1 +/- -> tamiya motors
I’ve wired an LED onto the VMOT/GND circuit to check for battery voltage.
With everything connected, the VMOT LED is on, and the Arduino code starts running. It sends motor commands, 128 (stopped),130,132,etc up to 254. It waits 2s after each increment. At first, the motor controller responds normally, running the motors at incrementally faster speeds, but at a value of 136-140 the motor controller lights all go out and the motors stop. Until I reset the controller no command produces any motion nor do the indicator lights come back on.
Now, if I disconnect the batteries from VMOT, so VMOT theoretically has no power, then the motor controller acts normally: the indicator lights light up progressively brighter with each step, and they stay on for all steps right up to motor value 254. Since there’s no VMOT power, the motors do not move but the indicators do light up. The LED I attached to VMOT (LED - pin connected to GND via a 480ohm resistor) also lights up even though there is no VMOT power. I can only assume that the VCC power from the Arduino is supplying enough power for the LEDs, but not the motors?
Suddenly reconnecting the VMOT power after commanding the motor to move at 140 or faster causes an immediate shutdown of the motor controller.
I know that the Arduino code is continuing to run, as I’ve watched it in the serial monitor, and also I’ve got the pin 13 LED flashing with each 2s cycle.
So, why is my motor controller shutting down when there is power supplied to VMOT and you give any motor command past about 140? Is this some kind of overcurrent protection?
Thanks in advance.
-t
Here’s the Arduino code (a small modification of code by Jeremy Bridon and Anthony Cascone):
/*
* SMC05A Pololu Dual Serial Motor Controller
* Jeremy Bridon <jbridon@psu.edu>
* Anthony Cascone <acascone@psu.edu>
*/
/*** Includes ***/
#include <SoftwareSerial.h>
#include "math.h"
/*** Definitions ***/
#define rxPin 5 // Defines the "recieve" pin for software serial to motor controller
#define txPin 6 // Defines the "transmit" pin for software serial to motor controller
#define resetPin 7 // Defines the reset pin for the motor controller
#define ledPin 13 //defines the LED pin
// Create a special SoftwareSerial for direction communications with the motor controller
SoftwareSerial motorSerial = SoftwareSerial(rxPin, txPin);
/*** Sample Setup Usage ***/
void setup()
{
// Set the baud rate of standard serial
Serial.begin(9600);
Serial.println("Ready");
//set up the LED pin
pinMode(ledPin, OUTPUT);
// Initialize the motor controller
InitMotor();
}
void loop()
{
for(int i = 0; i < 127; i += 2)
{
Serial.print("step: ");
Serial.print(i);
// Set the motors (index 0 and 1) forward
digitalWrite(ledPin,HIGH);
SetMotor(0, 128+i);
SetMotor(1, 128-i);
Serial.print("motors: [");
Serial.print(128+i);
Serial.print(",");
Serial.print(128-i);
Serial.println("]");
delay(2000); // Wait 1 second
// Set the motors (index 0 and 1) backwards
digitalWrite(ledPin,LOW);
SetMotor(0, 128-i);
SetMotor(1, 128+i);
delay(2000); // Wait 1 second
}
// Reset the motor controller (By setting low then high signals to the resetPin)
digitalWrite(resetPin, LOW);
delay(10);
digitalWrite(resetPin, HIGH);
}
// Public: Initialize the motor controller and unique serial communications
void InitMotor()
{
// Setup Pins for I/O
pinMode(rxPin, INPUT); // Serial Recieve Pin
pinMode(txPin, OUTPUT); // Serial Transmit Pin
pinMode(resetPin, OUTPUT); // Motor Reset Pin
// Set the baud rate of software serial
motorSerial.begin(9600);
delay(100);
// 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);
}
// Public: Set a speed (0 to 127 for backwards, 128 to 255 for forward) based on a motor index
void SetMotor(int motorIndex, int speed)
{
// Cap the given speed
if(speed < 0)
speed = 0;
else if(speed > 255)
speed = 255;
// Convert the given speed to directional speeds
bool Forward;
if(speed >= 128)
{
Forward = true;
speed -= 128;
}
else
{
Forward = false;
speed = 127 - speed;
}
// Pass our conversion to the base SetMotor function
SetMotor(motorIndex, speed, Forward);
}
// Public: Set a speed (0 to 127) and direction (boolean) to a motor
void SetMotor(int motorIndex, int speed, boolean GoForward)
{
// Create the packet buffer
unsigned char buffer[4];
// Start byte and device ID byte
buffer[0] = 0x80;
buffer[1] = 0x00;
// Set motor index
unsigned char index = 0;
if(motorIndex > 0 || motorIndex < 0)
index = 2;
// Motor number and direction
if(GoForward)
buffer[2] = 0x00 | index;
else
buffer[2] = 0x01 | index;
// Motor speed
unsigned char targetSpeed = 0;
if(speed >= 128)
targetSpeed = 127;
else if(speed < 0)
targetSpeed = 0;
else
targetSpeed = (unsigned char)speed;
buffer[3] = targetSpeed;
// Send the packet
SendPacket(buffer, 4);
}
// Private: Send a packet through the custom serial motorSerial
void SendPacket(unsigned char *buffer, int bufferCount)
{
for(int i = 0; i < bufferCount; i++)
motorSerial.print(buffer[i], BYTE);
}