Frustrated need for Arduino Example code for High Power Motor Driver 18v25

I and a teacher/coach of an underwater robotics team that requires 20 - 25 amps for each motor. Motors must run in both directions. At Pololu’s recommendation, I bought 6 High Power Motor Drivers 18v25 and want to run them from either an arduino. I know where to get pwm from an arduino, but the “DIR” terminal on the board has me concerned. I know there is a “phase locked” method to handle forward and reverse from pwm, but at this point I am getting lost.

I have a fair understanding of programming, but I need a basic arduino sketch that will give the ability to test run the motors in both directions using an arduino. Can someone please point me in that direction?

Hello.

It sounds like you are mostly concerned about the DIR pin. In the normal sign-magnitude operation, the DIR pin just needs a simple high or low signal to change the polarity of the output channels, so you can connect the DIR pin to any digital output pin on the Arduino board and control it with digitalWrite(). Our DRV8835 Dual Motor Driver Shield Arduino library uses this sign-magnitude operation, so you might try using that as a reference to see how it is handled.

If you are using the driver in a locked-antiphase operation, you can hold the PWM pin high (with digitalWrite() or by simply tying it to a high voltage) and send a PWM signal to the DIR pin. When operating like this, A 50% duty cycle turns the motor off, a lower duty cycle drives the motor in one direction, and a higher duty cycle drives the motor in the other direction.

Brandon

Thank you so much. I did not know that you could use the library for one
device and use it for another product. Early on, I produced some magic
blue smoke from some of my testing and even though I know what I did that
produced the problem; I am still gun shy. From what you are saying, it
looks like I would need to change the duty cycle. But if I just examine
(if statement) the output of the joystick and if I am negative y territory
I can digitalwrite() to DIR. Does that sound correct?

I have an alternative method using raspberry pi and a motor control hat.
If I use the motor output from the hat as my pwm signal, would the 5v
(instead of 3.5v) output be an issue for the Pololu G2 High-Power Motor
Driver 18v25 I purchased?

Thank you again for your help!

Hello.

You generally should not expect a library to work with other products. However, in this case since the DRV8835 shield and the high power motor drivers both use a 2-pin sign-magnitude interface and our library for the DRV8835 shield is just setting up the required PWM signals and controlling the DIR pins with digitalWrite(), it should be fine as long as you make the same connections to the Arduino.

For your application, you might need to expand on that library since it only handles 2 motor channels and you are potentially using 6, which is why I suggested using it as a reference. The library handles the PWM and DIR when you call the setM#Speed() command. That command accepts a speed variable between -400 and +400; if the speed value is negative, it drives the DIR pin high or low, and if it is positive it does the opposite. If you are going to use a joystick signal to determine the motor output, you could do something like you mentioned: if the reading is under the neutral point, set the DIR pin low, and if it is over the neutral point, set the DIR pin high (or visa versa).

It sounds like you are talking about using the motor outputs of a Raspberry Pi HAT as inputs to the G2 motor driver. The G2 High-Power Motor Drivers have a maximum logic voltage of 5V, so a 5V signal is fine, but it is generally not good practice to use the output of one motor driver as an input to another.

Brandon

Thanks again Brandon. I need a solution in place before fall semester
starts. This would be real easy if my current demands were below 5 amps,
however we found out that our demands can exceed 20 amps. I am trying to
control 6 high current motors with forward and reverse ability as well as 5
servos (low power) from an x-box controller. My current solution involves
a Rpi connection to Arduino to High Power motor driver to brushed motor.
Other than the motors being brushed and 12v/20amp (because of large
inventory), is there a better solution from Pololu? I need to make two of
these control stations.

The G2 18v25 motor drivers can handle 25A continuously without additional cooling, so we expect them to be able to handle 20A loads.

By the way, depending on which Arduino you are using, you might not have enough timers and pins available to generate hardware PWM signals and achieve individual control of all of your motors and servos. If that is the case, you might be interested in using one of our Maestro servo controllers. The Maestros generate hobby RC servo signals and can be controlled from an Arduino via a TTL serial interface. We also have an Arduino library for them, which makes it easy to get started programming. For a system that controls 5 servos, the 6-channel Maestro would be an appropriate fit.

-Jon

Jon, this looks like a much better solution instead of all of the garbage
that I am going through. Could I use an input device such as a usb game
controller with the maestro? I am starting to worry about control lag with
two or three devices in series.

The Maestro cannot be controlled directly with a USB game controller. You would have to use something like a Raspberry Pi to read the controller’s inputs, and then send your own control signals to the Maestro or your Arduino. As for your other concern, it is difficult to assess how much lag you might get without determining which parts are being used first. In general, I do not expect the amount of lag introduced by communicating between a Raspberry Pi and Arduino or an Arduino and a Maestro to have much impact on your ROV.

-Jon