Thanks Thanks:  0
Needs Pictures Needs Pictures:  0
Picture(s) thanks Picture(s) thanks:  0
Page 3 of 11 FirstFirst 12345678 ... LastLast
Results 31 to 45 of 163
  1. #31
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    sorry about the late reply. A quick google tells me that error is apparantly caused by a comms error as the program is being uploaded. Try saving your sketch, shutting down the arduino software, disconnecting your arduino (unplugging the usb cables). Then plug it all back in again, open the arduino software and try to upload the sketch again.

    you can probably eliminate the pins being an issue by disconnecting everything external to the arduino board before uploading....

    this may also help:
    http://www.instructables.com/id/A-so...nc-not-in-syn/

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





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

    Default Not much luck

    I tried to run the last sketch by Rusty and foob, and nothing except errors again. This is a mystery as this sketch was compiling, and running ok last night, except for the limit switches.

    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"
    RustyArc_stepper:1: error: function definition does not declare parameters
    RustyArc_stepper:22: error: 'AccelStepper' does not name a type
    RustyArc_stepper.ino: In function 'void setup()':
    RustyArc_stepper:43: error: 'stepper1' was not declared in this scope
    RustyArc_stepper.ino: In function 'void loop()':
    RustyArc_stepper:76: error: 'stepper1' was not declared in this scope
    RustyArc_stepper:85: error: 'stepper1' was not declared in this scope
    RustyArc_stepper:90: error: 'stepper1' was not declared in this scope

    And the sketch

    Code:
    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);
      }
    
    
      
    }
    Ken

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

    Default

    Okay, I'm a little puzzled by those errors. Essentially what its saying is there is a problem with the first line of your sketch, which then seems to be carrying into the AccelStepper library and breaking stuff there.

    hmm.. you don't have that 1st line which says Code: actually in your sketch do you? If so, delete it and then try compiling.

    *edit* Yup, that seems to be the problem - I get the same errors as you if I have that first line in. Delete the Code: line and you should be fine.

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

    Default

    Okay, I've verified this compiles, although I havn't tested anything else.

    Give the attached file a try
    Attached Files Attached Files

  6. #35
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default You are a genius

    FINAL TEST

    I've just got home, and read your email. Such a simple oversight causing all those errors. Soon fixed that and rewired the limit switches.

    The other thing I had to do was down in line 8 that reads in part-

    =AFMS.getStepper(200, 1); change 1 to 2 as my motor is connected to terminals M3 & M4, not M1 & M2

    LIMIT SWITCHES

    They work as follows-depress the limit switch and the motor stops. Keep the limit switch depressed and push fwd or rev pb, motor runs only while the button is held down, ie, let go the button and the motor stops.

    This seems to working really well thanks to you and RustyArc

    I'll let you blokes have a little rest before I hit you with the next amendment, and that will be drive carriage for say 300mm, stop and take picture, move another 300mm, stop and take picture etc etc

    I'm impressed,

    Ken

  7. #36
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    So you sorted out the pullups for the limit switches then?

    Good catch picking up the code: thing foobillious - I saw that line 1 error in previous posts, but the penny never dropped. I have to say, the way cutting and pasting works on this forum software can often be a bit offputting.

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

    Default Release command

    Rusty and foob.

    My stepper gets terribly hot rotating or stopped. I know this is one of the drawbacks of steppers, they draw max power when stationary. Since this project will eventually be battery powered, is there some way of squeezing in the "release" command that takes power off the motor when it is stopped?

    I've had several attempts at this and failed. I can't find the right protocol. The command is release()

    Ken

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

    Default

    Before I take a whack at the move x amount then stop code, could you please check if this works?
    I'm a bit tired, but I think it should fix the movement off the limit switches issue, and it should also stop the motor from getting hot if its stopped.
    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, 2);
    
    
    // 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 control direction
      static char enabled=0;                    // used to keep track of if the motor has been enabled (used to allow the motors to idle)
      static int analog_value = 0;              // Holds raw analog value.
      
     
      if (digitalRead(LEFT_PIN)==0 && digitalRead(LEFT_LIM_PIN)==1) {   // allow movement LEFT if the LEFT limit switch isn't hit
          sign=1;
      } else if (digitalRead(RIGHT_PIN)==0 && digitalRead(RIGHT_LIM_PIN)==1) {  // allow movement RIGHT if the RIGHT limit switch isn't hit
         sign=-1;
      } else if (digitalRead(LEFT_LIM_PIN)==0 || digitalRead(RIGHT_LIM_PIN)==0 || digitalRead(STOP_PIN)==0) { // if neither of the above is true, and a limit or stop switch has been hit then stop the motors
         sign=0;
         stepper1.setSpeed(sign);
      }
      
      if (sign!=0) {                          // motor has a valid direction 
        if (enabled==0) {                     // motor was previously disabled, re-enable it (but don't re-enable it every single time we go through the loop)
          enabled=1;
          stepper1.enableOutputs();
        }
      } else {                                  // a limit switch or the stop switch has been hit.  disable the output to the motor.
        enabled=0;
        stepper1.disableOutputs();    
      }
    
      // Give the stepper a chance to step if it needs to
      if (enabled==1) {
        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, if the motor is currently enabled.
      if (enabled==1) { 
        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);
      }
    }

  10. #39
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Limit switch code changes?

    Hi foobillious,

    I was too tired last night to have a proper look at your code changes. Not sure why you changed the limit switch code, they seem to be working as they should.
    Can you briefly describe in English what changes you did and why.

    What I really like about your code changes is the fact that the motor stops, in it's tracks, when a button is pressed or limit switch. As mentioned earlier, the motor would run on for a turn or two before stopping.

    I sent your code to Brian Schmalz for comment, and he was most impressed with the upgrade.

    With respect to the motor getting hot when stopped, I see you have tried to address that problem, however, the motor is still drawing power when stopped. I can feel it vibrating and getting hot.

    This is a bit of a worry.

    Ken

  11. #40
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    Hi Ken,

    Sorry, I must have been more tired than I thought. I was under the impression that it wasn't working the way you wanted it to.

    I changed the switch code so that movement in a direction is allowed only if that direction's limit switch isn't hit. What I think will happen now is if the right limit switch is hit then no movement to the right will be allowed, however if the left direction button is hit then the carriage will start moving to the left at the pre set speed, and will continue in that direction until the other limit switch is hit, or the stop button is pushed. Its pretty straightforward to change it back to the old code. just let me know which way around you want it.

    I'll take a look at the Adafruit library, and see if I can figure out the release command. I was concentrating on the accelstepper library.

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

    Default

    okay, release command was fairly straightforward. I've added it in. We can probably change the disableOutputs(); stuff as well, but I'd like to know if this works first:
    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, 2);
    
    
    // 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 control direction
      static char enabled=0;                    // used to keep track of if the motor has been enabled (used to allow the motors to idle)
      static int analog_value = 0;              // Holds raw analog value.
      
      if (digitalRead(LEFT_PIN)==0 && digitalRead(LEFT_LIM_PIN)==1) {   // allow movement LEFT if the LEFT limit switch isn't hit
          sign=1;
      } else if (digitalRead(RIGHT_PIN)==0 && digitalRead(RIGHT_LIM_PIN)==1) {  // allow movement RIGHT if the RIGHT limit switch isn't hit
         sign=-1;
      } else if (digitalRead(LEFT_LIM_PIN)==0 || digitalRead(RIGHT_LIM_PIN)==0 || digitalRead(STOP_PIN)==0) { // if neither of the above is true, and a limit or stop switch has been hit then stop the motors
         sign=0;
         stepper1.setSpeed(sign);
      }
      
      if (sign!=0) {                          // motor has a valid direction 
        if (enabled==0) {                     // motor was previously disabled, re-enable it (but don't re-enable it every single time we go through the loop)
          enabled=1;
          stepper1.enableOutputs();
        }
      } else {                                  // a limit switch or the stop switch has been hit.  disable the output to the motor.
        enabled=0;
        motor1->release();
        stepper1.disableOutputs();    
      }
    
      // Give the stepper a chance to step if it needs to
      if (enabled==1) {
        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, if the motor is currently enabled.
      if (enabled==1) { 
        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);
      }
    }

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

    Default Release command works

    Hi foobillious,

    You nailed it. (Wish you lived next door, bet you're glad you don't) When the motor is stopped, there's not a hint of any vibration, I don't have a way of verifying it electrically.

    I guess now all the superfluous code can be wiped. Where did you look to find out how the "release" command works and is worded?

    I'm not sure which version of the limit switch code is best, perhaps you could advise. All my requirement was that when the right limit is hit, no further movement can take place in that direction and vica versa. I think both versions of your code do this.

    I really struggled with the release command and got absolutely no help from the Adafruit forum for this project. In the end they gave me the big A and locked the thread, charming!

    I think my age hinders me a bit from learning new tricks, but at least I'm trying and picking things up from you blokes.

    Many thanks

    Ken

  14. #43
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    weird, the adafruit people are normally quite good with newbies. guess they thought you were a troll. Mind you with this sort of thing your only really going to get help if people are in the mood.

    anyway, I found the correct usage by looking in the library file itself. If you go into your arduino libraries folder and into the Adafruit_Motor_Shield folder you'll see a Adafruit_MotorShield.h and Adafruit_MotorShield.cpp file. the .h file is a header file (its just a text file, you can open it with notepad), and basically tells the compiler about a lot of definitions the compiler needs to actually link to the Adafruit library. Include in that are the functions definitions.

    In the Adafruit_StepperMotor class in the public section there is a function: void release(void); which is your release function. the (void) bit tells us that it doesn't need any parameters passed to it, and the void before the word release tells us it doesn't return anything either. The public section means we can access that code from anywhere in our program, as long as we have a Adafruit_StepperMotor object.

    In your code the Adafruit_StepperMotor object is a variable of type Adafruit_StepperMotor called motor1. Its set up on line 10 and 11:
    Code:
    // Define the stepper and the pins it will use
    Adafruit_MotorShield AFMS = Adafruit_MotorShield();            // this creates a variable of type Adafruit_MotorShield called AFMS
    Adafruit_StepperMotor *motor1 = AFMS.getStepper(200, 2);    // this asks AFMS to give us a pointer to one of its Adafruit_StepperMotor objects  
                                                                // a pointer is a reference, or link to the actual object.
    once we have that, if we can use that pointer to call the object's release() function:
    Code:
    motor1->release();
    It's probably not an age thing. It tends to look like giberrish unless you've taken the time to work through and figure out what everything means. Once you understand how programming languages tend to work it becomes a lot easier.

    Moving on though.
    I'm not 100% clear on what your trying to do. I've got a vague concept that you want a camera on a carriage to move a specific distance along the track, stop and take a photo, then repeat? Do you know how far your carriage moves either per step of your stepper motor or per revolution? The way the AccelStepper library works is we can tell it we want to move X steps from the current position, and then it move that far along. If we know how far your carriage moves for a given number of steps then we can use an exact distance. If not then we'll just play around till we get something that works

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

    Default Camera slider operation

    Hi foobillious,

    Thanks for the insight into the Adafruit code.

    I've never actually seen a camera slider in the flesh, but have seen some units on the web whereby everything is controlled by a small LCD screen. Far, far too complicated for me, coding would be a nightmare. I'm just after something very basic with knobs and switches to do the controlling.

    This unit will be used out in the field and I imagine the circuit boards and controls will be in an enclosure. The possibility of changing code on the fly, is not feasible.

    DISTANCE CONTROL

    That said, I would like to be able to control the distance traveled with a potentiometer, say zero to 300mm max per movement, along a 2m track. I believe the GT2 (2mm) toothed pulley is about 25mm in dia so it's circumference is about 78mm, therefore one turn will give me 78mm.

    If you have a better suggestion, I'm all ears.

    I'm really pleased with what you have come up with so far, it's appreciated.

    Ken

  16. #45
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Speed control

    foobillious,

    One other small problem, speed control.

    I will definitely be using the "microstep" function as it's nice and smooth, however, using a 10K pot the max speed is one rev every 10 seconds.

    I'd like to use "microstep" so that some shots can be taken whist the camera is moving. (less jitter)

    I've fiddled with some of the parameters and the speed doesn't seem to alter. Is there an easy way of speeding up the motor?

    Ken

Page 3 of 11 FirstFirst 12345678 ... 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
  •