Control DC and Stepper Motors With L298N Dual Motor Controller Modules

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
asaf
Posts: 19
Joined: Sat Dec 29, 2018 4:32 pm

Control DC and Stepper Motors With L298N Dual Motor Controller Modules

Post by asaf » Sat Dec 29, 2018 4:44 pm

some one have example how to use l298n with pyboard?
i use it with arduino - Control DC and Stepper Motors With L298N Dual Motor Controller Modules and Arduino.
and now i need to use it on pyboard.
Thanks Asaf

OutoftheBOTS_
Posts: 799
Joined: Mon Nov 20, 2017 10:18 am

Re: Control DC and Stepper Motors With L298N Dual Motor Controller Modules

Post by OutoftheBOTS_ » Sat Dec 29, 2018 9:05 pm

First you have to explain whether your controlling steppers or DC motors as both are different code.

Second what are the specs of the motors you want to control(voltage/amperage)

The L298n has a very big forward voltage of 2.8v so is incredibly inefficient that's why they come with such a big heat sink. The only advantage is the the L298n will run at voltages as high as 48v at current as high as 4amp

For all my small robotics I tend to use the l9110s as it forward voltage is 0.7v so it is a really efficient H-bridge but it si only rated to 12v at peak current of 1.5amp

asaf
Posts: 19
Joined: Sat Dec 29, 2018 4:32 pm

Re: Control DC and Stepper Motors With L298N Dual Motor Controller Modules

Post by asaf » Sat Jan 05, 2019 12:35 pm

do you have example code of l9110s and example of connecting the wires to the pyboard.i need to take a car forward and back.
thanks asaf

OutoftheBOTS_
Posts: 799
Joined: Mon Nov 20, 2017 10:18 am

Re: Control DC and Stepper Motors With L298N Dual Motor Controller Modules

Post by OutoftheBOTS_ » Sat Jan 05, 2019 7:41 pm

First it is important for me to understand what type and size of m otors your using. Are you driving stepper motors or DC motors and what are the voltage and amperage of the motors for me to know if a L9110 is suitable for your motors.

Here's the hardware I use for small stepper motors https://www.aliexpress.com/item/3D-Prin ... st=ae803_5

so this is the hardware I normally use fro small DC motors https://www.aliexpress.com/item/L9110S- ... st=ae803_5

Here is the datasheet https://www.elecrow.com/download/datasheet-l9110.pdf

Wiring the L9110: it is dual H-bridge so can drive 2 DC motors. each motor will need 2 input pins from the micro-controller. I use 1 pin as a direction pin and the other as a PWM/speed pin. The power needed to drive the motor will go to Vcc and GND, you will also need to connect GND to your micro-controller. Each motors input controll pins will also need to be connected to the micro-controller where 1 pin can be connected as a digital high/;ow pin and the other as a PWM pin.

please note how setting the input pins relates to how the output power to the motor
truth.JPG
truth.JPG (22.02 KiB) Viewed 2908 times
as you can see when ever the 2 input pins are the same the motor is off and when ever they are different the motor spin and it will spin depending upon the order of which 1 high and which 1 is low.

Software: I use 1 pin as direction pin and the other pin as speed pin. If the direction is low then the motor will get power when ever the speed pin is high so the speed the motor will spin at will be the duty with of the speed pin i.e PWM_duty = desired_speed. If the direction is high then motor will spin the other way and the motor will get power anytime the speed pin is low so you have to invert the PWM duty i.e PWM_duty = 100 - desired_speed

wr300000
Posts: 30
Joined: Sun Jan 14, 2018 3:54 pm

Re: Control DC and Stepper Motors With L298N Dual Motor Controller Modules

Post by wr300000 » Wed Sep 25, 2019 1:32 pm

I plan to make my either ESP8266 or ESP32 module to control bipolar stepper motor thru L298N driver board. I've got an idea to send out 4 binary bits thru 4 ESP GPIO pins directly to synchronize both coil sets inside stepper motor. My question is how to I bind 4 bit together within a half byte of uPython to ensure that I can send all 4 bits out altogether at the same time to L298N driver board ?

Online
User avatar
Roberthh
Posts: 2566
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Control DC and Stepper Motors With L298N Dual Motor Controller Modules

Post by Roberthh » Wed Sep 25, 2019 3:36 pm

You can write directly to the GPIO port output data register with the machine.mem8 or machine.mem16 function. The base output data register of the ESP8266 is at address 0x60000300. Writing a value to that register sets the GPIO bits accordingly. Reading address 0x60000318 returns the state of the GPIO input/latches.
There are also set/clear addresses to affect single bits only. Writing a 1 to a bit at 0x60000304 sets a single output bit, writing a 1 at 0x60000308 clears a single output bit.
The GPIO pins have to be configured beforehand as output pins. For convenience, you can do the using the machine.Pin methods.

Similar for the ESP32. Details can be found in the respective technical references. There surely are calls for that in the esp_idf, but there is no Python API to set more than one bit at once.

Post Reply