Stepper Motor woes
 
Notifications
Clear all

Stepper Motor woes

19 Posts
4 Users
30 Likes
1,800 Views
Christine86
(@christine86)
Member
Joined: 4 years ago
Posts: 45
Topic starter  

Hi, I'm building a stepper motor driven 'Parts Carousel' to hold the containers I've designed

Containers

 I've designed a carousel, which uses a 3.95" touch display.

Front View
Front Display

 This relies on a stepper motor in the centre, which rotates a platter

Top View
Bearings

 After all of this, I had assumed driving the stepper would be trivial, but I've become completely lost. I followed bill's instructions, using an A4988 driver & a 17HS15-1504S-X1 39mm Stepper Motor. It doesn't seem to matter what I do, ALL I get is a LOT of rattling on my bench, & perhaps some jittery movement.

 

This is the sketch I've used to test the stepper, (slightly changed from Bill's, to allow the setting of reset sleep etc), but using the same 'void' section.

/*
Stepper Motor Demonstration 4
Stepper-Demo4.ino
Demonstrates NEMA 17 Bipolar Stepper with A4988 Driver

DroneBot Workshop 2018
https://dronebotworkshop.com
*/

// Define Constants

// Connections to A4988

const int stepPin = 4; // Step
const int dirPin = 5; // Direction
const int MS1 = 9;
const int MS2 = 10;
const int MS3 = 11;
const int ENABLE = 6;
const int RESET = 7;
const int SLEEP = 8;

// Motor steps per rotation
const int STEPS_PER_REV = 200;

void setup() {

// Setup the pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(MS1,OUTPUT); //MS1 to MS3 used to change stepfrom 1 to 1/16
pinMode(MS2,OUTPUT);
pinMode(MS3,OUTPUT);
pinMode(ENABLE,OUTPUT); //On - Off for A4988
pinMode(RESET,OUTPUT);
pinMode(SLEEP,OUTPUT); //Put A4988 to Sleep

digitalWrite(ENABLE, LOW);
digitalWrite(SLEEP, HIGH);
digitalWrite(RESET, HIGH);
digitalWrite(MS1, LOW);
digitalWrite(MS2, LOW);
digitalWrite(MS2, LOW);

}

void loop() {

digitalWrite(dirPin, HIGH);

// Spin motor one rotation slowly
for (int x = 0; x < STEPS_PER_REV; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}

// Pause for one second
delay(1000);

// Set motor direction counterclockwise
digitalWrite(dirPin, LOW);

// Spin motor two rotations quickly
for (int x = 0; x < (STEPS_PER_REV * 2); x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}

// Pause for one second
delay(1000);

}

I had bought 3 stepper motors, unsure which would be suitable for the job. ALL 3 steppers exhibit EXACTLY the same symptoms, barely turning, whilst jittering up and down on my desk(The stepper is NOT in the carousel, it's just sitting on a breadboard. I'm supplying the stepper 12V @1.5Amps. But it seems to not want more than 200mA.

Power Supply

 This is the circuit board I've designed, to supply the 12V & 5V the stepper & Arduino will need, though at this stage, I've not used this either.

 

Has someone any idea what is wrong, or what I've done wrong, it's depressing that everything else is ready to go, but I'm left with a bouncing jittery stepper motor. It's probably (I hope) something easily remedied, but I'm at a loss!

Thanks

Christine


   
Inst-Tech and Biny reacted
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@christine86

Nice job on the design and 3D printing !

Since you'll eventually be turning a (possibly) heavy load of parts, I would suggest that you switch over to use the AccelStepper library instead of manually coding for the stepper.

The library will provide all of the movement and control that you need but will also offer acceleration and deceleration for the rotation. That will become very important to avoid having he motors stall out if the parts weigh too much.

A frequent cause of the chattering you describe is inadequate voltage supplied (make sure the A4988 trimmer is adjusted correctly) or bad timing on the stepper pulses (usually pulsing too fast so the the stepper can't keep up).

Try switching to AccelStepper and re-test. Let us know how it goes.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
 Biny
(@binaryrhyme)
Member
Joined: 2 years ago
Posts: 269
 

Nice lookin' project! Deferring to @Will on this one - just wanted to pass on the high five!

I edit my posts to fix typos, correct grammar, or improve clarity. On-screen keyboards are evil.


   
ReplyQuote
Christine86
(@christine86)
Member
Joined: 4 years ago
Posts: 45
Topic starter  

@will & @binaryrhyme Thank you both. Seems my Fusion 360 prowess is better than my stepper motor knowledge.

The article Bill wrote, said that just for testing, I need only select 'Direction' & then pulse on 'Step'.

I'll try using the 'AccelStepper library' (I hope it comes with examples?), & report back.

Thanks,

Christine


   
Inst-Tech and Biny reacted
ReplyQuote
Christine86
(@christine86)
Member
Joined: 4 years ago
Posts: 45
Topic starter  

@will am I missing something? I installed accelstepper, & then tried 'ConstantSpeed.pde' since it seemed the easiest to try first.

The minimal comments said i should use pins 2, 3, 4 & 5 (within the constructor) on the arduino. This is surely wrong, since a Mega doesn't have the ability to provide power for a stepper. Is it that I should be using an 'ULN2004A'? I have ordered some, but the boards i designed & had made up through JLCPCB for my carousel are using the A4988.

Do I have to abandon these boards, I have just learned the pinouts for these. I'm using
@dronebot-workshop approach to setting the current through the A4988 to a stepper lead, but can't get any current there at all.

I know i must be doing something wrong, now I'm worried I've either cooked the A4988, &/or the stepper. i guess i'm going to have to buy more A4988s & steppers, & then try again.

In confusion,

Christine


   
Biny reacted
ReplyQuote
 Biny
(@binaryrhyme)
Member
Joined: 2 years ago
Posts: 269
 

@christine86 Hmm. I don't have the parts to replicate your set up, but I'll ask some obvious questions - if too trivial, I beg your pardon.

1) Are you testing the motor in isolation, or in the mechanical assembly? My thought here is the problem may be on the mechanical side vs the code (you mentioned rattling). edit: NVM, its on a breadboard.

2) Do you have access to a scope to verify the PWM sent to the driver? Always good to walk it back and eliminate complicating factors, know what is solid. Let's say your crystal is faulty and the clock speed is off - not saying that is the case. (But you could test the accuracy of the delay() with a simple blink sketch as well.)

