Help with connecting Arduino clone to L298 based motor driver

I am quite new to the world of robotics, but have years of experience with basic passive components (caps, resistors, etc) so I thought this would be a fun way to start learning more.

To start myself off, I picked up a handful of arduino clones, mostly seeeduinos. I built some motor shields and got those programmed, and working successfully with some cheap hobby motors, I've also successfully managed to get some servo's running without a problem as well.

Now I'm working on a bot that requires a more than the 1A that the L293 based stuff I've been using, so I found this cheap motor driver, based on the L298, that seems like it should work perfectly for me.

The problem is, apparently, I seem to be too inept to figure out how to actually connect the motor driver to the arduino!

My goal is to set the driver board up for PWM control of 2 DC motors. The only information on setting the board up is on the page above--- no additional information was included with the board. To save everyone the trouble, here's the information they provide on the site...

Here's an enlarged image of the board (from their site)

Simple 8 pin interface PWM Mode (GND,VCC,M11,M12,M21,M22,PWM2,PWM1) (Jumpers JP1 & JP2 placed)

 

The markings on the board (for the 8 Pin Header) are actually a bit differrent than the above statement claims... GND, VCC, L1,L2,L3,L4,EN2, EN1

I'm pretty sure the L1, L2, L3, L4 match up with M11, M12, M21, M22 they mention, and that EN2 and EN1 are PWM2, and PWM1.

 

On the other side of the board The terminal blocks are marked a bit better...

VDD, GND, Motor1(2 pins), Motor2(2 pins)

 

With VCC and GND connected to a 9V power source, VDD is puts out 5V, thanks to the onboard 7805, so I am plannning on using VDD/GND to power the arduino-- That's about the only part that works right now =-)

I am planning on using pins 10 and 11 on the arduino for PWM control (EN2 and EN1), but I'm not sure what to do with the L1, L2, L3, L4 pins from the header (also known as M11, M12, M21, M22).

 

I've tried contacting the seller about the mislabelled pins, and asked if they had any guidance on how to wire it to an arduino, but I haven't heard anything back---guess that's why they're cheap.

I could probably figure this all out with the data sheet and meter, but even though this was cheap, I'd still rather not risk screwing that up and blowing up the L298 or the arduino if I get something wrong, so I'm hoping someone here might have an idea of how this should work.


I am open to any and all suggestions. Thanks in advance!

-Lenny

If you check out the photo

If you check out the photo further down the page (which shows the board from a different angle), you can see that the driver IC is specifically an L298N from STMicro. The datasheet for this part should help you with any questions specific to this particular IC (there are others in the L298 range with similar but not identical specs).

From here on out I’ll use the datasheet terminology, so with reference to your 8-pin header, the input side connections are: [GND, Vs, Input1, Input2, Input3, Input4, EnableB, EnableA].
Obviously you’ve already got Vs and GND figured out, but I’ll just mention that the L7805 (VDD output) also feeds into the Vss pin on the L298. Vss is the connection for the logic components of the L298 - it enables TTL (+5V and 0V) level components (like your microcontroller) to interface happily with the L298. Without it, a microcontroller would need to send the full Vs (+9V in your case) to the input pins in order to activate the motors.

Now onto the good stuff. EnableA and EnableB are active-high enables for Output1+Output2 and Output3+Output4 respectively. All this means is that when, for example, the input to EnableA is set to low, Output1+Output2 are disabled. If you were to turn EnableA off while a motor connected to Output1+Output2 was running, the motor would act as if it was removed from the circuit, and it would just spin to a stop when it ran out of momentum.
The 2 jumpers (JP1 and JP2) are designed to connect the Enable pins to Vss, which means that the Output pins are always on, saving you from having to use 2 of your digital output pins to control them… but if you want to run PWM then that’s not very convenient. Make sure you don’t use the jumpers as they’ll try to override your PWM control outputs.
Unsurprisingly, Input1 controls Output1, Input2 controls Output2, and so on. When you wire a motor to ‘Motor1’ output terminals you’re connecting it to Output1 and Output2 (probably… the labelling is a little silly). To drive the aforementioned motor ‘forward’ you need to set EnableA high, Input1 high and Input2 low. This sets Output1 to roughly Vs and Output2 to roughly GND, shoving current through the motor in one direction. If you flip the inputs, making Input1 low and Input2 high, the motor will naturally run the other way. If you set both Input pins to low or both to high then the motor will be shorted out, which acts like an electromagnetic brake. In fact it is an electromagnetic brake. If you pull EnableA low at any time then the motor will freewheel as mentioned earlier, which in some cases is better than having the motor slowed down from the braking effect.

So, to sum up the control scheme for Motor1:
•Motor1 Action •Input1 •Input2 •EnableA
Run forward High Low High
Run backwards Low High High
Stop High High High
Stop Low Low High
Freewheel don’t care don’t care Low

The same applies for Motor2, using Input3, Input4 and EnableB.

As far as connecting to your Arduino clone goes, you can use any of the regular Digital I/O pins for controlling the Inputs, and 2 of the PWM enabled I/O pins for controlling the Enables. It doesn’t really matter which pins, as long as you label them correctly in the code when it comes to programming them.

No doubt there are parts of that post which you already know, but it’s better to go overboard than vice versa =D
Plus after writing so many engineering reports lately it’s hard to stop once my fingers hit the keyboard…

There is a detailed pdf of a

There is a detailed pdf of a similar motor driver at Solarbotics with the same truth table, as Telefox said.

If you need servos for your robots, pin 10 is not a good choice for the motor PWM, because the Arduino Servo Lib uses timer1 for the servos and pin 10 can’t be used for PWM together with servos. Better choice is pin 5, 6 (timer 0) or pin 3, 11 (timer 2). See the Arduino pin map.

Another tip is to use a NPN transistor as inverter for the direction signal. With this modification you only need one direction signal and one PWM signal for a motor. The schematic is also described in the Solarbotics pdf

 

Many thanks

Telefox, you are a gentleman, and a scholar. Your awesome explanation was precisely what I needed to get my motors spinning. You also saved me TONS of frustration by pointing out what the jumpers were actually there for (directing Vss to the Enable pins). I’m not sure if you noticed, but the original site actually had the jumper settings backwards.

From their site…

  • Simple 8 pin interface PWM Mode (GND,VCC,M11,M12,M21,M22,PWM2,PWM1) (Jumpers JP1 & JP2 placed)
  • Also can be used in NonPWM Mode (GND,VCC,M11,M12,M21,M22) (Jumpers JP1 & JP2 open)

Initially when I read the description you provided, after having read the vendor’s “instructions” a few hundred times, I wasn’t sure which one was right, so I took a look at the Datasheet, pulled out my multimeter, and sure enough, with JP1 and JP2 closed, Vss was being passed to both enable pins, just as you (and let’s not forget the datasheet) described.

Again, many thanks!

-Lenny

 

Hehe, I completely missed

Hehe, I completely missed the description being wrong about the jumper settings. Good thing you checked it yourself, since another possibility is that the Enable pins were held high with weak pull-up resistors, with the jumpers used to connect the Enable pins to the input header. I didn’t see any pull-up resistors, but it’s always worth whipping out the multimeter when in doubt.

Anyway, glad to hear you’ve got your controller all set up =D