L298N Motor Driver Board Pyboard 6V DC motors
L298N Motor Driver Board Pyboard 6V DC motors
Hello, I'm new to python and brand new to micro python. Working on a project with the L298N motor controller board, Pyboard V1.1 and a single 6v 71mA - 470mA 1.92Kgcm tourque DC motor. I have spent the last few hours trying to make the motor turn. This motor controller has three pins to control motor A, an enable pin that also reads the pwm signal for speed control, and two more pins that are in a high or low state to control the rotation direction of the motor. I am using pyBoard pins X1 for pwm and X2 and X3 for high or low . I searched the internet and not able to find a basic way to implement this with the pyboard and L298N motor controller. I am not well understanding how this should be done, is most of the problem. Can anyone help me with the details of making this motor turn?
Re: L298N Motor Driver Board Pyboard 6V DC motors
Hi,
The L298N is a dual full-bridge controller. To learn more about this, I'd start with a full-bridge (often called an H-bridge). The basic idea of an H-bridge is that it has two inputs (A and B). To go forward, you turn on A and turn off B, backward turn off A, turn on B.
The L298N extends this by ANDing A and B above with the enable.
Anyway, the simplest thing to test would be to turn on A, turn off B, and turn on EN. (Forget about PWM for now).
Then to go in reverse
Next for speed control by PWM-img the enable pin. (This just means you're turning it on/off really fast, which means the motor is only turned on for some percentage of the time.
This should run at 1/4 speed.
(Adapted from https://docs.micropython.org/en/latest/ ... ckref.html )
I knew to use Timer channel 2, because X1 is connected to Timer2 (see https://store.micropython.org/product/PYBv1.1#image5)
The L298N is a dual full-bridge controller. To learn more about this, I'd start with a full-bridge (often called an H-bridge). The basic idea of an H-bridge is that it has two inputs (A and B). To go forward, you turn on A and turn off B, backward turn off A, turn on B.
The L298N extends this by ANDing A and B above with the enable.
Anyway, the simplest thing to test would be to turn on A, turn off B, and turn on EN. (Forget about PWM for now).
Code: Select all
from machine import Pin
en = machine.Pin('X1', machine.Pin.OUT)
a = machine.Pin('X2', machine.Pin.OUT)
b = machine.Pin('X3', machine.Pin.OUT)
a.on()
b.off()
en.on()
Code: Select all
a.off()
b.on()
This should run at 1/4 speed.
Code: Select all
import pyb
pwm_timer = pyb.Timer(2, freq=1000)
pwm_channel = pwm_timer.channel(1, pyb.Timer.PWM, pin=en)
pwm_channel.pulse_width_percent(25)
I knew to use Timer channel 2, because X1 is connected to Timer2 (see https://store.micropython.org/product/PYBv1.1#image5)
Re: L298N Motor Driver Board Pyboard 6V DC motors
Also, can you link to the board you're using with the L298N? There may be some additional connections you have to make.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: L298N Motor Driver Board Pyboard 6V DC motors
I play with motors a fair bit as love robotics and I find the L298N a really crap H-Bridge for any smaller motors. The L298N has a huge forward voltage of close to 3v. This means first of all it is super inefficient and gets really hot and drains your batteries very quickly. If you need to power 6v DC motor then you will need a 9v power supply as the H-Bridge chews 3v.
I tend to use the L9110s as it has only about 0.7v forward voltage and after using it on heaps of small DC motors have found it to work very well. Due to how it pins work I basiclly use 1 pin as a direction pin and the other pin as a PWM speed pin, this means you onbly need 2 pins per motor where as the L298N needs 3 pins per motor.
The L9110s is super cheap see https://www.aliexpress.com/wholesale?ca ... ext=L9110s
I tend to use the L9110s as it has only about 0.7v forward voltage and after using it on heaps of small DC motors have found it to work very well. Due to how it pins work I basiclly use 1 pin as a direction pin and the other pin as a PWM speed pin, this means you onbly need 2 pins per motor where as the L298N needs 3 pins per motor.
The L9110s is super cheap see https://www.aliexpress.com/wholesale?ca ... ext=L9110s
Re: L298N Motor Driver Board Pyboard 6V DC motors
Thanks for the info. getting going in the right direction. Here is the board I'm using with the L298N.
https://docs.micropython.org/en/latest/ ... ckref.html
Being powered with a 9.9V 1500mAh battery, I guess is should be fine to turn the 6V motors. Good to know about the inefficient controllers but for this version have to work with what's here. Thanks again!
https://docs.micropython.org/en/latest/ ... ckref.html
Being powered with a 9.9V 1500mAh battery, I guess is should be fine to turn the 6V motors. Good to know about the inefficient controllers but for this version have to work with what's here. Thanks again!
Re: L298N Motor Driver Board Pyboard 6V DC motors
Sorry, I meant the board that contains the L298N. e.g. https://tronixlabs.com.au/robotics/moto ... australia/
Re: L298N Motor Driver Board Pyboard 6V DC motors
This is the motor controller board;
https://www.lelong.com.my/arduino-l298n ... Sale-P.htm
Thanks for the instructions Jimmo, the motor is turning!
https://www.lelong.com.my/arduino-l298n ... Sale-P.htm
Thanks for the instructions Jimmo, the motor is turning!
Re: L298N Motor Driver Board Pyboard 6V DC motors
Great, yep that answers my question. Nothing extra to do.johnbanes wrote: ↑Sat May 25, 2019 1:46 pmThis is the motor controller board;
https://www.lelong.com.my/arduino-l298n ... Sale-P.htm
Excellent, and speed control working too?
Re: L298N Motor Driver Board Pyboard 6V DC motors
Yes sir, all good.
Re: L298N Motor Driver Board Pyboard 6V DC motors
I'm adding a second motor to the code, do I need to to also add another Timer.PWM for the second motor or can both motors use the same timer channel?