ByteC

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: gShield controlling stepper with out G-Code/PC? #11117
    ByteC
    Member

    oops, please set

    digitalWrite(disablePin, HIGH);

    to

    digitalWrite(disablePin, LOW);

    to enable the stepper motors.

    And set the 3rd line to
    // initial example parts captured from mechapro.de

    in reply to: gShield controlling stepper with out G-Code/PC? #11116
    ByteC
    Member

    yes, tried it today.
    I’m using Version 5B, with an Arduino Due, Accelstepper lib

    #include <AccelStepper.h>
    #include <stdint.h>
    #initial example captured from from mechapro.de
    
    const uint8_t disablePin = 8;
    
    // pin assignment X-Axis
    //const uint8_t stepPin = 2;
    //const uint8_t dirPin = 5;
    
    // pin assignment Y-Axis
    //const uint8_t stepPin = 3;
    //const uint8_t dirPin = 6;
    
    // pin assignment Z-Axis
    const uint8_t stepPin = 4;
    const uint8_t dirPin = 7;
    
    // actuate stepper motor
    void forwardstep() {  
      digitalWrite(dirPin, HIGH);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1);
      digitalWrite(stepPin, HIGH);
    }
    
    void backwardstep() {  
      digitalWrite(dirPin, LOW);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1);
      digitalWrite(stepPin, HIGH);
    }
    
    // setting up the AccelStepper library with custom actuator functions
    AccelStepper stepper(forwardstep, backwardstep); // use functions to step
    
    void setup()
    {
      // configuration of gpio interface
      pinMode(stepPin, OUTPUT);
      //pinMode(errorPin, INPUT_PULLUP);
      pinMode(dirPin, OUTPUT); 
      pinMode(disablePin, OUTPUT); 
    //  pinMode(sleepPin, OUTPUT); 
      
      digitalWrite(disablePin, HIGH);
      
      // ramp parameters
      stepper.setMaxSpeed(2000);
      stepper.setAcceleration(20000);
    }
    
    int dir = 1;
    void loop()
    {
        if (stepper.distanceToGo() == 0)
        {
            // Random change to speed, position and acceleration
            // Make sure we dont get 0 speed or accelerations
            delay(10);
            stepper.move(dir * 300);
            dir = dir * -1;
        }
        stepper.run();
    }
Viewing 2 posts - 1 through 2 (of 2 total)