Thanks Thanks:  0
Needs Pictures Needs Pictures:  0
Picture(s) thanks Picture(s) thanks:  0
Page 2 of 11 FirstFirst 1234567 ... LastLast
Results 16 to 30 of 163
  1. #16
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    Have you installed the AccelStepper library as per Example 3 on Brian Schmalz's page?

  2. # ADS
    Google Adsense Advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many





     
  3. #17
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default AccelStepper installed

    Gentlemen,

    I have all the necessary libraries installed, and have been running Brian Schmaltz's example 6 sketch without error, apart from the delays.

    Am currently trying to printout the amended sketch, and wouldn't you know it, the printer is spewing out blank pages. Can't take a trick.

    Ken

  4. #18
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    okay, sorry for the double post and the delay. very slow internuts at the moment.

    So it looks like there are two ways to install. The easiest (i accidentally downloaded the beta arduino, which is version 1.5.8) is to download the zip file from http://www.airspayce.com/mikem/ardui...epper-1.45.zip

    Once you've downloaded the file, go into your arduino ide and go to the sketch menu. Select Import Library and then Add Library...

    Next browse to where you downloaded the AccellStepper-1.45.zip file and select that. The Arduino software will import that library and will use it from the downloaded location.

    Alternatively, if that option isn't available to you, right click on the AccellStepper-1.45.zip file and select Extract All...

    Next browse to the Arduino Library folder (normally My Documents\Arduino\libraries ) and extract into there. If you restart your arduino IDE the library should appear in your Import library list (don't bother clicking on it - it is already in your sketch).

    I apparantly need to get the Adafruit motorshield library, so I'll go get that and then do a test compile on the code.

    urgghh.. looks like the Adafruit motorshield library has changed a bit since those examples were written. give me a sec and I'll try and work it out.

  5. #19
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    okay, and apologies for the triple post.

    I installed the adafruit library following the instructions here: https://learn.adafruit.com/adafruit-...ibrary-install

    Once I'd done that I modified the code so it is similar to the adafruit examples, while still keeping the original author's intent and our modifications. Make sure you have both the AccelStepper library and the Adafruit library installed and then give this a try. It compiles for me, but I haven't got any hardware to test it with.
    Code:
    // Example6 code for Brian Schmalz's Easy Driver Example page
    // http://www.schmalzhaus.com/EasyDriver/EasyDriverExamples.html
    
    #include <AccelStepper.h>
    #include <Wire.h>
    #include <AFMotor.h> 
    
    
    // Define the stepper and the pins it will use
    AF_Stepper motor1(200,1);      // this sets up your stepper motor as 200 stps per revolution and on port 1
    
    
    
    // you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
    void forwardstep() { 
      motor1.onestep(FORWARD, SINGLE);
    }
    void backwardstep() { 
      motor1.onestep(BACKWARD, SINGLE);
    }
    
    AccelStepper stepper1(forwardstep, backwardstep); // use functions to step
    
    // Define our three input button pins
    #define  LEFT_PIN  2
    #define  STOP_PIN  3
    #define  RIGHT_PIN 4
    // and define our two Limit inputs
    #define LEFT_LIM_PIN 5
    #define RIGHT_LIM_PIN 6
    
    // Define our analog pot input pin
    #define  SPEED_PIN A0
    
    // Define our maximum and minimum speed in steps per second (scale pot to these)
    #define  MAX_SPEED 500
    #define  MIN_SPEED 0.1
    
    void setup() {
      // The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go
      stepper1.setMaxSpeed(500.0);
     
      // Set up the three button inputs & limit inputs with pullups
      pinMode(LEFT_PIN, INPUT_PULLUP);
      pinMode(STOP_PIN, INPUT_PULLUP);
      pinMode(RIGHT_PIN, INPUT_PULLUP);
      pinMode(LEFT_LIM_PIN, INPUT_PULLUP);
      pinMode(RIGHT_LIM_PIN, INPUT_PULLUP);
    }
    
    void loop() {
      static float current_speed = 0.0;         // Holds current motor speed in steps/second
      static int analog_read_counter = 1000;    // Counts down to 0 to fire analog read
      static char sign = 0;                     // Holds -1, 1 or 0 to turn the motor on/off and control direction
      static int analog_value = 0;              // Holds raw analog value.
     
      // If a switch is pushed down (low), set the sign value appropriately
      if (digitalRead(LEFT_PIN) == 0) {
        sign = 1;
      }
      if (digitalRead(RIGHT_PIN) == 0) {   
        sign = -1;
      }
      if (digitalRead(STOP_PIN) == 0) {
        sign = 0;
      }
      // code from Rusty
      if (digitalRead(LEFT_LIM_PIN)==0) {  // if the left limit pin is hit
        if (digitalRead(RIGHT_PIN)==0) {   // allow the right button to move us off the limit
            sign=-1;
        }
        else {
            sign=0;                           // but otherwise we should stop the motor
            stepper1.setSpeed(sign);        // by setting the motor's speed to 0
        }
      }
      if (digitalRead(RIGHT_LIM_PIN)==0) { // if the right limit pin is hit
        if (digitalRead(LEFT_PIN)==0) {    // allow the left button to  move us off the limit
            sign=1;
        }
        else {
            sign=0;                            // but otherwise we should stop the motor
            stepper1.setSpeed(sign);        // by setting the motor's speed to 0
        }
      }
    
      // Give the stepper a chance to step if it needs to
      stepper1.runSpeed();
      //  And scale the pot's value from min to max speeds
      current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
      // Update the stepper to run at this new speed
      stepper1.setSpeed(current_speed);
      // This will run the stepper at a constant speed
      stepper1.runSpeed();
    
      // We only want to read the pot every so often (because it takes a long time we don't
      // want to do it every time through the main loop). 
      if (analog_read_counter > 0) {
        analog_read_counter--;
      }
      else {
        analog_read_counter = 3000;  //  <-- change this to a lower number (i.e 500 or 1000) to increase pot response
        // Now read the pot (from 0 to 1023)
        analog_value = analogRead(SPEED_PIN);
      }
    
      
    }

  6. #20
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    Quote Originally Posted by neksmerj View Post
    Gentlemen,

    I have all the necessary libraries installed, and have been running Brian Schmaltz's example 6 sketch without error, apart from the delays.

    Am currently trying to printout the amended sketch, and wouldn't you know it, the printer is spewing out blank pages. Can't take a trick.

    Ken
    whups.. missed this. sorry, ignore me.

  7. #21
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    Ken are you able to post back the code that is throwing the error?
    if you just copy it, and then past it into a post between code blocks (use the button that looks like a # ) it'll be easier to read and figure out what is going wrong.

    *edit* sorry - i mean please post the entire sketch..

    *edit2* annnnd as it turns out I'd downloaded the old Adafruit motorshield library, not the one for the current V2 motor shield. so, definately ignore my code.

  8. #22
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Still a problem compiling

    foobillious,

    That's strange, you say your sketch compiles ok, and yet mine does not.

    This is the error report

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.
    Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"


    function definition does not declare parameters


    sketch_feb05a:1: error: function definition does not declare parameters
    sketch_feb05a:11: error: 'AF_Stepper' does not name a type
    sketch_feb05a.ino: In function 'void forwardstep()':
    sketch_feb05a:17: error: 'motor1' was not declared in this scope
    sketch_feb05a:17: error: 'FORWARD' was not declared in this scope
    sketch_feb05a:17: error: 'SINGLE' was not declared in this scope
    sketch_feb05a.ino: In function 'void backwardstep()':
    sketch_feb05a:20: error: 'motor1' was not declared in this scope
    sketch_feb05a:20: error: 'BACKWARD' was not declared in this scope
    sketch_feb05a:20: error: 'SINGLE' was not declared in this scope
    sketch_feb05a.ino: At global scope:
    sketch_feb05a:23: error: 'AccelStepper' does not name a type
    sketch_feb05a.ino: In function 'void setup()':
    sketch_feb05a:42: error: 'stepper1' was not declared in this scope
    sketch_feb05a.ino: In function 'void loop()':
    sketch_feb05a:75: error: 'stepper1' was not declared in this scope
    sketch_feb05a:84: error: 'stepper1' was not declared in this scope
    sketch_feb05a:89: error: 'stepper1' was not declared in this scope

    Ken

  9. #23
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    Hi Ken,

    yes, i had the wrong library downloaded. It was for an older version of the Adafruit motorshield. I'll try again with the new one. Just have to clear some work first. Should be about 5-10 more minutes and then I'll try again.

  10. #24
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    Hi Ken,
    Okay, I've installed the correct Adafruit Motorshield v2 library and I've done a test compile on rusty's code. It seems to compile fine for me. Would you be able to try it again? Code below for ease of use:
    Code:
    // Example6 code for Brian Schmalz's Easy Driver Example page
    // http://www.schmalzhaus.com/EasyDriver/EasyDriverExamples.html
    
    #include <AccelStepper.h>
    #include <Wire.h>
    #include <Adafruit_MotorShield.h>
    
    // Define the stepper and the pins it will use
    Adafruit_MotorShield AFMS = Adafruit_MotorShield();
    Adafruit_StepperMotor *motor1 = AFMS.getStepper(200, 1);
    
    
    // you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
    void forwardstep() { 
      motor1->onestep(FORWARD, SINGLE);
    }
    void backwardstep() { 
      motor1->onestep(BACKWARD, SINGLE);
    }
    
    AccelStepper stepper1(forwardstep, backwardstep); // use functions to step
    
    // Define our three input button pins
    #define  LEFT_PIN  2
    #define  STOP_PIN  3
    #define  RIGHT_PIN 4
    // and define our two Limit inputs
    #define LEFT_LIM_PIN 5
    #define RIGHT_LIM_PIN 6
    
    // Define our analog pot input pin
    #define  SPEED_PIN A0
    
    // Define our maximum and minimum speed in steps per second (scale pot to these)
    #define  MAX_SPEED 500
    #define  MIN_SPEED 0.1
    
    void setup() {
      AFMS.begin();
     
      // The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go
      stepper1.setMaxSpeed(500.0);
     
      // Set up the three button inputs & limit inputs with pullups
      pinMode(LEFT_PIN, INPUT_PULLUP);
      pinMode(STOP_PIN, INPUT_PULLUP);
      pinMode(RIGHT_PIN, INPUT_PULLUP);
      pinMode(LEFT_LIM_PIN, INPUT_PULLUP);
      pinMode(RIGHT_LIM_PIN, INPUT_PULLUP);
    }
    
    void loop() {
      static float current_speed = 0.0;         // Holds current motor speed in steps/second
      static int analog_read_counter = 1000;    // Counts down to 0 to fire analog read
      static char sign = 0;                     // Holds -1, 1 or 0 to turn the motor on/off and control direction
      static int analog_value = 0;              // Holds raw analog value.
     
      // If a switch is pushed down (low), set the sign value appropriately
      if (digitalRead(LEFT_PIN) == 0) {
        sign = 1;
      }
      if (digitalRead(RIGHT_PIN) == 0) {   
        sign = -1;
      }
      if (digitalRead(STOP_PIN) == 0) {
        sign = 0;
      }
      // code from Rusty
      if (digitalRead(LEFT_LIM_PIN)==0) {  // if the left limit pin is hit
        if (digitalRead(RIGHT_PIN)==0) {   // allow the right button to move us off the limit
            sign=-1;
        }
        else {
            sign=0;                           // but otherwise we should stop the motor
            stepper1.setSpeed(sign);        // by setting the motor's speed to 0
        }
      }
      if (digitalRead(RIGHT_LIM_PIN)==0) { // if the right limit pin is hit
        if (digitalRead(LEFT_PIN)==0) {    // allow the left button to  move us off the limit
            sign=1;
        }
        else {
            sign=0;                            // but otherwise we should stop the motor
            stepper1.setSpeed(sign);        // by setting the motor's speed to 0
        }
      }
    
      // Give the stepper a chance to step if it needs to
      stepper1.runSpeed();
      //  And scale the pot's value from min to max speeds
      current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
      // Update the stepper to run at this new speed
      stepper1.setSpeed(current_speed);
      // This will run the stepper at a constant speed
      stepper1.runSpeed();
    
      // We only want to read the pot every so often (because it takes a long time we don't
      // want to do it every time through the main loop). 
      if (analog_read_counter > 0) {
        analog_read_counter--;
      }
      else {
        analog_read_counter = 3000;  //  <-- change this to a lower number (i.e 500 or 1000) to increase pot response
        // Now read the pot (from 0 to 1023)
        analog_value = analogRead(SPEED_PIN);
      }
    
      
    }

  11. #25
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Have made the same blue

    Hi foob,

    I too made the same mistake initially, as did Brian Schmalz, some of the Adafruit sketches are old and only apply to the V1 board.

    I appreciate the help you are giving me. For me trying to decipher code is trying to untangle Egyptian hieroglyphics.

    Ken

  12. #26
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    How did you get on re doing the cut, paste and compile? any change or is it still throwing errors at you?

  13. #27
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Getting closer

    foob,

    I finally got your sketch to compile, think I missed one squiggly bracket right at the bottom of the sketch.

    There is one error message though,

    avrdude:st500_getsync():not in sync:reap=0x00

    Despite that, the motor turns CW, ACW and stops, however, the limit switches have no effect.

    Using a 5V digital probe, I don't get a high on pins 5 & 6, (limit switch pins) but do get a low on those pins when I depress the limit switches.

    I get a high on pins 2,3 &4 which get pulled low with the appropriate PB

    Any thoughts?

    edit: changed the pin numbers to 5 & 6, inadvertently called them pins 4 & 5

    Ken

  14. #28
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    Quote Originally Posted by neksmerj View Post
    Using a 5V digital probe, I don't get a high on pins 5 & 6, (limit switch pins) but do get a low on those pins when I depress the limit switches.
    Do you have these two initialisation lines in your code?

    Code:
    pinMode(LEFT_LIM_PIN, INPUT_PULLUP);
    pinMode(RIGHT_LIM_PIN, INPUT_PULLUP);

  15. #29
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Limit switch code

    Hi Rusty,

    Yes, I'm using your code, cut and pasted from the screen.

    What ever you have written, I'm using.

    Just wondering whether pins 5 & 6 are reserved for something else, however, I think not.

    I wonder whether adding external resistors, say 1K, would help?

    Ken

  16. #30
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    I'm not familiar with the Arduino architecture, but a quick read of the docs suggests there's nothing special about 5 & 6. You could change the code to use pins 7 & 8 just to check.

    You shouldn't need to add an external pullup resistor, the two INPUT_PULLUP commands I mentioned above connect the pins to the supply rail via a 20k resistor, which then should be registering as high.

Page 2 of 11 FirstFirst 1234567 ... LastLast

Similar Threads

  1. Limit/home switches
    By warrick in forum CNC Machines
    Replies: 2
    Last Post: 7th July 2012, 08:11 PM
  2. Limit switches
    By Bob Willson in forum CNC Machines
    Replies: 0
    Last Post: 24th August 2011, 12:31 PM
  3. CNC Mill Limit Switches
    By electrosteam in forum METALWORK FORUM
    Replies: 8
    Last Post: 10th September 2010, 07:31 PM
  4. How to Wire Limit switches on Xylotex board.
    By Ch4iS in forum CNC Machines
    Replies: 19
    Last Post: 19th October 2008, 09:58 PM
  5. Xylotex & limit/home switches
    By John H in forum CNC Machines
    Replies: 3
    Last Post: 31st July 2008, 08:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •