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.