L298N with stepper motor on ESP32

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
minusplusminus
Posts: 4
Joined: Sun Feb 09, 2020 1:19 pm

L298N with stepper motor on ESP32

Post by minusplusminus » Mon Mar 23, 2020 4:43 pm

Hi, I have seen this post regarding using the L298N on a non ESP32 board:
viewtopic.php?t=6477

I'm figuring out how to do this on my board. I don't understand how to set the pulse width and timer values on ESP32.
This is what I have. There is movement when I exectute this command, but beeping from the stepper for the frequency. But no further movement.

Code: Select all

import time

import machine
from machine import Pin, PWM
en = machine.Pin(14, machine.Pin.OUT)
IN1 = machine.Pin(2, machine.Pin.OUT)
IN2 = machine.Pin(0, machine.Pin.OUT)

#forward
IN1.on()
IN2.off()
en.on()

pwm2 = PWM(en, freq=1000, duty=512)

I'm using this board. https://www.velleman.eu/products/view?i ... be&lang=nl

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

Re: L298N with stepper motor on ESP32

Post by OutoftheBOTS_ » Tue Mar 24, 2020 9:59 am

First of all are you using a stepper motor or a DC motor??

The current code you posted will turn a DC motor but not a stepper motor.

Although it is possible to drive a stepper motor with a dual H-Bridge like a L298N this will have many disadvantages to using a stepper driver.

Normally what matters most with a stepper is current and you will adjust the voltage until you get the needed current. With a stepper driver they chop amps to what ever you set them to and you just supply more voltage than needed.

Also do be aware that all h-bridges have voltage drop across the H-Bridge, i.e the voltage you supply the H-bridge isn't the voltage the motor receives as the H-bridge will use up some voltage turning it to heat thus the big heat sinks you see on H-Bridge. The L298N is partially inefficient.

It is super important that you match the driver to the motor (DC or stepper and voltage and currents needs)

Please post the motors that you want to drive :)

minusplusminus
Posts: 4
Joined: Sun Feb 09, 2020 1:19 pm

Re: L298N with stepper motor on ESP32

Post by minusplusminus » Tue Mar 24, 2020 3:09 pm

Hi,

Thanks for your reply

I'm using the nema 17 for this. That's a shame, the guy in the shop sold me this as an universal stepper motor driver. Does this one work? https://learn.adafruit.com/adafruit-tb6 ... r-breakout

Edit:

i've experimented a bit.

used this tutorial:

https://lastminuteengineers.com/stepper ... o-tutorial

Connected the L298N together with AccelStepper port:


https://github.com/pedromneto97/AccelSt ... icroPython

Code: Select all

import time

from machine import Pin


from AccellStepper import AccelStepper, FULL4WIRE


IN1 = Pin(2, Pin.OUT)
IN2 = Pin(14, Pin.OUT)
IN3 = Pin(0, Pin.OUT)
IN4 = Pin(4, Pin.OUT)

stepper = AccelStepper(FULL4WIRE, IN1, IN2, IN3, IN4, False)

stepper.set_max_speed(1000)

while True:

    print('reset to position')
    stepper.set_current_position(0)
    while stepper.current_position() != 800:
        print(stepper.current_position())
        stepper.set_speed(300)

        stepper.run_speed()
    time.sleep(2)

I've mentioned that this driver works best on 5v 0.2A. Higher or lower creates stuttering. I don't know if this sensitivity is common? I've mention that the pull power is extremely low

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

Re: L298N with stepper motor on ESP32

Post by OutoftheBOTS_ » Tue Mar 24, 2020 10:40 pm

Ok Nema 17 is a physical size of a motor it doesn't tell me what amps or volts it should be driven at. Although it is probably a stepper motor servo motors also come in this size.

Atm all the motor drivers you are posting are what is a called a H-bridge. like all the H-bridges you have posted it is a dual H-bridge (2 h-bridges). This can drive 2 DC motors or 1 stepper motor but it is the gard way to drive a stepper.

Usually you will drive a stepper with what is called a stepper driver. A stepper driver is a dual H-bridge with some other added circuits to make it much easier to drive steppers. These stepper drivers will create the step pattern and also chop the amps at pre-set.

Please post a link to the exact nema17 your using so I can tell the correct amps.

3d printer usually use nema17 steppers and they call there stepper drivers step sticks. These step stick will at very most drive 1.5amps. Most nema17 will drive at less than 1.5amps but I do have nema17 here that drive as high as 2amps and can't be driven off a 3d printer step stick.

A bit of a youtube tutorial I found here https://www.youtube.com/watch?v=LUbhPKBL_IU&t=1201s

Post Reply