TinyCircuits

TinyShield Motor Driver

TinyShield Motor Driver
« on: July 22, 2013, 12:52:39 PM »
I am having difficulty getting my Tiny Shield Motor driver to work. I suspect that it has to do with the ground connections.

I know that my code is running since I added an LED Shield and it is blinking as programmed. I am using 2 AA batteries and measure 3VDC going into the Motor Driver, but the motor is not turning (it works on 3VDC).

I followed the wiring instructions on the Tiny-Circuits site, copied below:

◦   "Step 3: Add a wire between the GND pin on the Motor x4 TinyShield and the negative terminal on the battery holder."
   
My Tiny Duino has a coin battery holder, but I am using an external battery. The negative terminal was “hidden” under the battery holder clip, so I used a cardboard piece to press a black ground wire into the coin space. I checked that there was indeed a 3VDC difference between the ground wire and positive terminal.
   
◦   "Step 4: Add a wire between the VM pin on the Motor x4 TinyShield and the positive terminal on the battery holder."

I soldered a red wire to the spot where the coin holder is attached to the Tiny Duino.

◦   "Step 5: Add a wire between the positive connection on the battery holder and the ‘+’ hole on the TinyDuino processor Board. This will connect the VM and VCC power supplies together."

I soldered a red wire to the ‘+’ on the Tiny Duino board.


I then tied the black wire to the AA batteries ground and into the Motor Driver GND. I tied all red wires together and the AA battery positive, and tied it to the Motor Driver VM input.

Nothing was working so I tried connecting the ‘-‘ on the Tiny Duino to the rest of the grounds but that did not help either.

I have used H-bridges and motor drivers before, but have spent 2 days on this and am stuck. I already tried a second motor driver shield. Any advice would be much appreciated.

Thanks

Nate

Re: TinyShield Motor Driver
« Reply #1 on: July 22, 2013, 02:56:39 PM »
Nate,

Sorry to hear you're having difficulty - on the motor shield itself, there are two pin holes at the top of the board - if you look on the underneath of the board close to where the TinyCircuits logo is, one pin says VM and the other says GND.  This is where the motor get's it power from - do you have both of these connected?

If so, can you supply the code that you are using to run these motors?

Thanks!

Ken Burns
TinyCircuits

Re: TinyShield Motor Driver
« Reply #2 on: July 22, 2013, 05:30:20 PM »
Ken,

Thanks for taking a look at this.

I did solder up all the pins that came with the motor driver. The one that is labeled GND and VM are hooked up to my battery, and indeed I measured the 3VDC battery voltage across it.

I did notice that when I remove the AA batteries and program the TinyDuino from the USB connector, I do not get any voltage going into the motor driver. Should the 5VDC from the USB be going to the + and - on the TinyDuino board, and ultimately out to the motor driver? I am not 100% clear how all the grounds and power supplies are connected in the various shields.

I am using the example code from the Motor Driver website. All I did was add a blinking light so I could see something.

Is there anyway to tell if the motor driver is working at all? 

Thanks

Nate
« Last Edit: July 22, 2013, 05:32:59 PM by ndelson »

Re: TinyShield Motor Driver
« Reply #3 on: July 23, 2013, 11:53:08 AM »
Nate -

The 5V from the USB is separate from the battery inputs on the main TinyDuino, and also separate from the VM from the motor board, so you won't see the 5V on those pins. 

Doh!  In looking at the sketch on the website I see one obvious problem, the sleep signal is not connected and this may be causing your problem by keeping the motors in sleep all of the time.  I'll fix this.

Here is a quick test that you can use, this should turn on the motor full blast in the forward direction.  Let me know if that works and sorry for the incorrect example.

Thanks,

Ken

Code: [Select]


int motorDirPin = 2;      // Motor direction connected to digital pin 2
int motorSpeedPin = 3;    // Motor speed connected to digital pin 3
int motorSleepPin = A3;      // Motor sleep to analog pin 3

