Arduino Forum

Using Arduino => Project Guidance => Topic started by: ceduq on Oct 17, 2019, 09:27 pm

Title: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 17, 2019, 09:27 pm
In order to build a sampler, I use a stepper motor to move a tray along a linear rail. I'm using a NEMA 17 size motor with a step angle of 1.8° and a peak current of 1.68A/phase.
The stepper motor and the driver are mounted as follows:
(https://wiki.mchobby.be/images/c/cf/STEPSTK-DRV8825-WIRE_01.png)

Instead of the Arduino, I use a Beaglebone Black.
I also set the current limit to 0.9 using the formula: Current Limit = VREF x 2 x 0.7 (for full step mode)

Finally, my motor connection is as follows: (after checking the pairs with a multimeter)
B2 : blue ; B1: red ; A1: green ; A2: black.

My problem :
-> all the connections seem ok but my stepper motor makes an abnormal strident noise as soon as I feed it...

(there is a picture of my electrical installation as an attachment)
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: 3Dgeo on Oct 17, 2019, 09:39 pm
M0/M1/M2 pins on the driver is for microstepping,  try highest microstepping, that should improve the situation. Also for optimal result steppers should be eased in/eased out.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Wawa on Oct 17, 2019, 09:51 pm
Instead of the Arduino, I use a Beaglebone Black.
Do you think you should be getting help on an Arduino forum?
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Railroader on Oct 17, 2019, 10:53 pm
@3Dgeo
I would recommend the opposite in the beginning. Use single step to verify the function, direction, number of steps per rev etc.
@OP
Do You have documentation telling where A1, A2, B1 and B2 connects? Else, try switching B1 and B2, or the As.
"Beaglebone Black" sounds like a line in the restaurant menue so coding help will probably be limited here.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 18, 2019, 05:28 pm
Yes, I already try to switch the stepper motor connections (B1 with B2 and B1,B2 with A1,A2).
I put in attachment the technical document of the motor with the connections. I also tried to plug the microstep pins but nothing change. The more I leave the motor under power (less than a minute), the more the noise increases.

To answer to @Wawa, the beaglebone black is a great combination of some of the interfacing flexibility of the Arduino with the fast processor and full Linux environment of the Raspberry Pi (more so in fact). The BeagleBone has good input/output features and can easily connect to the network, so I can have it run a web server to make its readings available to me. But the Arduino community is more developed, so it's more interesting for me to ask my question here.

(https://i1.wp.com/cdn.makezine.com/uploads/2013/04/screen-shot-2012-10-25-at-9-33-34-pm.png?resize=483%2C406)

Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Railroader on Oct 18, 2019, 06:07 pm
Study the driver board, how to set it up, especially regarding stepping. Don't use random and guesses.
Have connected the ENABLE pin to GND?
When power is on, try to turn the stepper by hand. Does that work easily or not?
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: groundFungus on Oct 18, 2019, 06:45 pm
It would help if you post the code that you  tried when you got the noise.  It may be that 3Dgeo is onto something in that you may be trying to get the motor to run at too high a speed from a dead stop.  Acceleration is the answer to that.  The AccelStepper library (https://www.airspayce.com/mikem/arduino/AccelStepper/) allows acceleration.  Try the Bounce example.

Read the how to use this forum-please read sticky (https://forum.arduino.cc/index.php/topic,148850.0.html) to see how to properly post code and some advice on how to ask an effective question.  Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 18, 2019, 06:48 pm
To answer to @RailRoader
No, the ENABLE pin isn't connected to the GND, do I have to do it?
When to power is on, i can't turn the stepper motor with my hand..
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Railroader on Oct 18, 2019, 06:55 pm
Strange. The ENABLE normally needs to be connected to GND to put out pwr to the stepper cables.
Disconnect the stepper and try turning it. That is what it feels like without pwr. Then connect ENABLE to GND, connect the stepper, put on Power, try again to turn and compare. I think there would be a greate difference.

@groundFungus. Where to start......
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: groundFungus on Oct 18, 2019, 07:02 pm
I would like to see their code, to start.   

I agree, the enable must be LOW for the motor to run.  If the motor makes the clunk sound when powered but will not run and is hard to turn by hand, I think that it is getting power, but not step pulses or step pulses are to fast.

Try Robin2's simple stepper program (https://forum.arduino.cc/index.php?topic=277692.0) to get the motor working.

And Robin2's stepper basics tutorial  (https://forum.arduino.cc/index.php?topic=284828.0)may have information that will help.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: MorganS on Oct 18, 2019, 07:17 pm
Measure the motor yourself with a meter to confirm that the wire you think is A1 is actually connected to A2 and ISN'T connected in any way to B1 or B2.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Railroader on Oct 18, 2019, 07:25 pm
@groundFungus.
Yes, code does play a roll.... The actual code.

@OP and @ MorganS
I once got a strangly working stepper. Having experience from running steppers I was puzzled. After some time I found a damage to one cable was much more than cosmetical. The copper wire inside was cut off! Reparing the broken cable made the stepper dance like it should. If is is China stuff everything is possible.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 21, 2019, 03:49 pm
Sorry for answer too late.
I tried to connect the Enable pin to the GND but the noise still persists and it is impossible to turn the stepper motor by hand.

I also tried to follow this pattern in order to put the Enable pin on LOW:
(https://wiki.mchobby.be/images/thumb/b/b2/DRV8825-Montage_Rouge-Bleu-Vert-Noir.jpg/640px-DRV8825-Montage_Rouge-Bleu-Vert-Noir.jpg)
But my motor didnt react anymore and I still could not turn it by hand.

Otherwise, here is the code I use to run the stepper motor. Note that the syntax is slightly different because I use a beaglebone:
Code: [Select]
#import Arduino library
from bbio import *

#Define pins
stepPin = GPIO2_3
dirPin = GPIO2_4

#Set the pins as output
def setup():
             pinMode(stepPin, OUTPUT)
             pinMode(dirPin, OUTPUT)

def loop():
             digitalWrite(dirPin, HIGH)
             for i in xrange(0,200,2):
                         digitalWrite(stepPin, HIGH)
                         delayMicroseconds(500)
                         digitalWrite(stepPin, LOW)
                         delayMicroseconds(500)

              delay(1000)

run(setup, loop)


when I run the code, the motor tries to turn but can not. So I tried to change the delay for: delayMicroseconds(1000)
but the problem is not solved.
During my first tests with the stepper motor( 1 week ago), he responded well to the code (despite the shrill noise). But today he doesnt answer at all. I think the condition of the motor is getting worse as I test it.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: MorganS on Oct 21, 2019, 04:52 pm
What is the power supply?

Did you measure the motor like I asked?
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 21, 2019, 05:18 pm
The power supply is a 12V 3.4Amp/h.

Yes, i checked the pairs with a multimeter set in "Buzzer" mode. The blue and red wires are together and the green and black wires are together. Then, I checked on the stepper motor datasheet which wires correspond to B1/B2 and A1/A2 :
- blue and red wires = B
- green and black wires = A
The wiring diagram is attached.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: groundFungus on Oct 21, 2019, 05:46 pm
Try slowing down the steps to 1 per second to see what it does. 
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 21, 2019, 06:09 pm
Last week, my motor worked well with a delay of 1s but now it doesnt react anymore ...I added in my loop a "print" to visualize each step until the 200th, I hear the sound of the motor but the rod doesnt turn at all.

Code: [Select]
#import Arduino Library
from bbio import *

#Define pins
stepPin = GPIO2_3
dirPin = GPIO2_4

#Set pins as output
def setup():
            pinMode(stepPin, OUTPUT)
            pinMode(dirPin, OUTPUT)

def loop():
            digitalWrite(dirPin, HIGH)
            for i in xrange(0,200,2):
                            digitalWrite(stepPin, HIGH)
                            delay(1000)
                            digitalWrite(stepPin, LOW)
                            delay(1000)
                            print("1")

            delay(1000)

run(setup, loop)
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Railroader on Oct 21, 2019, 11:40 pm
Your stepper was running in the beginning You tell. Your setting for current, 0.9 Amps looks okey. Do You use heatsinks on the driver? 12 Volt pwr supply is okey. Could it be that the driver board gets hot and Cuts down current in order to save itself?
Did You check the heat discipation from the driver board in the beginning. Could it be possible that the driver board IC is toast some way?

Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: ceduq on Oct 23, 2019, 04:19 pm
My battery was losing all its "juice" once connected, explaining that my stepper motor no longer responds to commands.
I could also test my project with an arduino. All problems seem solved using the Arduino.
The only difference I can see between the Arduino and the Beaglebone is the current delivered by the digital pins:
-> about 48 mA for the Arduino pin
-> about 6 mA (sometimes just 4mA) for the Beaglebone pin

If I rely on the driver datasheet, the current of 4mA is sufficient because it requires a high input current (Ihc) <100 uA (0.1 mA). In addition, the circuit has an internal resistance (pulldown) of about 100k ohm, which corresponds to a current of 33 uA (0.033 mA) to 3.3 V.

What do you think ?
I realized that the driver and the beaglebone were heating up quite quickly when powered on.
Title: Re: Controlling stepper motor with a DRV8825 driver
Post by: Railroader on Oct 23, 2019, 08:14 pm
Remember that a stepper consumes current all the time, even at stand still to keep. That makes the stepper maintainits position.
Arduino UNO outputs can deliver 20 mA, 40 mA shortly. Note that there is maximum for total current delivery so You can't put out 20 mA on all outputs at the same time.
Do You use heatsinks on the driver board? Even then it gets hot so I have installed a little 12 volt fan blowing air to the heatsinks in order to have power extended time.
Beaglebone was also heating up?

Attach a wiring diagram!