Pololu h-bridge

Hello !!
I need some help with my DRV8835 :

I need to connect 2 DC motors with this h-bridge, but I can’t found any working program, (I’m using the DRV8835MotorShield library).
The connections are :
MD → +5V
IN1 PH A → pin 51
IN2 EN A → pin 3 (PWM)
IN1 PH B → pin 50
IN2 EN B → pin2(PWM)
VCC-> +5V
VIN-> +6V
GND → pin (-) of the battery.

This is the DRV8835MotorShield.cpp :

#include "DRV8835MotorShield.h"
const unsigned char DRV8835MotorShield::_M1DIR = 50;
const unsigned char DRV8835MotorShield::_M2DIR = 51;
const unsigned char DRV8835MotorShield::_M1PWM = 2;
const unsigned char DRV8835MotorShield::_M2PWM = 3;
boolean DRV8835MotorShield::_flipM1 = false;
boolean DRV8835MotorShield::_flipM2 = false;

void DRV8835MotorShield::initPinsAndMaybeTimer()
{
  // Initialize the pin states used by the motor driver shield
  // digitalWrite is called before and after setting pinMode.
  // It called before pinMode to handle the case where the board
  // is using an ATmega AVR to avoid ever driving the pin high, 
  // even for a short time.
  // It is called after pinMode to handle the case where the board
  // is based on the Atmel SAM3X8E ARM Cortex-M3 CPU, like the Arduino
  // Due. This is necessary because when pinMode is called for the Due
  // it sets the output to high (or 3.3V) regardless of previous
  // digitalWrite calls.
  digitalWrite(_M1PWM, LOW);
  pinMode(_M1PWM, OUTPUT);
  digitalWrite(_M1PWM, LOW);
  digitalWrite(_M2PWM, LOW);
  pinMode(_M2PWM, OUTPUT);
  digitalWrite(_M2PWM, LOW);
  digitalWrite(_M1DIR, LOW);
  pinMode(_M1DIR, OUTPUT);
  digitalWrite(_M1DIR, LOW);
  digitalWrite(_M2DIR, LOW);
  pinMode(_M2DIR, OUTPUT);
  digitalWrite(_M2DIR, LOW);
#ifdef DRV8835MOTORSHIELD_USE_20KHZ_PWM
  // timer 1 configuration
  // prescaler: clockI/O / 1
  // outputs enabled
  // phase-correct PWM
  // top of 400
  //
  // PWM frequency calculation
  // 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
  TCCR1A = 0b10100000;
  TCCR1B = 0b00010001;
  ICR1 = 400;
#endif
}

// speed should be a number between -400 and 400
void DRV8835MotorShield::setM1Speed(int speed)
{
  init(); // initialize if necessary
    
  boolean reverse = 0;
  
  if (speed < 0)
  {
    speed = -speed; // make speed a positive quantity
    reverse = 1;    // preserve the direction
  }
  if (speed > 400)  // max 
    speed = 400;
    
#ifdef DRV8835MOTORSHIELD_USE_20KHZ_PWM
  OCR1A = speed;
#else
  analogWrite(_M1PWM, speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
#endif 

  if (reverse ^ _flipM1) // flip if speed was negative or _flipM1 setting is active, but not both
    digitalWrite(_M1DIR, HIGH);
  else
    digitalWrite(_M1DIR, LOW);
}

// speed should be a number between -400 and 400
void DRV8835MotorShield::setM2Speed(int speed)
{
  init(); // initialize if necessary
    
  boolean reverse = 0;
  
  if (speed < 0)
  {
    speed = -speed;  // make speed a positive quantity
    reverse = 1;  // preserve the direction
  }
  if (speed > 400)  // max PWM duty cycle
    speed = 400;
    
#ifdef DRV8835MOTORSHIELD_USE_20KHZ_PWM
  OCR1B = speed;
#else
  analogWrite(_M2PWM, speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
#endif

  if (reverse ^ _flipM2) // flip if speed was negative or _flipM2 setting is active, but not both
    digitalWrite(_M2DIR, HIGH);
  else
    digitalWrite(_M2DIR, LOW);
}

// set speed for both motors
// speed should be a number between -400 and 400
void DRV8835MotorShield::setSpeeds(int m1Speed, int m2Speed){
  setM1Speed(m1Speed);
  setM2Speed(m2Speed);
}

void DRV8835MotorShield::flipM1(boolean flip)
{
  _flipM1 = flip;
}

void DRV8835MotorShield::flipM2(boolean flip)
{
  _flipM2 = flip;
}

and my program…

#include <DRV8835MotorShield.h>

/*
 * This example uses the DRV8835MotorShield library to drive each motor with the
 * Pololu DRV8835 Dual Motor Driver Shield for Arduino forward, then backward. 
 * The yellow user LED is on when a motor is set to a positive speed and off when
 * a motor is set to a negative speed.
 */

#define LED_PIN 11

DRV8835MotorShield motors;

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  
  // uncomment one or both of the following lines if your motors' directions need to be flipped
  //motors.flipM1(true);
  //motors.flipM2(true);
}

void loop()
{
  // run M1 motor with positive speed
  
  digitalWrite(LED_PIN, HIGH);
  

    motors.setM1Speed(400);
    delay(2000);
    motors.setM2Speed(400);
    delay(2000);
   motors.setM1Speed(-400);
    delay(2000);
    motors.setM2Speed(-400);
    delay(2000);
 
}

I’m using an Arduino Mega
Thank you for your help !!!

Thierry :confused: :slight_smile:

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Sorry, it's my first post on this forum. I've changed the issue.

Thanks :slight_smile:

Thierry

Hi,
Try here where the product came from.

and read this;

"google and yee shall find"

[Pololu DRV8835 Example by JasonJaeger](http://"http://"Pololu DRV8835 Example by JasonJaeger DRV8835 Example.ino"")

Also look in the library examples that come with it, you can find them in Files, Examples and then click the library name in the list.

Can you tell us your electronics, programming, Arduino, hardware experience?

Tom... :slight_smile:

Thank you for you answer…
I’ve already try almost one hundred times this program, but I’m not really sure of the connections between the motor shield, and the arduino Mega …
We can hear a little sound from the motor, but he doesn’t move …
About my experience, I’m in an engineer school, and I’ve already used a lot of shields (Bluetooth, 433, Motors, …) but I don’t understand the problem :confused:

Thank you ! :slight_smile:

Thierry

Hi,

Can you please post a copy of your current circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Label the pins and make sure you include your power supplies.

A picture of your project would help with component layout too.

Thanks.. Tom.. :slight_smile:

Here you are …

Thank you so much !!! :slight_smile:

Thierry

Try:

void setup()
{
  pinMode (50, OUTPUT) ;
  pinMode (51, OUTPUT) ;
  analogWrite (2, 100) ;
  analogWrite (3, 100) ;
}

void loop ()
{
  delay (1000) ;
  digitalWrite (50, HIGH) ;
  digitalWrite (51, HIGH) ;
  delay (1000) ;
  digitalWrite (50, LOW) ;
  digitalWrite (51, LOW) ;
}

Which should reverse the motors each second, running at a moderate speed.

Hi,
If you are using a SLA battery, PLEASE put a fuse in the positive wire before anything shorts.

The SLA is capable of many amps more than your project can survive.

A blown fuse is cheaper and easier to replace than burnt-out pcbs and wiring.

Tom... :slight_smile:

The Fritzing picture shows VCC of the motor driver connected to V-in of the Mega. Should be VCC to the 5volt pin.
How is the Mega powered.
If you had >7.5volt on the DC jack, and the motor driver connected like that, then the driver could be toast.
Leo..