Thanks Thanks:  0
Needs Pictures Needs Pictures:  0
Picture(s) thanks Picture(s) thanks:  0
Page 7 of 11 FirstFirst ... 234567891011 LastLast
Results 91 to 105 of 163
  1. #91
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Camera slider update

    Hi Rusty
    I'm using a PC and running windows 7
    Looks like I've scared off foobillious, guess he's really busy.
    Ken

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





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

    Default Camera slider update

    Hi foobillious,

    I have sent you a PM.

    Ken

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

    Default

    Hi guys,

    I'm around, but I've been out of town and away form my workshop, decent computer and electronics gear.

    I've had a few thoughts about how to do this and get it to work properly, so I'll post in a day or two when I've actually tried it out.

  5. #94
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Camera slider update

    Hi foob,

    I have sent you another PM

    Ken

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

    Default Camera slider update

    Hi foob and Rusty,

    This is pretty crude, but seems to work, almost.

    To reiterate, I'm driving a carriage along a linear track using an Arduino, Adafruit motor shield and a stepper motor. At each end of the track is a limit switch.

    There are three push buttons, fwd, stop and rev. I have to thank foob for writing the limit switch code, it had me baffled.

    The other requirements are that the motor turn for say half a turn, stop, and turn pin 13 on briefly to fire a camera shutter.

    I have the motor stopping and starting by simply adding delay(1000); to the end of the sketch, and I can get pin 13 to go high, then low, when the motor is stopped.

    The only problem I have is pin13 turns on and off all the time. Sorry if I have confused everyone.

    Attached is the sketch so far

    Ken

    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, MICROSTEP);
    }
    void backwardstep() { 
      motor1->onestep(BACKWARD, MICROSTEP);
    }
    
    
    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);
      pinMode(13,OUTPUT);
    
    
    }
    
    
    
    
    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 = 500;  //  <-- 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);
        delay(1000);
        
       digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(500);              // wait for a second
      digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
      
      }
    }

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

    Default

    Hi Guys, sorry I haven't been responding. I've been busy with my own project, out of town or stuck at work for the last couple of weeks. I'm also out of town this weekend and all next week... *sigh*

    Ken you might want to check out the recent ben heck show episodes on youtube:
    https://www.youtube.com/watch?v=NxlqawCnX3s

    he is doing an auto-tracking camera thing which uses a lot of the same ideas.

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

    Default Camera slider update

    Hi foob,

    I may have over complicated this project with my wishlist requirements.

    Instead of determining how many turns of the motor between stops, by setting a pot, would it be much simpler if the motor is programmed to step say 100 turns between stops?

    Something like motor1->step(100)? Then command it to stop for say 1 second, then continue etc etc?

    Ken

  9. #98
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Camera slider update

    Gentlemen, I really hope I have not bored everyone to tears with my project.

    I now have something that really works, and hope that RustyArc and foobillious read this thread, because I need some advice.

    Briefly the motor rotates approx 1/2 a turn, and stops briefly to pulse pin13, the camera pin. The motor stops when it reaches the delay command down near the bottom of the sketch.

    This is not ideal, can someone show me how to program the stepper to rotate so many steps, say 200 in either direction depending on which push button is pressed.

    I've been fiddling in this area, and can't get anything to work.

    Ken

    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, MICROSTEP);
    }
    void backwardstep() { 
      motor1->onestep(BACKWARD, MICROSTEP);
    }
    
    
    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 CAMERA_PIN 13 
    
    
    
    
    // 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);
      pinMode(13,OUTPUT);  //camera shutter pin
    
    
    }
    
    
    
    
    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 = 500;  //  <-- 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);
        delay (1000);              //Stop the motor
          
        if (sign==0) {            // If motor is stopped by stop button or limit switch
        digitalWrite (13,LOW);    // disable camera pin.
      }else digitalWrite (13,HIGH); // Activate camera pin 
      delay (250);                // Short delay
      digitalWrite (13,LOW);       // Deactivate camera pin
        
      }
    }

  10. #99
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    Quote Originally Posted by neksmerj View Post
    This is not ideal, can someone show me how to program the stepper to rotate so many steps, say 200 in either direction depending on which push button is pressed.
    I've had a very quick look at this - you've used an earlier, and what is probably simpler, version of the code. The catch here is that you can't count steps with this approach, you'd need to use the code Foob wrote.

    What you could probably do with this code is control distance moved based on time, which while not as accurate, is probably easier to code and understand. In short, pressing a direction button would set a time value that would be decremented on each iteration of the loop until it reaches zero, at which point the motor would stop and trigger the shutter pin. It'd also need to stop if it hit a limit or the stop switch was hit.

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

    Default

    Hi guys, i'm back in town and I've got a bunch of electronics stuff i'm planning on playing with this weekend, including another crack at this. I've got some gear that I think will work well enough for testing purposes, so I'll give it a go anyway. I've got to do my stuff first, but hopefully sunday afternoon I'll be able to have a go.

  12. #101
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    Quote Originally Posted by foobillious View Post
    Hi guys, i'm back in town and I've got a bunch of electronics stuff i'm planning on playing with this weekend, including another crack at this. I've got some gear that I think will work well enough for testing purposes, so I'll give it a go anyway. I've got to do my stuff first, but hopefully sunday afternoon I'll be able to have a go.
    Good to hear, I can't say I'm too keen on developing code when I've got no way of testing it on hardware.

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

    Default Camera slider update

    Hi foobillious,

    Welcome back, just chuck all that non important electronic stuff aside, and give the "big project" all your attention.

    A greatly simplified version would be appreciated. Forget about setting the distance travelled by pot, instead setting by software would have to be easier, surely.

    Ken

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

    Default

    Quote Originally Posted by neksmerj View Post
    A greatly simplified version would be appreciated. Forget about setting the distance travelled by pot, instead setting by software would have to be easier, surely.
    The complexity derives, in some respects, from the requirement to count steps as well as checking speed. Foob's also written it in a more structured fashion using functions for different tasks. That ultimately makes it easier to write, debug and add features.

    Setting the step distance by a pot doesn't really add any complexity to the code, it's just an analogue pin read plus some scaling.

  15. #104
    Join Date
    Nov 2008
    Location
    somewhere
    Posts
    152

    Default

    yep, rusty explained it well. There are two functions within the accelstepper library that handle the movement based on distance. The runSpeed function that your using completely skips all the code within the library that checks on distance.

    I'm planning on stepping back a bit and doing a couple of tests - just one program that will move a specified distance back and forward, and another which will move the distance each time a direction button is pushed, changing direction based on the button. Once those work I should have everything needed for the full version.

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

    Default Camera slider update

    Hi foob and rusty,

    great to hear from you guys. I feel such an idiot not to be able to write my own sketches. They say you can't teach an old dog new tricks, I'm an old dog but I have at least had a go.

    foob, feel free to completely rewrite the sketch as you think fit. It was probably unfair of me to shove someone else's code on to you to work with, but I must say, you've done a remarkable job so far.

    Bring on the weekend

    Ken

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