3) Any interrupts active that are taking too much time, or other possible code blocking possibilities?

4) Did Bill's sketch run without the reset modifications?

5) ... and just because I'm a stickler for style, indent inside your functions, loops and other blocks, lol. 😉

In my career, almost always when a bug is really stubborn and I'm ready to blame the hardware, I find the bug, and it was me, lol.

Keep us posted.

I edit my posts to fix typos, correct grammar, or improve clarity. On-screen keyboards are evil.


   
Christine86 reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@christine86 

The library is  generic class, so it can has constructs for different types of setup. In your case, you're using a driver so you'll need to choose the appropriate constructors. The documentation shows:

 

Public Types

enum  MotorInterfaceType {
  FUNCTION = 0, DRIVER = 1, FULL2WIRE = 2, FULL3WIRE = 3,
  FULL4WIRE = 4, HALF3WIRE = 6, HALF4WIRE = 8
}

 

So you'll want to choose the constructor using DRIVER=1 for example

AccelStepper mySteppe( DRIVER,stepPin,dirPin);
 
Which tells the library to construct  stepper instance which will be using a driver and communication with it via the step and direction pins you've specified.

 

 

Anything seems possible when you don't know what you're talking about.


   
Christine86 and Biny reacted
ReplyQuote
Christine86
(@christine86)
Member
Joined: 4 years ago
Posts: 45
Topic starter  

Hi @Will and @binaryrhyme

Hi guys,

Replying to BR first;

IMG 0993

!/ My designed circuit is not in use, just using my breadboard.
2/ My cro detects PWM fine, something weird going on with Current through 1A though (barely registering current, but power supply reads over an Amp).
3/ No interrupts, except those within AccelStepper libraries I presume
4/ No idea what 'reset mod' is? I just ran Bill's .ino file(in first post)
5/ it was bill's file. It looks as though my copy & paste stripped the 'formatting' from it. Don't worry, at Uni I was renowned for having miles of comments & perfectly ordered indents 🙂

 

Now to Will;

This is the .pde i'm now running.

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{
stepper.setMaxSpeed(1000);
stepper.setSpeed(50);
}

void loop()
{
stepper.runSpeed();
}

There is SOME good news, in desperation, I just shoved the 'STEP' cable into pin 2 of my Mega, & for the very first time, I got some movement. The jittering is still present, but with VERY careful rotation of the current adjust screw, I managed to get some movement with much reduced bouncing.

Is this normal Will? Seems if I actually used this in my carousel, it wouldn't be stable (the pot only travels in about 315 deg). The slightest movement from the sweet spot results in non-movement or weird movement.

The Stepper I'm using is four lead(Black/Green & Blue/Red),but there doesn't seem to be the constructor you're talking about??