void setup()
{
  pinMode(motorDirPin, OUTPUT);       // sets the pin as output
  pinMode(motorSpeedPin, OUTPUT);     // sets the pin as output
  pinMode(motorSleepPin , OUTPUT);     // sets the pin as output

  digitalWrite(motorDirPin, LOW);     // sets the default dir to be forward
  digitalWrite(motorSpeedPin, HIGH);   // sets the default speed to be full on
  digitalWrite(motorSleepPin , HIGH);   // sets the sleep mode to be off
}

void loop()
{
   // Don't do anything
}

Re: TinyShield Motor Driver
« Reply #4 on: July 23, 2013, 10:37:33 PM »
Ken,

Thanks for the quick response.

I finally got it to work. But there are some additional changes still needed in the example code.

The posted code only operates the motor in one direction.

To change directions you need to change the signs of both input 1 and input 2. Simply changing the sign of motorDirPin will not change the direction.

See the Bridge Table on page 6 of the motor driver spec sheet:

http://www.ti.com/lit/ds/symlink/drv8837.pdf

So far I operated the motor in both directions at full power by putting one pin high and the other low, and then switching both. I have not yet implemented PWM control.

Thanks

Nate
« Last Edit: July 24, 2013, 01:03:51 AM by ndelson »

Motor Driver Function
« Reply #5 on: August 01, 2013, 09:42:09 AM »
I finally got around to implementing a motor function that operates the motor properly in both forward and reverse. The original example code as posted only operates the motor in one direction. Also the original code uses the same pin for the PWM signal to control motor speed. Even if you do get this approach to work it will result in nonsymmetrical motor operation, since in one direction the motor will coast on the low portion of the PWM signal and in the other direction it will brake. The code below operates both directions symmetrically.


Code: [Select]
/* Tiny Motor Function
 
 This program operates the TinyShield Motor Driver x 4 in a function. Board description is at:
 http://tiny-circuits.com/shop/tinyshield-motorx4/
 
 The motor can be operated in forward, reverse, braking, or coast mode. Speed can be controlled via PWM.
 
 Operation is based upon the specs of the H-Bridge motor driver TI DRV8837. The commands use the Bridge Control table on page 6 at:
 http://www.ti.com/lit/ds/symlink/drv8837.pdf
 Unlike other H-Bridges where an Enable pin is operated in PWM mode and other pins control direction, the
 TI DRV8837 has two Input pins. Proper operation requires that the PWM pin varies based upon direction of motor rotation
 to ensure symmetric operation of the motor (otherwise the motor will brake in one direction in low PWM segments and coast in
 the other direction).
 
 Created 1 Aug 2013
 by Nathan Delson
 */

// Define global motor variables
const int Forward = 5;   
const int Reverse = 6;
const int Brake = 7;
const int Coast = 8;
int motorSleepPin = A3;      // Motor sleep is analog pin 3

int LedPin = 13;  // Arduino LED, which is used to flash if error occurs

void setup() {

  digitalWrite(motorSleepPin, HIGH);   // sets the Motor Driver sleep mode to be off

  pinMode(LedPin, OUTPUT);   // for flashing

  // turn all 4 motors off (i.e. to coast)
  for ( int i=0; i <= 4; i++){
    MotorlControl(Coast,0,i);
  }

}

