HELP with Stepper Code


hi, looking  arduino coding stepper motor operating system.  i'm complete newbie (old mech engineer) world of arduino , 'c' programming please bear me.

system-  nema17 /100:1 ratio stepper  connected leonardo board via easy driver shield. it's controlled via 2 pushbutton momentary switches (fwd & rev) , 2 limit switches on stepper motor/gear box assy (rev & stop/park).   rev switches connected in parallel, 1 automated operation, other manual intervention/override.

operation- push fwd(go) button , stepper motor runs cw until hits rev limit switch (or manual rev button pushed) , returns ccw stop/park limit switch , stops - total movement 20deg.  additionally, fwd/cw (go) movement speed variable via 10k pot (slowly rotate @ manually set / adjusted speed). while rev/ccw movement runs @ single high speed only. (returns start position , stops).  it has r/g/b led indicators each action/mode.

my difficulties - found during adruino research brian schmalz excellent easydriver examples, 1 of i've used , modified (butchered??).  sadly doesn't work i'm doing huge number of incorrect things within code???  i've read complex stepper codes talking of push button 'debounce' etc, struggle understand require?

code: [select]


//based on example5 code brian schmalz's easy driver example page
// http://www.schmalzhaus.com/easydriver/easydriverexamples.html
 

#include <accelstepper.h>


// define stepper , pins use
accelstepper stepper1(1, 9, 8);

// define our 3 input button pins
#define  go_pin     4
#define  stop_pin   3
#define  return_pin 2
#define  enable     6
#define  relay1     7
#define  led_blue   11
#define  led_green  12                      
#define  led_red    10  
#define  speed_pin  0  
#define  max_speed  5500
#define  min_speed  1

      

void setup() {
  // accelstepper value have set here max speeed, higher we'll ever go
  stepper1.setmaxspeed(10000.0);
  
  // set 3 button inputs, pullups
  pinmode(go_pin, input_pullup);
  pinmode(stop_pin, input_pullup);
  pinmode(return_pin, input_pullup);
  pinmode(relay1, output);        
  pinmode(led_blue, output);
  pinmode(led_green, output);
  pinmode(led_red, output);
  pinmode(enable,output);

}

void loop() {
  static float current_speed = 0.0;         // holds current motor speed in steps/second
  static int analog_read_counter = 3000;    // counts down 0 fire analog read
  static char sign = 0;                     // holds -1, 1 or 0 turn motor on/off , control direction
  static int analog_value = 0;              // holds raw analog value.

if (digitalread(go_pin) == 0) {    
    sign = -1;
    digitalwrite(relay1,low);
    digitalwrite(led_blue,low);
    digitalwrite(led_green,low);
    digitalwrite(led_red,high);

if(analog_read_counter > 0)
    analog_read_counter--;
    analog_read_counter = 3000;
    analog_value = analogread(speed_pin);
    stepper1.runspeed();
    current_speed = sign * ((analog_value/1023.0) * (max_speed - min_speed)) + min_speed;
    stepper1.setspeed(current_speed);
    stepper1.runspeed();

}

  else if (digitalread(return_pin) == 0) {
    sign = 1;
    digitalwrite(relay1,high);
    digitalwrite(led_blue,low);  
    digitalwrite(led_green,high);
    digitalwrite(led_red,low);
    stepper1.setspeed(max_speed);
    stepper1.runspeed();
  }
  
    
  else if (digitalread(stop_pin) == 0) {
    sign = 0;
    digitalwrite(relay1,low);
    digitalwrite(led_blue,high);
    digitalwrite(led_green,low);
    digitalwrite(led_red,low);
    digitalwrite(enable, high);  
 
  }
  }


any coding thing work highly appreciated.
wiring diagram attached.

hi,
welcome forum.
thanks reading how use forum message.

have written code @ once or in stages?
that is.
  • connected control box , written code read , output leds , got worrking.
  • started new code control easydriver , stepper, , got working.
  • added limits , got them working.
  • combined codes , got them working,


what not working?

tom..... :)


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > HELP with Stepper Code


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'