Controlling stepper without involving arduino (a lot)

I have a project where arduino does a lot of things (receiving signal from nRF24, reading scale, controlling servo etc.) and already each loop is taking long. Now I need to expand it to control a bipolar stepper motor which turns a trapez screw. The stepper has to turn 1,25 of revolution each time arduino detects a falling edge from a hall sensor (interrupt). The problem is that rotating it takes long and I don't want to occupy arduino. I came up with an idea to use NE555 in a-stable mode, which is powered from digital pin. It generates appropriate signal to DRV8825 for a time required to make 1,25 of rotation. Interrupt from hall sensor changes state to HiGH on the pin and second interrupt changes it to LOW when time has come.
Other solution is to use addtional arduino nano, which gets signal generated by interrupt in main arduino via digital pin and its only task is to rotate the motor by 1,25 rev.
Do you think it is ok or there is other easier solution?

I think posting the formatted code using code tags would interest helpers.

If you use the AccelStepper library you can just tell the stepper to go 250 steps (1.25 revolutions of a 200 step per rev motor) and it will go there with no further action except calling a run() function often (takes very little time). No need for extra hardware.

Stepper basics.

Here is example code showing how your stepper may work. I set it up and tested using my Uno and CNC shield with a DRV8825 driver in the X axis header. I'm using a pushbutton switch to simulate your interrupt. As you can see most of the code is for detecting a state change of the pushbutton switch.

#include <AccelStepper.h>

const byte enablePin = 8;  // for CNC shield
const byte  buttonPin = 9;

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 2, 5);

bool lastButtonState = HIGH;

void setup()
   pinMode(enablePin, OUTPUT);
   pinMode(buttonPin, INPUT_PULLUP);
   digitalWrite(enablePin, LOW);
   // Change these to suit your stepper if you want

void loop()
   static unsigned long timer = 0;
   unsigned long interval = 50;  // check switch 20 times per second
   if (millis() - timer >= interval)
      timer = millis();
      // read the pushbutton input pin:
      bool buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
         if (buttonState == LOW)
      // save the current state as the last state,
      //for next time through the loop
      lastButtonState = buttonState;

The stepper will advance 250 steps for each press of the button. All the code needs to do is call the run() function often as possible (each time through loop) to make the stepper move.

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