void loop() {

  int MotorNum;  // Motor Number: 1, 2, 3, or 4
  int MotorSpeed;    //  0 to 255
  int ControlMode;   //  Forward=5, Reverse=6, Brake=7, or Coast=8

  MotorNum = 1;

  // Ramp the motor speed up in Forward direction
  MotorlControl(Forward,0,MotorNum);
  delay(50);
  MotorlControl(Forward,63,MotorNum);
  delay(50);
  MotorlControl(Forward,127,MotorNum);
  delay(50);
  MotorlControl(Forward,191,MotorNum);
  delay(50);
  MotorlControl(Forward,255,MotorNum);
  delay(50);

  // Ramp the motor speed down in Forward directoin
  MotorlControl(Forward,191,MotorNum);
  delay(50);
  MotorlControl(Forward,127,MotorNum);
  delay(50);
  MotorlControl(Forward,63,MotorNum);
  delay(50);
  MotorlControl(Forward,0,MotorNum);
  delay(50);

  // Ramp the motor speed up in Reverse direction
  MotorlControl(Reverse,0,MotorNum);
  delay(50);
  MotorlControl(Reverse,63,MotorNum);
  delay(50);
  MotorlControl(Reverse,127,MotorNum);
  delay(50);
  MotorlControl(Reverse,191,MotorNum);
  delay(50);
  MotorlControl(Reverse,255,MotorNum);
  delay(50);

  // Ramp the motor speed down in Reverse direction
  MotorlControl(Reverse,191,MotorNum);
  delay(50);
  MotorlControl(Reverse,127,MotorNum);
  delay(50);
  MotorlControl(Reverse,63,MotorNum);
  delay(50);
  MotorlControl(Reverse,0,MotorNum);
  delay(50);

}


void MotorlControl( int ControlMode,  int MotorSpeed,  int MotorNum) {

  /* Definitions of Inputs
   ControlMode - Forward=5, Reverse=6, Brake=7, or Coast=8
   MotorSpeed - 0 to 255
   MotorNum - Motor Number: 1, 2, 3, or 4 
   Flashes on Arduio LED will occur if inputs are outside valid ranges*/

  int IN1Pin;  // Pin on Tiny Duino that connects to Input 1 of motor driver
  int IN2Pin;  // Pin on Tiny Duino that connects to Input 2 of motor driver

  // set IN1 and IN2 according to motor used (1-4)
  switch (MotorNum) {
  case 1:
    IN1Pin = 2;
    IN2Pin = 3;
    break;
  case 2:
    IN1Pin = 4;
    IN2Pin = 5;
    break;
  case 3:
    IN1Pin = 6;
    IN2Pin = 7;
    break;
  case 4:
    IN1Pin = 8;
    IN2Pin = 9;
    break;
  default:
    // Invalid motor number flash
    digitalWrite(LedPin, HIGH);   
    delay(50);               
    digitalWrite(LedPin, LOW);   
    delay(50); 
  }


  pinMode(IN1Pin, OUTPUT);       // sets the pin as output
  pinMode(IN2Pin, OUTPUT);       // sets the pin as output

  // Check that MotorSpeed is between 0 and 255
  if ( MotorSpeed < 0 || MotorSpeed > 255 ) {
    // Invalid MotorSpeed flash
    digitalWrite(LedPin, HIGH);   
    delay(100);               
    digitalWrite(LedPin, LOW);   
    delay(100); 
  }

  // Operate H-Bridge according to the Bridge Control Table of the DRV8837
  // In Forward and Reverse always set the low pin as fixed and the high pin to
  // the PWM value. When the PWM pin is high the motor operates in the specfied direcion,
  // and when the PWM is low the motor coasts.

  switch (ControlMode) {
  case Forward:
    digitalWrite(IN2Pin, LOW);         // sets the Mode
    analogWrite(IN1Pin, MotorSpeed);   // sets the speed with a PWM signal
    break;
  case Reverse:
    digitalWrite(IN1Pin, LOW);         // sets the Mode
    analogWrite(IN2Pin, MotorSpeed);   // sets the speed with a PWM signal
    break;
  case Coast:
    digitalWrite(IN1Pin, LOW);         // sets the Mode
    digitalWrite(IN2Pin, LOW);         // sets the Mode
    break;
  case Brake:
    digitalWrite(IN1Pin, HIGH);         // sets the Mode
    digitalWrite(IN2Pin, HIGH);         // sets the Mode
    break;
  default:
    // Invalid ControlMode flash
    digitalWrite(LedPin, HIGH);   
    delay(200);               
    digitalWrite(LedPin, LOW);   
    delay(200); 
  }

} // End of MotorlControl Function














« Last Edit: August 08, 2013, 04:02:17 AM by calvinthedestroyer »