Help with connecting dual MC33887 to Arduino Mega

Hello

Im in the process of building my 1st robot with an arduino mega (coming in soon). My initial plan is build a simple differential drive robot (light or proximity sensing) running on two 12V motors. Would be extremely grateful if someone could guide me, as i am not well versed with electronics.

Two of these geared motors are coming in from ebay and all i know bout them is that they are 300rpm and 5W. So im guessing power is approx 0.5A (stall??). I have also ordered a polulu Dual MC33887 Motor Driver.

I’ve done up a rough diagram on how i ‘think’ it should be connected.

A few questions regarding this.

  1. Are the connections correct?

  2. Does pin EN go to the 5V on the arduino, or do i connect it to an external +5v supply? Or do i need to connect it at all?

The MC33887 datasheet states this about pin EN:

From the product description page:

  1. Does pin D2 need to be connected at all? ie, can the robot run without PWM ? From what i’ve understood, without PWM, the motors will come to a sudden halt instead of gradually decelerating or accelerating, if logic states are reversed.

  2. The two motors are 12V each, hence will it make sense to provide two 12V power sources in parallel?

  3. Pins FS, FB and D1 are not connected, and i presume these are ok for a simple robot.

Thanks very much for reading.


Hello.

You should connect the big ground pad (the one on the left) directly to your battery’s ground, not to the Arduino’s ground. If you connect it to the Arduino’s ground, all of the current used by your motors will need to flow through the Arduino to get from your motors to the battery, and the Arduino’s ground traces probably aren’t designed to handle this amount of current. Notice how big the left ground pad is, and how much copper there is around it? This is all to support large amounts of current. If you look at the Arduino’s ground connections, they are probably much smaller holes with thin traces that will burn out if you put a few amps through them continuously.

The statements you quoted should make it clear that you cannot leave this pin disconnected if you actually want the motor drivers to do anything other than sit in low-power sleep mode. You need to put 5V on the enable pins; it doesn’t matter where this 5V comes from as long as it’s got a common ground with the board. The simplest solution is probably to use the Arduino’s 5V, or you can connect both enable lines to one of your digital outputs and drive it high to wake the drivers (if you have a digital output to spare).

You need to make a connection to D2, but it doesn’t have to be a PWM output. You can connect it straight to a 5V source and just use inputs 1 and 2 to control the motors. You should understand that the motor driver just puts the full battery voltage across the motor outputs in the direction you’ve specified to make your motor run forward and reverse. Using a PWM causes the driver to rapidly alternate between full voltage and no voltage so that the motor spins at a speed proportional to the percentage of time the driver has full voltage across the motor outputs. Without using PWM, your motors will only ever move at full speed, which will make your robot jerky and difficult to control.

No. Connecting separate power sources in parallel is rarely a good idea; it is almost always better to use a single battery/battery pack with more capacity. For example, a 12V car battery has much more capacity (and hence can deliver much more current) than eight alkaline AAA’s in series. If eight AAA’s don’t cut it, you should move to eight AA’s (or Cs, or Ds, or NiMHs, etc), not add another 8 AAAs in parallel.

It’s definitely reasonable to leave these pins disconnected for simple applications.

- Ben

Ben, That was most helpful. Thank you very much.

I’ve modified the diagram as per your advice; I hope it got it right this time!

I was pretty sure that i had to power the EN pin, but i thought id ask just to confirm. Regarding batteries, could i ask as to why connecting in parallel isnt the best choice? Not to doubt what you said, but a lot of tutorials/FAQs suggest that increasing current flow for robotic applications can be achieved by parallel connections.

Thanks very much.


Those connections look good to me.

Using a single battery will be more efficient than using two batteries of lesser capacity in parallel, so unless your project has some weird constraints, you’re usually better off getting a higher capacity battery. For example, a AA alkaline has roughly twice the weight and volume of a AAA alkaline, but it typically has three times the capacity (so it can supply roughly three times the current). Additionally, different batteries will probably be at slightly different voltages, and they might discharge at slightly different rates. What this means is that you’re effectively shorting different voltages together when you connect them in parallel, which causes current to flow between the batteries until their voltages are equalized. This can lead to unnecessary power loss, especially if the batteries you have connected in parallel are not well matched.

- Ben

Very informative post. Thank you Ben.

Hi, for everyones sake i’m not going to be half asleep making this post.
I’m using an Arduino Duemilanove, my questions (to list them specifically)

  1. What kind of code would be used to control the Dual MC33887 using my arduino Duemilanove?
  2. Does the dual MC33887 allow for Multi-Direction control over the motors?
  3. Is there a truth table for this motor driver?

As an FYI I have done a decent amount of coding but not in these areas.
Thanks a I will do my best not to have awful posting like the one previous to this.
-Dylan

Hello and welcome.

Regarding the “nube to posting” comment, just try to communicate well. So far, your haphazard punctuation and missing words (I think) make your post look lazy, and if your code is similar, you’ll probably have a tough time with programming. Just look at your last sentence. Are you just missing a period, and is your point that you have some experience with your Arduino? Did you mean “as well”? (In that case, I’m left wondering if you actually have an Arduino Mega or a different Arduino.)

Have you programmed anything yet? If not, you might start with something simpler. If so, you should ask a more specific question.

- Jan

_

I changed the last posting Jan, it now has been re-worded, it helped to not be half asleep while posting.
-Dylan

Hello Dylan.

This is a very broad question so I’m not sure what kind of answer you are expecting. Most generally, you’ll probably want to use Arduino digital outputs to control the direction of the motors via the IN1 and IN2 pins and Arduino PWM outputs to control the motor speed via the !D2 (PWM) pins. Digital I/O with the Arduino is very easy, and you should be able to use AnalogWrite() (or something similar as I’m not entirely sure of the syntax) to generate PWMs. You might also use analog inuts to monitor the motor currents and digital inputs to monitor for motor faults, though this is entirely optional.

Yes, the MC33887 motor drivers each implement a full H-bridge. If all you want is unidirectional speed control, you could get by with a single MOSFET and wouldn’t need anything as advanced as an MC33887.

There is a truth table in the motor driver’s datasheet, which can be found under the resources tab of the dual MC33887 motor driver carrier product page.

- Ben

Ben thanks for the speedy reply,I wrote some code for controlling the motor driver. This should be of some help to anyone trying to control the driver but does not know how to code to do so.

int D2L = 1;
int IN2L = 2;
int D2R = 3;
int IN1R = 4;
int IN2R = 5;


void setup()
{
  pinMode(D2L, OUTPUT);
  pinMode(IN2L, OUTPUT);
  pinMode(IN1L, OUTPUT); 
  pinMode(D2R, OUTPUT);
  pinMode(IN1R, OUTPUT); 
  pinMode(IN2R, OUTPUT); 
}

void loop()
{

  
}


void leftspeedcontrol()
{
  digitalWrite(, LOW);
  delay(20);
}

void leftforward()
{  //leftforward
 digitalWrite(IN1L, LOW);
  digitalWrite(IN2L, HIGH);
  delay(20);
}

void leftbackward()
{
  digitalWrite(IN1L, HIGH);
  digitalWrite(IN2L, LOW);
  delay(20);
}

void rightspeedcontrol() 
{
  digitalWrite(, LOW);
  delay(20);
}

void rightforward()
{ //rightforward
 digitalWrite(IN1R, LOW);
  digitalWrite(IN2R, HIGH);
  delay(20);
}

void rightbackward()
{  //right reverse
  digitalWrite(IN1R, HIGH);
  digitalWrite(IN2R, LOW);
  delay(20);
}

I am working on a library for this but it will be some time in coming, perhaps a week or two.