B4R Question Step Motor with A4988

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello Friends...

I tried first time stepper motor.
I used Wemoıs D1R1+ NEMA17 step motor + A4988 drver + 24V-2A powersupp.
I connected like under below.
Sample & Decuments

its run with 400-430 RPM max.:cool:
I used 2 method fro drive.
  • Micros() counting
  • DelayMicroseconds()
But Result are diffrent.
With the "DelayMicroseconds()" method, there is no jolt, it works with a high pitched voice.
But;
"Micros() counting" method has vibration and noise. It's like a hammer drill. There is a noisy ride.
There seems to be noise in the electricity.
Whats the problem?

I want to use it as in CNC lathe. I want to connect with wifi and learn the location of the engine simultaneously. I want show PC screen live angle pozitions.
There fore need to more free loops for wifi cominications.


Micros() counting method:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private wemos As D1Pins
    Private Pindir As Pin
    Private Pinstep As Pin
    Private PS As Boolean
    Private DS As Boolean
    Private bekle ,syc ,xx As UInt
    Public Serial1 As Serial
    Private Timer1 As Timer
    Private d1, d2 As ULong
    Private RPM As UInt
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Pindir.Initialize(wemos.D7,Pindir.MODE_OUTPUT)
    Pinstep.Initialize(wemos.D5,Pinstep.MODE_OUTPUT)
    Delay(1000)
    PS=True
    DS=False   
    Pindir.DigitalWrite(True)
    Pinstep.DigitalWrite(True)
    RPM=200
    bekle=(60000000/RPM)/400
    xx=0
    Delay(1000)
    Log("sistem hazır :",bekle)
    Log("RPM :",RPM)
    DS=False
    syc=0
    d1=0
    d2=0
    AddLooper("Dongu")
    d1=Micros
    d2=d1
End Sub

Sub stepH
    Pinstep.DigitalWrite(True)
    'DelayMicroseconds(10)
    PS=True
End Sub

Sub stepL
    Pinstep.DigitalWrite(False)
    'DelayMicroseconds(10)
    PS=False
End Sub


Sub Dongu
    d1=Micros
    If (d1-d2) Mod bekle =0 Then
        
        d2=d1
        
        If PS Then
            stepL
        Else
            stepH
        End If
    End If
    
End Sub


DelayMicroseconds method:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private wemos As D1Pins
    Private Pindir As Pin
    Private Pinstep As Pin
    Private PS As Boolean
    Private DS As Boolean
    Private bekle ,syc ,xx As UInt
    Public Serial1 As Serial
    Private Timer1 As Timer
    Private d1, d2 As ULong
    Private RPM As UInt
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Pindir.Initialize(wemos.D7,Pindir.MODE_OUTPUT)
    Pinstep.Initialize(wemos.D5,Pinstep.MODE_OUTPUT)
    Delay(1000)
    PS=True
    DS=False   
    Pindir.DigitalWrite(True)
    Pinstep.DigitalWrite(True)
    RPM=200
    bekle=(60000000/RPM)/400
    xx=0
    Delay(1000)
    Log("sistem hazır :",bekle)
    Log("RPM :",RPM)
    DS=False
    syc=0
    d1=0
    d2=0
    AddLooper("myLooper")
    d1=Micros
    d2=d1
End Sub

Sub myLooper
    
    Pinstep.DigitalWrite(False)
    DelayMicroseconds(bekle)
    Pinstep.DigitalWrite(True)
    DelayMicroseconds(bekle)
end sub
 

Tayfur

Well-Known Member
Licensed User
Longtime User
Using delay to control the program flow is always a mistake. Use CallSubPlus instead.
Dear @Erel ;
thanks for info.
This function is very practical but not enough for fast drive.

I listed underbelow.
CallSubPlus("x",1,1) >> 150RPM
CallSubPlus("x",2,1) >> 75RPM
CallSubPlus("x",3,1) >> 50RPM
CallSubPlus("x",4,1) >> 37RPM
CallSubPlus("x",5,1) >> 30RPM
CallSubPlus("x",6,1) >> 25RPM

Therefore , I cant drive 285RPM or 305 or 211RPM..
I will add wishlist CallsubPlusX ( with microsecond);)

do you have different idea?

1614002589544.png
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
With the "DelayMicroseconds()" method, there is no jolt, it works with a high pitched voice.
The A4988 drivers are known to make the motors "noisy"... I had them in my 3D printer with 8bit MB... Since then I changed to a 32bit MB with TMC2209 drivers... I just enjoy the silence.
 
Last edited:
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
The A4988 drivers are known to make the motors "noisy"... I had them in my 3D printer with 8bit MB... Since then I changed to a 31bit MB with TMC2209 drivers... I just enjoy the silence.

@Cableguy Thank you for sharing the experience.
This week I will be working with this card.
Apart from the sound, there are sometimes stepping and misfire.
If I'm not successful, I'll use your suggestion.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
The A4988 drivers are known to make the motors "noisy"... I had them in my 3D printer with 8bit MB... Since then I changed to a 32bit MB with TMC2209 drivers... I just enjoy the silence.

Hello friend;