It was only desperation that lead me to stick the wire from 'STEP' into pin 2 of the Mega. I'm using 12V for the stepper. It can go to 24V according to it's datasheet. Would raising the voltage to 16 or 20v make it more stable? I just can't see this working in my carousel, without me having to constantly adjust the current to the very small range i'm getting now.

Do you have a program in mind that uses the constructor you mention, perhaps that might be more stable? I've got all the rest of my coding done, with graphics & parts lists etc. but now I'm STUCK!!

Thnx

christine


   
ReplyQuote
 Biny
(@binaryrhyme)
Member
Joined: 2 years ago
Posts: 269
 

@christine86 Lol. OK, sorry 'bout that. Just wanted to do a pulse check on potentially simple stuff. It sounds pretty wonky.

I edit my posts to fix typos, correct grammar, or improve clarity. On-screen keyboards are evil.


   
Christine86 reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

Anything seems possible when you don't know what you're talking about.


   
Christine86 reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 
Posted by: @christine86

There is SOME good news, in desperation, I just shoved the 'STEP' cable into pin 2 of my Mega, & for the very first time, I got some movement. The jittering is still present, but with VERY careful rotation of the current adjust screw, I managed to get some movement with much reduced bouncing.

Yes, adjusting the A4988 to provide enough current to drive the stepper while still preventing too much current which could damage the stepper and/or the driver.

Is this normal Will? Seems if I actually used this in my carousel, it wouldn't be stable (the pot only travels in about 315 deg). The slightest movement from the sweet spot results in non-movement or weird movement.

Um ... movement of what from the "sweet spot" ?

The Stepper I'm using is four lead(Black/Green & Blue/Red),but there doesn't seem to be the constructor you're talking about??

No, AccelStepper is very old (still supplies examples in .pbe format) and I haven't looked at the source for a long time. Seems like the later amendments for driver usage never made it into the examples. I'm sorry about that, I should have traced it back since I understand that you're relatively new to stepper motors.

It was only desperation that lead me to stick the wire from 'STEP' into pin 2 of the Mega. I'm using 12V for the stepper. It can go to 24V according to it's datasheet. Would raising the voltage to 16 or 20v make it more stable? I just can't see this working in my carousel, without me having to constantly adjust the current to the very small range i'm getting now.

There should be NO - zero - none - connection from the Arduino directly to the stepper. All wiring should go from the stepper to the driver and from the driver to the stepper. Remember that the driver and the Arduino must share a common GND, so be sure to provide that.

Unless you specifically intent to vary multistepping as you run, you're better to tie all of them to GND. At the same time you should probably tie the SLP (sleep) pin to the RESET pin on the A4988 to prevent it from sleeping.

This configuration does not require the use of PWM, the pulses are generated by the AccelStepper library with the Arduino. Tis is what allows Acceleration and deceleration.

Your "other" code should also address several other considerations:

1) you'll need to provide some way of "homing" the turntable when you first power up

2) you'll need to determine the step counts of the various "front face" of your trays

3) don't know how you're determining where to rotate, 1 button/stack may be easiest

4) you may need to provide an interlock to prevent selecting a new target while the turntable is turning

5) you may need to provide the ability to run clockwise or widdershins in order to transition from one parts bin to the next using the least amount of rotation (and time).

 

If any of this is still unclear, please let me know. Steppers can be intimidating to start with but they're really not difficult to use.

 

Anything seems possible when you don't know what you're talking about.


   
Christine86 reacted
ReplyQuote
Christine86
(@christine86)
Member
Joined: 4 years ago
Posts: 45
Topic starter  

@will Thanks!

Yes, i have tested the pairs, & strangely, they are correct. 🙂

This makes more sense, I've used 2 for STEP & 3 for DIR. The stepper is happily doing it's thing. There is still though, a truly small range of the current POT to make the stepper turn, & not rattle horribly.

Should I be using a different driver, I only used the A4988, after i read the article by Bill. I have already ordered a ULN2003 board;

Driver

 do you think this would work better? Also, do you have any ideas regarding bumping up the voltage to say 20V or so might give better performance? I had the previous .pde running after your first response, & in the only two or so hours, had already drifted to turning, but making a slight rattling sound.
I had hoped this would be very easy, but it has become the most troublesome in this design.

As an aside, is there a trusted site for getting good steppers, it seems to be pot-luck as to what you get?

Thnx, to both you & @binaryrhyme, I at least have moved past the hair pulling out stage 😱 (one stage b4 drowning myself in scotch) I was in b4 your help!

Christine


   
Biny reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 
Posted by: @christine86

Yes, i have tested the pairs, & strangely, they are correct. 🙂

Good, that's another item ticked off the list.

