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

    Default

    So you just want an adjustment for the distance moved? When I have a moment I'll hook up a 10K pot and add some code to read & scale it.

    Note that way I'll write it, the code will only check the distance pot once when a direction button is pressed, you won't be able to adjust the distance while the stepper is running.

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





     
  3. #152
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    I've added support for a distance pot - I used a 10K pot with the wiper connected to A0 and the outer pins connected to gnd & 5V. You can set the MAX_DISTANCE and MIN_DISTANCE values to set the range the pot operates over.

    Code:
    /* Ken's Camera Slider ** -------------------------------------------------------------------------------------------
    ** Overview:
    **   Uses a stepper motor to move a camera along a slider, stopping at regular distance 
    **   intervals.
    **   When the movement stops the camera should take a number of photographs, triggered by pin
    **   13 on the arduino going high for a brief pulse.
    **   Direction of the stepper movement is controlled by 2 buttons, Left and Right (or forwards,
    **   backwards).
    **   The stepper motor can be stopped at any time by hitting a stop button, or by one of the
    **   limit switches triggering.  Movement will not continue until a direction button is hit
    **   and the corresponding limit switch is not active.
    **   Distance for each interval is controlled by a potentiometer, as is speed of rotation.
    **
    ** Hardware:
    **   Stepper Motor is connected to an Adafruit Motorshield V2, on motor connector 2
    **   Camera trigger is connected to Digital output 13
    **   All switches use the internal pullup and are connected between the corresponding pin and
    **   ground
              Switch        Digital Pin
              Left      -    2
              Right     -    4
              Stop      -    3
              Left Limit-    7
              Right Limit-   6
              Distance pot-  A0
    **
    **  Required Libraries:
    **  Adafruit MotorShield V2  src:
    **  AccelStepper             src:
    */
    
    
    #include <Wire.h>
    #include <Adafruit_MotorShield.h>
    #include <AccelStepper.h>
    
    
    // Definitions:
    #define LEFT_PIN       2            //  swap this with the RIGHT_PIN value if direction of rotation is not as intended
    #define RIGHT_PIN      4
    #define STOP_PIN       3
    #define LEFT_LIM_PIN   7 
    #define RIGHT_LIM_PIN  6
    
    
    #define DISTANCE_PIN  A0
    #define MAX_DISTANCE 1000
    #define MIN_DISTANCE 100
    #define MAX_SPEED    250
    #define MAX_ACCEL    200
    
    
    #define CAMERA_PIN    13
    #define CAMERA_PULSE  50
    
    
    #define STEPS_PER_REV 200
    #define STEP_TYPE SINGLE         // you can change this to DOUBLE, SINGLE, INTERLEAVE or MICROSTEP to control the step type
    
    
    
    
    // Global Variables:
    Adafruit_MotorShield AFMS=Adafruit_MotorShield();  // access to the motor shield using the default I2C address
    Adafruit_StepperMotor *motor1=AFMS.getStepper(STEPS_PER_REV,2); // connect to a stepper motor
    AccelStepper stepper1(forwardstep,backwardstep);  // use functions to step
    
    
    // setup function just configures the hardware to be operating the way we want it to operate
    void setup()
    {
      Serial.begin(9600);          // serial library will only be used for debug purposes - can safely be removed later
      Serial.println("Ken's Camera Slider");
      
      AFMS.begin();                // connect to the motorshield using the default 1.6kHz frequency
            
      stepper1.setMaxSpeed(MAX_SPEED); // set default speed and acceleration for the accelstepper library
      stepper1.setAcceleration(MAX_ACCEL);
      
      pinMode(LEFT_PIN,INPUT_PULLUP); // set up the input pins
      pinMode(STOP_PIN,INPUT_PULLUP);
      pinMode(RIGHT_PIN,INPUT_PULLUP);
      pinMode(LEFT_LIM_PIN,INPUT_PULLUP);
      pinMode(RIGHT_LIM_PIN,INPUT_PULLUP);
      pinMode(CAMERA_PIN,OUTPUT);    // and the output pin
    }
    
    
    void loop()
    {
      static char dir=0;
      static char stepping=0;
      static int stepdist=0;
      static float dist_prop;
      
      if (stepping) // Check to see if we should stop, check to see if the camera should be fired, run the stepper
      {
        if (digitalRead(STOP_PIN)==0 || (digitalRead(LEFT_LIM_PIN)==0 && dir==1) || (digitalRead(RIGHT_LIM_PIN)==0 && dir==-1))
        {
         stepping=0;
         stepper1.moveTo(stepper1.currentPosition());
         stepper1.run();
         motor1->release();
         dir=0;
        }
        else
        {
          if (stepper1.distanceToGo()==0)  //Arrived at shooting point
          {
            delay(200);
            TrigCamera();
            delay(50);
            UpdateDistance(stepdist,dir);
          }
          stepper1.run();
        }
        
      }
      else  // We're stopped. Check direction buttons to see if we should start, if so, set the speed and distance - these values could be read from pots.
      {
        if (digitalRead(LEFT_PIN)==0 && digitalRead(LEFT_LIM_PIN)==1)
        {
          dir=1;
          stepping=1;
          dist_prop=analogRead(DISTANCE_PIN)/1023.0;            // read the distance pot and convert it to a proportion of the pot travel.
          stepdist=dist_prop * (MAX_DISTANCE-MIN_DISTANCE) + MIN_DISTANCE; // Scale according to max and min limits, and offset
          UpdateDistance(stepdist,dir);
        }
        else if (digitalRead(RIGHT_PIN)==0 && digitalRead(RIGHT_LIM_PIN)==1)
        {
          dir=-1;
          stepping=1;
          dist_prop=analogRead(DISTANCE_PIN)/1023.0;            // read the distance pot and convert it to a proportion of the pot travel.
          stepdist=dist_prop * (MAX_DISTANCE-MIN_DISTANCE) + MIN_DISTANCE; // Scale according to max and min limits, and offset
          UpdateDistance(stepdist,dir);
        }
        
      }
      
    }
    
    
    void TrigCamera()
    {
      digitalWrite(CAMERA_PIN,HIGH);
      delay(CAMERA_PULSE);
      digitalWrite(CAMERA_PIN,LOW);
    }
    
    
    void UpdateDistance(int stepdist, char dir)
    {
      long newpos;
      
      newpos=stepper1.currentPosition() + (stepdist*dir);
      stepper1.moveTo(newpos);
    }
    
    
    
    
    // this function will be called by the AccelStepper every step the motor turns forward
    void forwardstep()
    {
        motor1->onestep(FORWARD, STEP_TYPE);
    }
    
    
    // this function will be called by the AccelStepper every step the motor turns backward
    void backwardstep()
    {
        motor1->onestep(BACKWARD, STEP_TYPE);
    }

  4. #153
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Camera slider update

    Hi Rusty,

    The distance pot add-on works a treat. I reckon this just about concludes this project unless foob has some more to add.

    I reckon it's about time I started ordering some hardware and get this project constructed.

    I did mention way way back that I intend using OpenBuilds hardware. Very professional stuff that doesn't cost an arm and a leg.

    http://openbuildspartstore.com/

    Gentlemen, again I can't thank you enough for your combined efforts.

    Ken

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

    Default

    Nothing more from me - very nice work rusty.

  6. #155
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    All good. I'll add the speed pot when I get a spare moment - the code will be identical to the distance pot stuff.

    I did have a quick play with the microstepping mode - anyone know what parameters need to be set to get it to do the same RPM as it does in single-step mode?

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

    Default

    Here you go:


    Code:
    /* Ken's Camera Slider ** -------------------------------------------------------------------------------------------
    ** Overview:
    **   Uses a stepper motor to move a camera along a slider, stopping at regular distance 
    **   intervals.
    **   When the movement stops the camera should take a photograph, triggered by pin
    **   13 on the arduino going high for a brief pulse.
    **   Direction of the stepper movement is controlled by 2 buttons, Left and Right (or forwards,
    **   backwards).
    **   The stepper motor can be stopped at any time by hitting a stop button, or by one of the
    **   limit switches triggering.  Movement will not continue until a direction button is hit
    **   and the corresponding limit switch is not active.
    **   Distance for each interval is controlled by a potentiometer, as is speed of rotation.
    **
    ** Hardware:
    **   Stepper Motor is connected to an Adafruit Motorshield V2, on motor connector 2
    **   Camera trigger is connected to Digital output 13
    **   All switches use the internal pullup and are connected between the corresponding pin and
    **   ground
              Switch        Digital Pin
              Left      -    2
              Right     -    4
              Stop      -    3
              Left Limit-    7
              Right Limit-   6
              Distance pot-  A0
              Speed pot -    A1
    **
    **  Required Libraries:
    **  Adafruit MotorShield V2  src:
    **  AccelStepper             src:
    */
    
    
    #include <Wire.h>
    #include <Adafruit_MotorShield.h>
    #include <AccelStepper.h>
    
    
    // Definitions:
    #define LEFT_PIN       2            //  swap this with the RIGHT_PIN value if direction of rotation is not as intended
    #define RIGHT_PIN      4
    #define STOP_PIN       3
    #define LEFT_LIM_PIN   7 
    #define RIGHT_LIM_PIN  6
    #define DISTANCE_PIN  A0
    #define SPEED_PIN     A1
    
    
    #define MAX_DISTANCE 1000
    #define MIN_DISTANCE 100
    #define MAX_SPEED    250
    #define MIN_SPEED    50
    #define MAX_ACCEL    200
    
    
    #define CAMERA_PIN    13
    #define CAMERA_PULSE  50
    
    
    #define STEPS_PER_REV 200
    #define STEP_TYPE SINGLE         // you can change this to DOUBLE, SINGLE, INTERLEAVE or MICROSTEP to control the step type
    
    
    
    
    // Global Variables:
    Adafruit_MotorShield AFMS=Adafruit_MotorShield();  // access to the motor shield using the default I2C address
    Adafruit_StepperMotor *motor1=AFMS.getStepper(STEPS_PER_REV,2); // connect to a stepper motor
    AccelStepper stepper1(forwardstep,backwardstep);  // use functions to step
    
    
    // setup function just configures the hardware to be operating the way we want it to operate
    void setup()
    {
      Serial.begin(9600);          // serial library will only be used for debug purposes - can safely be removed later
      Serial.println("Ken's Camera Slider");
      
      AFMS.begin();                // connect to the motorshield using the default 1.6kHz frequency
            
      stepper1.setMaxSpeed(MAX_SPEED); // set default speed and acceleration for the accelstepper library
      stepper1.setAcceleration(MAX_ACCEL);
      
      pinMode(LEFT_PIN,INPUT_PULLUP); // set up the input pins
      pinMode(STOP_PIN,INPUT_PULLUP);
      pinMode(RIGHT_PIN,INPUT_PULLUP);
      pinMode(LEFT_LIM_PIN,INPUT_PULLUP);
      pinMode(RIGHT_LIM_PIN,INPUT_PULLUP);
      pinMode(CAMERA_PIN,OUTPUT);    // and the output pin
    }
    
    
    void loop()
    {
      static char dir=0;
      static char stepping=0;
      static int stepdist=0;
      static int stepspeed=0;
      static float pot_prop;
      
      if (stepping) // Check to see if we should stop, check to see if the camera should be fired, run the stepper
      {
        if (digitalRead(STOP_PIN)==0 || (digitalRead(LEFT_LIM_PIN)==0 && dir==1) || (digitalRead(RIGHT_LIM_PIN)==0 && dir==-1))
        {
         stepping=0;
         stepper1.moveTo(stepper1.currentPosition());
         stepper1.run();
         motor1->release();
         dir=0;
        }
        else
        {
          if (stepper1.distanceToGo()==0)  //Arrived at shooting point
          {
            delay(200);
            TrigCamera();
            delay(50);
            UpdateDistance(stepdist,dir);
          }
          stepper1.run();
        }
        
      }
      else  // We're stopped. Check direction buttons to see if we should start, if so, set the speed and distance - these values could be read from pots.
      {
        if (digitalRead(LEFT_PIN)==0 && digitalRead(LEFT_LIM_PIN)==1)
        {
          dir=1;
          stepping=1;
          pot_prop=analogRead(DISTANCE_PIN)/1023.0;            // read the distance pot and convert it to a 0 to 1 proportion of the pot travel.
          stepdist=pot_prop * (MAX_DISTANCE-MIN_DISTANCE) + MIN_DISTANCE; // Scale according to max and min limits, and offset
          UpdateDistance(stepdist,dir);
          pot_prop=analogRead(SPEED_PIN)/1023.0;            // read the speed pot and convert it to a proportion of the pot travel.
          stepspeed=pot_prop * (MAX_SPEED-MIN_SPEED) + MIN_SPEED; // Scale according to max and min limits, and offset
          stepper1.setMaxSpeed(stepspeed);
        }
        else if (digitalRead(RIGHT_PIN)==0 && digitalRead(RIGHT_LIM_PIN)==1)
        {
          dir=-1;
          stepping=1;
          pot_prop=analogRead(DISTANCE_PIN)/1023.0;            // read the distance pot and convert it to a proportion of the pot travel.
          stepdist=pot_prop * (MAX_DISTANCE-MIN_DISTANCE) + MIN_DISTANCE; // Scale according to max and min limits, and offset
          UpdateDistance(stepdist,dir);
           pot_prop=analogRead(SPEED_PIN)/1023.0;            // read the speed pot and convert it to a proportion of the pot travel.
          stepspeed=pot_prop * (MAX_SPEED-MIN_SPEED) + MIN_SPEED; // Scale according to max and min limits, and offset
          stepper1.setMaxSpeed(stepspeed);           
        }
        
      }
      
    }
    
    
    void TrigCamera()
    {
      digitalWrite(CAMERA_PIN,HIGH);
      delay(CAMERA_PULSE);
      digitalWrite(CAMERA_PIN,LOW);
    }
    
    
    void UpdateDistance(int stepdist, char dir)
    {
      long newpos;
      
      newpos=stepper1.currentPosition() + (stepdist*dir);
      stepper1.moveTo(newpos);
    }
    
    
    
    
    // this function will be called by the AccelStepper every step the motor turns forward
    void forwardstep()
    {
        motor1->onestep(FORWARD, STEP_TYPE);
    }
    
    
    // this function will be called by the AccelStepper every step the motor turns backward
    void backwardstep()
    {
        motor1->onestep(BACKWARD, STEP_TYPE);
    }

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

    Default Camera slider update

    Many thanks for adding back in the speed pot, that works well. Tis a pity it can't be adjusted on the fly, but that's ok.

    This project is for the benefit of my son who is an avid photographer and storm chaser. I can't think of anything more stupid than driving into the eye of an electrical storm.

    I mentioned to my son that the only thing to top this project off would be a touch screen. Five seconds later he said "Like this". He bought one for a Raspberry pi project, and apparently, it's not suitable, so now I have one.

    Question. Is it difficult to incorporate a touch screen with an Arduino? I imagine certain connections would need to be made, some sort of library downloaded, and some push button graphics be added.

    I haven't a clue so am looking for advice.

    Again thanks foob and Rusty.

    Ken

  9. #158
    Join Date
    Jun 2010
    Location
    Canberra
    Posts
    769

    Default

    I've been following what has been asked for in functional terms, not a specific application. In doing so, I've reduced the implementation to a very simple 2-state machine. The benefit is that it is indeed very simple, easy to understand, and easy to modify the parameters.

    The cost of that simplicity is functionality, such as on-the-fly speed or distance adjustment. If that is something you need, then it can be implemented, however the code will be more complicated.

    As for touch-screens, there may well be libraries for the Arduino, but the level of complexity skyrockets. You have to render what appears on the screen as well as handling the tactile feedback. Given the interface has only 3 buttons and two pots, I'm wondering what extra functionality a touch-screen would provide?

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

    Default

    Yep, Rusty's implementation is clean and elegant, but getting the speed and distance pots to trigger an update is going to be messy. that gets back into the land of what I was doing, and its harder to understand and/or debug, particularly when your trying to achieve consistent movement.

    A better solution might be to do an additional update of the pots when the camera is being fired. That way you change the pots, and the next movement of the motor would have the new settings. I suspect that would be much more difficult to "drive" from the users point of view however.

    Realistically though, if you think about how a photographer is likely to want to use it. They'll probably spend some time setting things up, getting things moving at the rate and distance they want, then they'll reset to the start and do it for real. Rusty's implementation is likely to work very well for that.

    With regard to the touchscreen - depending on which touchscreen you've got there may be arduino libraries available for it. However you'll need to design and build a gui interface for it and do lots of other things. One thing to keep in mind is while your arduino is processing inputs and displaying things on the screen it isn't triggering motor steps, which means your motor will turn more slowly. Again, how useful would it be? If your just emulating some buttons and two pots, its easier (and cheaper) to do it with the buttons and two pots. If you want to display some data (distance or speed settings), your probably still better of just using a 16x2 LCD and displaying data on that.

    Before you head down the touchscreen path I'd recommend you spend a week or so just playing with your arduino and learning how to write programs that will do what you want. Jeremy Blum's tutorials on youtube are probably a good starting point. They are pretty easy to understand and the circuits are easy/cheap to build: https://www.youtube.com/playlist?lis...67CE235D39FA84 . That'll get you a long way.

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

    Default Camera slider update

    Gentlemen,

    what you both say is absolutely right, so we'll skip the touch screen. I only mentioned it because I have one and thought it would look "neat".

    I had no idea how complex it would turn out to be, and I'm more than happy with the current sketch.

    Well done fellas,

    Ken

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

    Default

    Hi Ken,

    Let me know once you've finished testing and are happy with its behaviour and I'll post the board back to you.

    Russell.

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

    Default Camera slider update

    Hi Rusty,

    I have sent you an email.

    Many thanks to you and foob

    Ken

  14. #163
    Join Date
    Nov 2006
    Location
    Heidelberg, Victoria
    Age
    79
    Posts
    2,251

    Default Camera slider update

    Today I had the pleasure of meeting Steven Brown, owner of Maker Store in the southern suburbs of Melbourne.

    There I picked up a length of 40x20 V-slot extruded aluminium track, wheel assemblies, motor mount, idler mount etc, etc, etc, and a length of 3mm pitch toothed belt.

    I felt like a kid in a lolly shop, parts in bins everywhere.

    On the floor was a fantastic cnc router made up of his parts, the OpenBuilds track system is second to none.

    As soon as I get my camera slider assembled, I'll post some photos.

    Ken

Page 11 of 11 FirstFirst ... 67891011

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
  •