DRV8835 coding for arduino (micro) help request

Is there anyone willing to share thier arduino code on getting the DRV8835 working with PWM and dual motors (tank drive). I am still learning arduino and am just working on a basic obstacle avoider bot. Most of my programming knowledge comes from taking pieces from other people’s published code for use in my project. My avoider uses 3 HC-SR04 ultrasonic sensors for distance/obstacle sensing…so i plan on using ultrasonic to feed the input to adjust the PWM speed. Thanks for any assistance.

Hello.

We do not have any specific example code for using the DRV8835 motor driver with an Arduino, but if you try writing the program for your obstacle avoidance robot and have trouble, you can post your code here, and I will take a look at it.

-Brandon

Here is the code I am using to test the motors…
I am using an arduino micro, I have 2 of the pololu micro gear motors (50:1), and am running 6vdc to the DRV8835 for motor power, the VCC in is from the arduino micro 5 volt supply pin and I am running the DRV8835 in mode0.
I have both motors going forward and reverse just fine…but the left turn and right turn don’t work…

// ------------------------------------------------------- Motors
int motor_left[] = {6, 5};
int motor_right[] = {10, 9};

// ------------------------------------------------------- Setup
void setup() {
 Serial.begin(9600);
 
// Setup motors
 int i;
 for(i = 0; i < 2; i++){
 pinMode(motor_left[i], OUTPUT);
 pinMode(motor_right[i], OUTPUT);
 }

}

// -------------------------------------------------------- Loop
void loop() { 

drive_forward();
 delay(5000);
 motor_stop();
 Serial.println("1");

 drive_backward();
 delay(5000);
 motor_stop();
 Serial.println("2");

 turn_left();
 delay(1000);
 motor_stop();
 Serial.println("3");

 turn_right();
 delay(1000);
 motor_stop();
 Serial.println("4"); 

motor_stop();
 delay(1000);
 motor_stop();
 Serial.println("5");
}

// --------------------------------------------------------------------------- Drive

void motor_stop(){
 analogWrite(motor_left[0], 1); //brake (outputs shorted to ground
analogWrite(motor_left[1], 1); 

analogWrite(motor_right[0], 1); 
analogWrite(motor_right[1], 1);
 delay(25);
}

void drive_forward(){
 analogWrite(motor_left[0], 255); 
analogWrite(motor_left[1], 0); 

analogWrite(motor_right[0], 255); 
analogWrite(motor_right[1], 0); 
}

void drive_backward(){
 analogWrite(motor_left[0], 0); 
analogWrite(motor_left[1], 255); 

analogWrite(motor_right[0], 0); 
analogWrite(motor_right[1], 255); 
}

void turn_left(){
 analogWrite(motor_left[0], 0); 
analogWrite(motor_left[1], 255); 

analogWrite(motor_right[0], 255); 
analogWrite(motor_right[1], 0);
}

void turn_right(){
 analogWrite(motor_left[0], 255); 
analogWrite(motor_left[1], 0); 

analogWrite(motor_right[0], 0); 
analogWrite(motor_right[1], 255); 
}

I do not see anything obvious in your code that would cause a problem. Do you have a ground connection between your DRV8835 and the Arduino Micro? Could you clarify what you mean when you say that left turn and right turn don’t work? If you change your code to only call your “turn_left” subroutine and take everything else out, what do the motors do?

-Brandon

My connections:
Arduino ground to breadboard ground line, 8835 ground to ground line
Arduino 5v supply to 8835 VCC
Arduino pin 6 to 8835 BENBL
Arduino pin 5 to 8835 BPHASE
Arduino pin 10 to 8835 AENBL
Arduino pin 9 to 8835 APHASE
Mode is not used

8835 Ground and VIN (motor output side of controller) has 6VDC battery +/- only (not attached to arduino ground line)
Bout1/2 to left motor
Aout 1/2 to right motor
VMM not used.

I have the program ouputting the step it completes and the motors work for forward (1), reverse (2), and brake (3), but not left 4 and right turn 5. The motors have no power for left and right turns.
I cut out everything but the left and right turn from the code above, and the motors still won’t move…

I still can’t get this motor controller to work for me…anyone out there have arduino code for any of the Texas Instruments DRV88xx chips?

I did switch over to a L293D and can get it to work fine with PWM and both digital and analogwrite() function. It would appear that I am not using the truth table correctly in the coding. Looks like it should be straight forward, but it sure isn’t working that way. I would keep the L293D, but it makes quite a bit of noise, so was hoping the DRV8835 would work better/quieter.

Your connections all sound correct to me. By the way, you should have a common ground in your system, and since you have your Arduino ground and your motor supply ground connected to the DRV8835, you do have a common ground between them.

I do not see how your forward and reverse commands would work correctly without your turning commands working, unless your motor connections are switched somehow (e.g. your left motor has one lead going to a Bout pin and one going to an Aout pin). Could you double check that your motor connections are connected how you described? If they all seem correct, could you post a picture of your setup including all of your connections?

I also noticed that in your “motor_stop” subroutine, you are using an analogWrite value of 1, which is different than the “1” indicated in the operation chart on the DRV8835 product page. The “1” in the chart is a digital high, which you can use an analogWrite value of 255 to simulate.

-Brandon

This is an old thread, but I found it while looking for something else. Thought I would chime in…

The drv8835 has two modes. When the mode pin is low, the control pins directly turn the corresponding output pins on and off. When the mode pin is high, one control pin is for direction and the other is pwm input.

You need to have the mode pin wired high.

Murray