Reverse direction bug with DRV8835 Arduino library

Hi,

I’m trying to use two single channel DRV8838 and the DRV8835 Arduino library(dual-channel driver) but maintaining a certain speed is not working for reverse direction.
When I try to keep the maximum speed using delay() and motors.flip are false everything works as expected.
e.g.

[code]for (int speed = 0; speed <= 400; speed++)
{
motors.setM1Speed(speed);
motors.setM2Speed(speed); // or motors.setSpeeds(speed,speed)
delay(2);
}

// here we are running at full speed for 2 seconds
// but this is not working for reverse direction.
// for reverse direction the motors stop for 2 seconds and continue when the next for loop starts
delay(2000);

for (int speed = 400; speed >= 0; speed–)
{
motors.setM1Speed(speed);
motors.setM2Speed(speed);
delay(2);
}[/code]
When I try to do the same in reverted direction (flipping the motors or using negative speeds from 0 to -400), during the delay time the motors do not move. I would expect them to run at the maximum speed as for the non-flipped example.

How can I fix this?
Thank you!

P.S.
I’m using this library with two DRV8838 connected accordingly.
It’s working just fine if I try it with the provided library example - one motor at a time, forward and reverse.
But I need this for both motors.

Hello.

We have not tried using our Arduino Library for the DRV8835 Dual Motor Driver Shield with two of the DRV8838 carriers, but I do not see any obvious problems with doing so. What motors and motor power supply are you using? Since it works when you use the example that runs one motor at a time, but not when you try to run both at once, it sounds like it might be power related. Could you try reducing the maximum speed in your code to 200 and seeing if that fixes the problem?

-Brandon

It’s not power related. I’m using HP micromotors at 6V and the Arduino example from the library gradually increases the motor speed so it goes from 0 to 400. My motors don’t stop in the middle of the loop.
The problem with reverse direction is that the motors stop at the “delay(2000);” line. So the first for loop works, then I have a pause of 2 seconds and then it continues with the second for loop. This never happens without reverse direction.

What happens when you reduce the speed to 200?

Ok, I tested with 200 and also with 399 reverse speed and I’m getting the expected behavior.
Why doesn’t it work on full speed(400) like it does with forward direction?

I tried to reproduce the problem here using two DRV8838 carriers and an Arduino Uno, but I was unable to. What Arduino are you using? Could you post the shortest complete version of your program that demonstrates the issue? Also, could you post some pictures of your setup that show all of your connections?

-Brandon

I’m using Arduino Uno R3.
The issue appears with the code bellow.
For negative speed, if I change from 400 to 399, everything works as expected.

Here’s my setup:


[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()
{
// run motors with positive speed

digitalWrite(LED_PIN, HIGH);

for (int speed = 0; speed <= 400; speed++)
{
motors.setSpeeds(speed, speed);
delay(10);
}
delay(3000);

for (int speed = 400; speed >= 0; speed–)
{
motors.setSpeeds(speed, speed);
delay(10);
}

// run motors with negative speed
digitalWrite(LED_PIN, LOW);

for (int speed = 0; speed >= -400; speed–)
{
motors.setSpeeds(speed, speed);
delay(10);
}

delay(3000);

for (int speed = -400; speed <= 0; speed++)
{
motors.setSpeeds(speed, speed);
delay(10);
}

}[/code]

Thank you for posting the extra details. I do not see anything obviously wrong from the diagram you posted. I would still be interested in seeing photos of your actual setup as well. I also tried using the code from your post in my setup here, and it still worked fine (even with the 400 values).

I did notice that a poor ground connection could cause problems that sound similar to what you are describing. Could you try checking the continuity of all the ground connections with a multimeter to make sure they are all solid connections?

If that does not fix the problem, could you try seeing what happens when you change your code to set the speed immediately to -400 instead of ramping up? For example, do the motors spin when you replace the code in your main loop with the code below?

motors.setSpeeds(0, -400);
delay(3000);
motors.setSpeeds(-400, 0);
delay(3000);
motors.setSpeeds(-400, -400);
delay(3000);
motors.setSpeeds(0, 0);

If this results in no movement from the motor, do you have access to an oscilloscope that you can use to look at the signals from your Arduino (when sending a target of -400)?

-Brandon

Hi Brandon,

I checked with your example and the motors work correctly until the setSpeeds(-400, -400) line, where they stop (but work if I change to -399).
The ground connection is pretty solid and I don’t have an oscilloscope.

Thanks for your help!

It does not seem like a software problem since we have not been able to recreate it. From the information we have about your setup, it looks fine. I am not sure how the boards themselves could be bad in a way that would cause this type of problem. Since it is working as expected with the -399 values, you might just use that instead of -400. Alternatively, if you want to continue troubleshooting, you could try with a different Arduino if you have one available. Aside from that, if you wanted to try with another set of DRV8838 drivers, you can contact us through email at support@pololu.com referencing this post, and we can look into helping you out.

-Brandon