Help using DRV8835 Motor Driver with Arduino UNO - Controlling Direction Independently For Two Motors

Hey guys,
I am trying to control the direction of two DC micro metal gearbox motors and so I recently received the DRV8835 dual motor driver carrier from Pololu however after having assembled the 2 motors and the driver with my arduino uno, I am having difficulty trying to control the direction of both motors. Sorry, I am very inexperienced and new to this field and would definitely appreciate any help with this issue.

To describe my situation, after receiving the DRV8835 I first soldered on 12 wires connecting to the AOUT1, AOUT2, BOUT1, BOUT2, AIN1, AIN2, BIN1, BIN2, VCC, GND, VIN, and GND. Currently I am using a 6V battery case powered by four AA batteries as my external power supply to power the motors. I have assured that AOUT1, and AOUT2 are connected to my first motor, and BOUT1, and BOUT2 to my second. Regarding my connections to the Arduino UNO, the AIN1 and AIN2 points are connected to pins 7 and 8, and BIN1 and BIN2 to pins 12 and 13. I thought that because I do not have anything connected to the MODE pin on the DRV8835, that the board is thus in IN/IN mode which means that I do not need to have any PWM connections however I am unsure of what to do here. For logic power, I am using the 5V connection from the Arduino UNO.

When I was testing the above setup, with this code:

#include <DRV8835MotorShield.h>

#define LED_PIN 13

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()
{
  digitalWrite(LED_PIN, HIGH);
  motors.setM1Speed(400);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  motors.setM1Speed(0);
  delay(1000);
  digitalWrite(LED_PIN, HIGH);
  motors.setM1Speed(-400);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  motors.setM1Speed(0);
  digitalWrite(LED_PIN, HIGH);
  motors.setM2Speed(400);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  motors.setM2Speed(0);
  delay(1000);
  digitalWrite(LED_PIN, HIGH);
  motors.setM2Speed(-400);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  motors.setM2Speed(0);
  delay(1000);
}

(sorry, I did not know what feature to use to post my code here in the appropriate format)

I thought this code should make the first motor spin in the positive direction, then stop, the negative, then stop, and repeat for the second motor however upon testing this, motor A spins in a direction A, then both motors spin with motor A spinning in the same direction and motor B spinning in direction B, then with motor B stopping as motor A continues in the same direction for another second, and after a second of nothing lastly motor A spins again in direction A and this time motor B spins in direction A. Its very weird to me how the motors behave like this. I tried to attach the arduino pins to the PWM pins 5,6 and 9,10 just to test and what happened was whenever the code said to turn M1 at either 400 or -400, motor A would spin in one direction, and whenever the code said to turn M2 at either 400 or -400, the motor would spin in the other direction which I did not understand.

I am trying to get this to work by using IN/IN mode and my goal is to be able to control each motor independently in terms of direction by telling the motors which way to spin and when to stop. I am not however at this point concerned with controlling the speed of each motor however if it was possible in IN/IN mode, it would be convenient. Thank you, any help is appreciated.

From your description and code, it looks like you might be confused about how our DRV8835 Arduino library works. The Arduino library uses the driver in Phase/Enable mode and assumes specific pins for the motor control signals, so in order to use it, you must use the same connections. The library is written to work for our DRV8835 shield, which uses pins 7 and 9 for APH and AEN respectively, and pins 8 and 10 for BPH and BEN respectively. The default state of the mode pin on the DRV8835 Dual Motor Driver Carrier is LOW, so in order to use the library, you will need to drive this pin HIGH as well.

By the way, It sounds like you are under the impression that IN/IN mode does not use PWM signals. Please note that the DRV8835 when in IN/IN mode actually needs 4 PWM signals to control the speed of each motor independently, whereas Phase/Enable mode only needs 2 PWM and 2 digital signals.

Brandon

Thank you for the reply Brandon, it cleared up a lot of confusions I had about the way the DRV8835 worked especially the fact that Phase/Enable mode required certain pins. For my project, I don’t think I will be concerned as much about speed control yet and will likely be using just 4 digital signals with In/In mode to just control motor direction, however the information regarding speed control will be useful to me in the future. Thanks again.