Stepper movement?

Some time back you helped with my project (saw dust collector). Trying to update the mechanical part to improve the vacuum seal in the rotating part. Quick description about the project. Using ACS712 sensor to detect which power tool is in use. That drives the stepper to move the disc to the correct opening. Intermittently, when turning a tool on, the disc jumps the wrong direction (about a quarter inch) then moves in correct direction to the opening. At that position it is not lined up completely. It's off by the amount of the backwards jump. Like it moved the correct number of steps from where the jump ended.
I have played with the Debounce time with no help. I have manually applied 5v to the ACS712 outputs in a variety of sequence and it appears to always work correctly, Never any jumps.
The new disc that's turning is lighter than the older disc. I don't know if this is a coding issue or hardware?
Code below
Greg

```cpp
//4/10/2025
               /*Auto Blast gate project:  for dust collection in wood shop.
  Arduino Nano
  ACS712 current sensor
  DRV8825 stepper driver with expansion card
  Nema 23 stepper/  STEPPERONLINE Low Current Nema 23 CNC Stepper Motor 1.8A 340oz.in/2.4Nm
  Halls effect homing sensor
  Homing routine is run at startup or reset to establish stepper position
  Each tool will be monitor by a current sensor and when that analog port exceeds a given threshold
  1. Rotate the stepper to a predetermined position to align ports for that tool.
  2. After the gate is align a digital pin will drive relay to turn on Vacuum system.
      Vacuum will stay on as long as sensor exceeds the threshold while tool is running. 
      When tool stops, vacuum will continue for 4 (adjustable) seconds to clear remaining dust.
  3. If the same tool is used next, the Stepper will remain in its current position.
      But the vacuum system should still operate the same.
  4. Rotating disk is 18" diameter with 8 position, 6 control by the ACS712 detecting Tool in use,
      2 control by buttons for non-Tool use.*/

#define MAX8BUTTONS
#include <MobaTools.h>
#include <Arduino.h>

const int  stepRev = 6400;    // steps per revolution 
const byte dirPin = 4;        // adjust stepper pins to your needs      
const byte stepPin = 5;       //   
const byte enablePin = 8;
const int  vacPin = 7;        // Drives relay to turn on Vacuum 
const byte halPin = 11;       // homing sensor  
MoToTimer  vacTimer;          // for delayed switch off
const long runOnTime = 3000;  // time for vac delay adjustable

// create stepper object
MoToStepper myStepper( stepRev, STEPDIR );

 
//......CREATE BUTTON OBJECTS ......  
// A0/Sweep/90°  A1/Hose/135°   A2/Down Draft/270°   A3/Miter/315°   A4/Drill/180°  A5/Sander/225°  A6/Bandsaw/45°  A7/Tablesaw(home)/0°
 
const byte buttonPins[] = {A0,A1,A2,A3,A4,A5,A6,A7};                  // All inputs for tools or positions with out tools
const long stepperPositions[] = {90, 135, 270, 315, 180, 225, 45, 0}; // in degrees, must be same number of elements as buttonPins
const byte buttonCnt = (8);                                           // read analogue inputs und return states for MoToButtons  
const int  threshold [] = {520,520,520,520,520,520,520,520};          //  A0, A1 are buttons, A2....A7 Adjustable for tools ACS712
int noCurrent = 520;                                                  //or specific value per sensor from array
byte difference = 10;

button_t readInputs()
  {
    button_t states = 0;
    for ( byte i = 0; i < 8; i++ ) {
      // read input and set according bit if value is greater than threshold
      analogRead(buttonPins[i]);
      //throw the first away, average the next two
      if ((analogRead(buttonPins[i]) + analogRead(buttonPins[i])) / 2 > threshold[i]) states |= (1 << i);
    }

    return states;
  }


MoToButtons myButtons( readInputs, 40, 500);        // number of buttons/positions  Debounce 20, 500

  // *******  Home Function *****

 void homing() {
  digitalWrite(vacPin, 1);
  myStepper.rotate(1);              // myStepper.doSteps( stepsPerRev );//Should work also, at least after one revolution the sensor should be hit.                                        
  while ( digitalRead(halPin) );    // wait until we pass the sensor
  myStepper.doSteps(15);            //Adjust number to fine tune zero. Changes to speed and ramp can effect this                                           
  while( myStepper.moving() );      // wait until movement is finished
  myStepper.setZero();
}         


void setup() {
  Serial.begin(9600);
  myStepper.attach(stepPin, dirPin);
  myStepper.setSpeed( 800 );                        // X10   500-800 
  myStepper.setRampLen(1500 );                      // 1500 steps to achive set speed -- 1250
  myStepper.attachEnable( enablePin, 100, LOW );    // if you want to switch off power when stepper reached position
  pinMode(vacPin, OUTPUT);
  homing();   // CALL HOMING FUNCTION
}

void loop() { 
 Monitor();                                   // Function in a TAB
    myButtons.processButtons();               // Check buttonstates
    static int32_t lastPos = 0;
    static int32_t newPos =0;
    static int32_t offset = 0;
    for ( byte pos = 0; pos < buttonCnt; pos ++ ) {
    
        // check all tools
        if ( myButtons.pressed(pos) ) {
            lastPos=myStepper.read();
            newPos = stepperPositions[pos]+offset;          //deciding shortest direction
            if ( (newPos-lastPos) >180 ) offset -= 360;     //CW            
            if ( (newPos-lastPos) <-180 ) offset += 360;    //CCW
            newPos = stepperPositions[pos]+offset;
            myStepper.write( newPos );   // Button was pressed, move stepper to the according position
            newPos=true;
        }
                   //**Vac control section**//

         // Tool is still switched on, and stepper has reached its position -> start vac
        if ( myButtons.state(pos) && myStepper.moving() == 0 ) {  
            digitalWrite(vacPin, 0);   // Turn Vac on
        }
         // Tool has been switched off, start timer to switch off vac
        if (myButtons.released(pos) ) {            
            vacTimer.setTime( runOnTime );        
        }
    }    
        //Turn vac off after timer expires 
    if (vacTimer.expired() ) {
        digitalWrite(vacPin, 1);   //TURN VAC OFF
    }

}




 
    



That suggests a glitch in the Arduino power supply due to line voltage variations, which can cause a processor reset, false readings on input pins, etc. Also, interference radiated from household wiring can be picked up by long, looping connections to input pins.

For suggestions on how to proceed, please post a wiring diagram of the setup, with all components, pins and connections clearly labeled. Hand drawn is preferred. A picture of the setup would help, too.

1 Like

Thanks for the reply, Attached some images below. Just to make sure we're on the same page. This is working with the original attachment. The part that attaches to the stepper was replace with a new design that seals better and weighs less than the the current one. The new one has the glitch. All the electronics are the same except the stepper that's the same model and brand as the original. I guess it's possible that the problem has always there, just didn't show up because of the weight difference?
While troubleshooting, I applied 5v to the ACS712 current sensors output, and it works every time. So instead of the tool triggering the sensor I have made it go high pass the threshold.


Unfortunately, the wiring image is difficult to interpret and the labels are mostly illegible. That is why forum members prefer a neat, hand drawn schematic.

The photo shows commendably neat wiring, but running long leads from I/O pins next to switched AC power leads is just asking for trouble.

Thanks again for the reply. Here is a updated version with a PCB I made to help clean up some of the clutter. Both it and the earlier one worked fine.
I can read the diagram but I made it. If I can find a better picture I will post it. I wouldn't attempt to draw it by hand.

Was finally able to get the drawing in a PDF. Once open you should be able to zoom in so it can be read. I use this drawing for my reference when working on the project. The Cat-5 cables are for external lights and buttons can be ignored,
Any question or thoughts

Thanks for your help
VAC 2 FRITZ (6)_bb.pdf (2.3 MB)

The homing function doesn't look like it protects against a wide angle range of digitalRead(halPin)==HIGH.

How big is "a quarter inch" in steps? How wide is the homing pulse activation range, as measured in steps?

Some folks move until the homing switch triggers, then back off into where it does not trigger, then slowly approach the edge of where the switch retriggers. That sort of procedure could be more robust against starting homing when the switch is already triggered by making sure it homes to the edge of the switch activation.

Thanks for your reply. The homing function is only used during reset to set the zero for the start. After that it just counts the steps to the trigger position. It then stores that position to take the shortest route to the next position (CW / CCW).

The quarter inch I referred to is about 15" away from the stepper shaft (it's a rotating disc). Not sure how to determine the number of steps. It's not always the same and doesn't do it every time.
Hope this helps, I struggle with trying to describe this

∂C/(2*π*r):  0.25/(2*3.14159*15)=0.0026525Rev

or using

we can convert that to steps:

0.002652585Rev * 6400steps/rev= 16.98 steps

Since most motors have 200steps/rev, with 6400 steps/rev, you're probably using a driver set for 32 microsteps, If that is true, then the 17 micro-step-steps would be about 17/32=1/2 step in physical stepper steps, which could account for the detents between the poles in the stepper.

Consider if the homing signal is also active for the same 1/4" or 0.002652585Rev*180°/π=0.15° of arc. Then, if you happened to start up on the far edge of the activation, then the homing initiating and completing there could explain an offset from other homing scenarios where it had to move to into the region of activation.

Consider this simulation, and the different homing origins you get if you have to move to the activation zone versus if you boot up/reset when the pot is already in the activation zone.

Have you discovered when you turn off your stepper while using other that full steps, when powered back up. the stepper must, always position itself at a FULL STEP position?

1 Like

Thanks for your reply. Interesting! I have not discovered that. Not sure how to check that out. Need to check my driver settings and maybe experiment with different setups?
Would it always position itself to the nearest full set or the last full step?

It's basic magnetism. The closest full step.

Thanks for your reply. Most of this is over my head :thinking: May need to read this a few more times. Is this what Paul was saying?

I might have left this out, after a reset and homing has occurred, It may move to several different positions perfectly before the jump happens. Does this still involve
homing?

It is hard to tell from here.

Are you saying that you turn it on, and it works fine for a while, and then (with the power on continuously) that it shifts about a 1/4" and stays shifted after that? Maybe there's a mechanical issue and it is sticking on something and skipping steps.

I think Paul is saying that powering off or dis-ENABLEing the stepper driver and re-enabling it could cause a shift to a different detent position. Is power on continuously between startup and the when the problem is observed? Or does the shift happen with some power interruption?

1 Like

Yes, the power is on during this. I wondered about sticking and can't detect any. If it's sticking or missing steps I wonder why it jumps backwards. Part of the trouble shooting I supplied 5v to the ACS current sensors output (Analog 0 tru 7) one at a time and it works perfect every time? If the tool on triggers the movement it might change positions a number of times before it happens. This should tell me something.

Again, thanks for your input.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.