This makes more sense, I've used 2 for STEP & 3 for DIR. The stepper is happily doing it's thing. There is still though, a truly small range of the current POT to make the stepper turn, & not rattle horribly.

Perhaps it's not clear that you only have to adjust the pot on the A4988 one time. After it's adjusted properly, you're finished with it (unless you change stepper motors or have a breakdown or something).

Should I be using a different driver, I only used the A4988, after i read the article by Bill. I have already ordered a ULN2003 board;

o, the A4988 is infinitely superior to the ULN, it handles more power and it requires only 2 pins (step and direction) whereas the ULN has to have the Arduino generate the pulses for each the 4 wires.

 I had the previous .pde running after your first response, & in the only two or so hours, had already drifted to turning, but making a slight rattling sound.
I had hoped this would be very easy, but it has become the most troublesome in this design.

My first attempts to use steppers were disasters, so I know how you feel. Hopefully the latest sample code will work better for you. You can adjust the speed by resetting the value in the setup routine or you can change it inside the loop.

As an aside, is there a trusted site for getting good steppers, it seems to be pot-luck as to what you get?

I just buy inexpensive NEMA17s from Amazon. But I mostly use mine for making plotters, so they're never under a heavy load.

Thnx, to both you & @binaryrhyme, I at least have moved past the hair pulling out stage 😱 (one stage b4 drowning myself in scotch) I was in b4 your help!

Well now, by all means don't let us stop you from at least bathing in scotch - drowning seems so permanent 🙂

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Christine86
(@christine86)
Member
Joined: 4 years ago
Posts: 45
Topic starter  

@will Sorry, your reply must have come in whilst i was writing my reply.

As to your points.

1/ Yes, the platter will have a magnet inserted in it(as the homing), & I have already designed the enclosure to have a hall-effect sensor. ATM I am using a interrupt that stops the platter when it reaches 'home'.

2/ Yes, I've done this too. My hope is to eventually have a smd LED which will light when the platter turns to the angle which brings that part container closest to me.

3/ There is a screen beyond the splashscreen

Second Screen

where you can select to just bring one color(each of the four sides is in colors, that give a suggestion as to it's contents), or you can drill down to an individual drawer (like M3 x 10 Bolt)

4/ yes there is a lock that prevents multiple moves b4 the previous command finishes running. There is a large 'Emergency STOP' Button I've designed on screen, that the user can touch to bring the platter to complete rest.

5/ YES, done this too! Ah, the math in this is truly fun, especially for the power button at top left of the screen(as shown in the image above), & each of the four 'sides' that correspond to the color of the drawer cases. . I've tried to think of every idiot move i might do, & tried to code for it's demise. I'm certain I haven't thought of every stupid thing i might do. It took a lot of coding to get this part done. I have a function that determines which direction to turn, to arrive at your destination with the least amount of time.

When i talk about increasing the voltage, I am only talking about VMOT (the stepper voltage). Max VMOT is said to be 24V, so I was thinking of bumping this up to 16 or 20V. Reticent to do this, unless you think this OK?

The sweet spot i refereed to was the current setting pot on the A4988 board. I'm surprised there's such a coarse adjustment, & that it drifts(possibly due to heating) after only a couple of hours.

Thnx for you help Will, I hope this makes sense to you?

Christine


   
Inst-Tech reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@christine86 

Excellent, sounds like you've really done your homework and are well prepared for everything.

I would leave it at the lower voltage for now, less power, less heat. You can always crank up the juice later if your turntable bogs down due to the weight. If that happens, you can always mount an axial bearing under the turntable to take most of the load and provide a relatively frictionless bed on which to roll the turntable.

The A4988 pot adjusting the current seems pretty small and crude for its job. Once a stepper motor starts running, it always seems that it winds up at a temperature of <physical pain>-2 degrees Celsius. If the driver feels hot to your touch, you should install the aluminum heat sink that came with it. I usually leave the control boards exposed to open air. If enclosed, I leave slots in the case and use a small 25mm fan to run inside the case to keep moving the hot inside air out of the box.

There should be very little "drift" in the A4988? What kind of error(s) are you seeing ?

I don't know how you're deciding where to stop, whether it's angles or step counts and from your work so far, I'm sure that you're far ahead of me here. I'd suggest that you use step counts to note where you are. The reason is that the stopping points will always be in (integer) steps around the circle and the difference between any two positions will always be an (integer) constant number of steps. So, by dealing always with steps, you avoid the potential evil of creeping error from using floating point values.

Anything seems possible when you don't know what you're talking about.


   
Duce robot, Christine86, Inst-Tech and 1 people reacted
ReplyQuote
Page 1 / 2