I tried TMC driver. you are correct. its very silence.
But its works 1/8 steps.? How can i use fullstep mode. I cant found documents.
I add wiring under below.

STEP_MOTOR_LAN_ESP32_bb.png
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
The TMCs can work in a variaty of ways, like SPI, UART, etc... I cannot help very much, but I am sure that if you search for info in any 3D-Printing community, you will find some.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I foun this, seems that at best you can drive them at 1/2 step...

1617985237828.png
 
Upvote 0

Laurent95

Active Member
Licensed User
Longtime User
Hello friend;

I tried TMC driver. you are correct. its very silence.
But its works 1/8 steps.? How can i use fullstep mode. I cant found documents.
I add wiring under below.

View attachment 111324

Hi,
I only did a search on "TMC2209 steps" and i found results, take a look at this link, there is all details about this stepper motor driver: TMC2209
So, you can even make it to works in fullstep.
But the couple will be more high, so, put end stop contacts, unless you want a broken machine.
The "sensorless" feature is never the best solution, you can imagine what the power signal on a motor can do on the other signal wires.
So on the UART or TX/RX wires, no matter the type of communication, emmm :eek:
I have CNC milling machines it's not the same than a 3D Printer.

EDIT: At my idea you have a lot of cheap cards to drive the Nemas, why you try to do your own one more ? For a CNC lathe you can even use an arduino with GRBL. For a lathe with stepper motors at 2A you'll certainly not do steel or aluminium, there are a lot of examples on the web, unfortunately all my links i have are in French.
Plus on a Wemos or any ESP8266 cards the Wifi needs MCU cycles to manage the Wifi, it's not really good idea to use them to drive a CNC who need a constant flow of the GCode on the machine.
As far as i know at all time i driven my CNCs i never have really often lost step. It was rare or most of time a collision between the tool and an other part of the piece. But i always use the machine under the max of couple or their max speed on my different motors. The smallest works with GRBL.

To be honest the ESPxx are really not the good MCU to drive a CNC, maybe not enough GPIO, a CNC need several sensors Urgency Stop, end stop, etc. on a milling CNC it's worst, the Wifi need MCU Cycles, you can not stop the loop or make her too busy without a reboot, because the Wifi will stop it through the watchdog.
Try to make a loop too busy and you'll seen your Wemos rebooting often.
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi,
I only did a search on "TMC2209 steps" and i found results, take a look at this link, there is all details about this stepper motor driver: TMC2209
So, you can even make it to works in fullstep.
But the couple will be more high, so, put end stop contacts, unless you want a broken machine.
The "sensorless" feature is never the best solution, you can imagine what the power signal on a motor can do on the other signal wires.
So on the UART or TX/RX wires, no matter the type of communication, emmm :eek:
I have CNC milling machines it's not the same than a 3D Printer.

EDIT: At my idea you have a lot of cheap cards to drive the Nemas, why you try to do your own one more ? For a CNC lathe you can even use an arduino with GRBL. For a lathe with stepper motors at 2A you'll certainly not do steel or aluminium, there are a lot of examples on the web, unfortunately all my links i have are in French.
Plus on a Wemos or any ESP8266 cards the Wifi needs MCU cycles to manage the Wifi, it's not really good idea to use them to drive a CNC who need a constant flow of the GCode on the machine.
As far as i know at all time i driven my CNCs i never have really often lost step. It was rare or most of time a collision between the tool and an other part of the piece. But i always use the machine under the max of couple or their max speed on my different motors. The smallest works with GRBL.

To be honest the ESPxx are really not the good MCU to drive a CNC, maybe not enough GPIO, a CNC need several sensors Urgency Stop, end stop, etc. on a milling CNC it's worst, the Wifi need MCU Cycles, you can not stop the loop or make her too busy without a reboot, because the Wifi will stop it through the watchdog.
Try to make a loop too busy and you'll seen your Wemos rebooting often.
Why do you assume it will be a CNC?
The op is trying (experimenting) stepper motor speed control... it may even be just for a linear actuator... but a fast one!
 
Upvote 0

Laurent95

Active Member
Licensed User
Longtime User
Hi All,

@Cableguy
Why do you assume it will be a CNC?
Because i read all the thread
Post 1
I want to use it as in CNC lathe
Now i assume that maybe it was better to let Tayfur respond ;)

it may even be just for a linear actuator... but a fast one !
I return you the question, why do you assume that ?
No matter, it's the same with an actuator, but the risk would be that the demultiply box could be broken.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi All,

@Cableguy

Because i read all the thread
Post 1

Now i assume that maybe it was better to let Tayfur respond ;)


I return you the question, why do you assume that ?
No matter, it's the same with an actuator, but the risk would be that the demultiply box could be broken.
I apologize... I had read, at least so I thought, the first post thoroughly, but obviously not.
After a much thorough reading, I agree you you 200%.
My advice would be CLS (Closed Loop Stepper-Motors) wich have 2 major abilities/advantages
1 - Zero missed Steps; since it's closed loop, it will always "know" at what step it is.
2 - because of 1, you can know by software at which step you are at.
 
Upvote 0
Top