Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Repeating steps (Timelapse project) on: June 09, 2014, 08:22:30 am
I think you could solve your problem with a variable that keeps track of the position (step number) of the motor. So if, after 10 movements the accumulated position is (say) 5736 all you need to do to get back to the start is do 5736 steps in the other direction.

You might consider using the AccelStepper library which has functions that keep track of the position and it also saves you the chore of using digitalWrite()s to cause the motor pulses.

...R

Hi Robin,

Many thanks for your help. I was planning on just altering my code and learning what it means.

Kind regards,
James
2  Using Arduino / Programming Questions / Repeating steps (Timelapse project) on: June 08, 2014, 12:56:46 pm
Hi There,

I have been making a camera slider for motion timelapse and have come to a hault with some coding. I basically need for the main bit of the code to repeat so many times so the slider goes in one direction (at the moment is it set to do it 10 times, I think) - once that has been completed I would like it to go back to the start in one movement and either start the first bit of code again or stop completely. I have been trying to find some code where it counts every time the step is completed and once the limit has been reached then another piece of code it activated to take the slider to the beginning.

Could someone point me in the right direction?

Cheers,
James

Code:
#define RELAY 6                 // Pin number 6 on Arduino Board
#define DIRECTION 7        // Pin number 7 on Arduino Board
#define STEP_PIN 8          // Pin number 8 on Arduino Board
int movemotor = 10;         // Runs program 10 times

void setup(){
pinMode(RELAY, OUTPUT);                 // Sets RELAY as an OUTPUT (Pin 6)
pinMode(DIRECTION, OUTPUT);        // Sets DIRECTION as an OUTPUT (Pin 7)
pinMode(STEP_PIN, OUTPUT);          // Sets STEP_PIN as an OUTPUT (Pin 8)
}

void loop(){
/* 8 microsteps per step. A 200 step stepper would take 1600 micro steps for one full revolution.
.25 is best speed for my motor - 15200 microsteps = 9.5 revolutions of motor (15200 / 1600 = 9.5) */

if (movemotor >=10){
rotate(-1520, .25);                          // Move so many steps at .25 speed
delay(1000);                                   // Delay to stop camera shake (1 Sec)
digitalWrite(RELAY,HIGH);            // Turn RELAY ON (Fires camera)
delay(300);                                    // Delay for 1/30th Sec
digitalWrite(RELAY,LOW);            // Turn RELAY OFF
delay(1700);                                  // Delay for 1.7 Sec before continuing
}
}

void rotate(int steps, float speed){
/* rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger */
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);
digitalWrite(DIRECTION,dir);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}
3  Using Arduino / Programming Questions / Re: Programming a stepper motor with H-Bridge on: May 12, 2013, 06:34:23 am
Hi,

My stepper motor is a 1.8 degree which means 200 steps. I have it attached to my timelapse slider and I've worked out through trial and error that I can do 500 steps (see code). At the moment it only goes in one direction. How do I reverse? Also is there a way to include the RPM in the code for speed control?

Code:
    #define ENA 2
    #define IN1 3
    #define IN2 4
    #define IN3 5
    #define IN4 6
    #define ENB 7
     
    void setup() {
      // Setup code to run once:
      pinMode(ENA, OUTPUT);
      pinMode(IN1, OUTPUT);
      pinMode(IN2, OUTPUT);
      pinMode(IN3, OUTPUT);
      pinMode(IN4, OUTPUT);
      pinMode(ENB, OUTPUT);
     
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      digitalWrite(ENB, HIGH);
     
    }
     
    void loop() {
      // Main code here, runs repeatedly:
      right1(); // Right
        for (int i = 0 ; i < 500; i++ ) {
        right2();
      }
      delay(5000);
      disengage();
      delay(1000);   
    }
     
    void right1() {
      digitalWrite(ENA, HIGH);
      digitalWrite(ENB, HIGH);
    }
         
    void disengage() {
      digitalWrite(ENA, LOW);
      digitalWrite(ENB, LOW);
    }
         
    void right2() {
     
      //101011
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      digitalWrite(ENB, HIGH);
      delayMicroseconds(1000);
     
      //000011
      digitalWrite(ENA, LOW);
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      digitalWrite(ENB, HIGH);
     
     
      //110011
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      digitalWrite(ENB, HIGH);
      delayMicroseconds(1000);
     
      //110000
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      digitalWrite(ENB, LOW);
      delayMicroseconds(1000);
     
      //110101
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      digitalWrite(ENB, HIGH);
      delayMicroseconds(1000);
     
     
      //000101
      digitalWrite(ENA, LOW);
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      digitalWrite(ENB, HIGH);
      delayMicroseconds(1000);
     
     
      //101101
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      digitalWrite(ENB, HIGH);
      delayMicroseconds(1000);
     
      //101000
      digitalWrite(ENA, HIGH);
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      digitalWrite(ENB, LOW);   
      delayMicroseconds(1000);
    }

Kind regards,
James Dolan
4  Using Arduino / Programming Questions / Programming a stepper motor with H-Bridge on: May 08, 2013, 02:42:37 pm
Hi there,

I am having problems understanding some code for my unipolar stepper motor using a arduino uno and a dual h-bridge motor driver board. I have it set up exactly like this " http://www.geekonfire.com/wiki/index.php?title=Dual_H-Bridge_Motor_Driver#Drive_Two_phase_4-wire_stepping_motor " - i am using the following code:

Code:
int ENA=2;//connected to Arduino's port 2
int IN1=3;//connected to Arduino's port 3
int IN2=4;//connected to Arduino's port 4
int ENB=5;//connected to Arduino's port 5
int IN3=6;//connected to Arduino's port 6
int IN4=7;//connected to Arduino's port 7
 
void setup()
{
 pinMode(ENA,OUTPUT);
 pinMode(ENB,OUTPUT);
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT);
 pinMode(IN4,OUTPUT);
 digitalWrite(ENA,HIGH);//enablae motorA
 digitalWrite(ENB,HIGH);//enable motorB
}
void loop()
{/*In the way of 4 beats to drive the stepping motor,A group connected to motorA,B
 B group connected to motorB,Suppose A representing the forward current of A group,
 A- representing the reverse current of A group,B representing the forward current of B group,
 B- representing the reverse current of B group.
 this way run as follow:
 AB    A-B    A-B-   AB-
 or
 AB   AB-    A-B-   A-B
 */
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH);
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW);
 delay(10);
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH);
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,HIGH);
 delay(10);
 digitalWrite(IN1,HIGH);
 digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,HIGH);
 delay(10);
 digitalWrite(IN1,HIGH);
 digitalWrite(IN2,LOW);
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW);
 delay(10);
}

My question is, how do I set the amount of steps and how do I add delays? Is there an easier way to code what I am trying to do? I understand this code on this website fine: http://www.tigoe.com/pcomp/code/circuits/motors/stepper-motors/ but I just can't get my head around this one.

I am adding this stepper motor on my homemade camera slider and I'm new to coding. In the long run I would like to be able to make a step, delay "camera shoot" and then loop this process. I will also eventually add my LCD keypad to be able to program the stepper motor whilst shooting timelapse.

Any help would be greatly appreciated.

Kind regards,
James Dolan
5  Using Arduino / Displays / LCD Keypad Shield Issues on: May 06, 2013, 10:21:14 am
Hi,

I am having problems with my LCD Keypad Shield (1602) with displaying properly:



As you can see the first 'letter' on each line are cut off and I am not sure why. This is the code:

Code:
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);  // adjust this to suit your pins.

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hello, James!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

Does anyone know what could be causing this?

Kind regards,
James Dolan
6  Using Arduino / Project Guidance / Re: Hybrid Stepper Motor? on: March 04, 2013, 03:45:16 pm
Hi John,

Thanks for clearing things up, it makes sence to me now.

I shall let you know how I go on.

Kind regards,
James
7  Using Arduino / Project Guidance / Hybrid Stepper Motor? on: February 27, 2013, 04:04:25 pm
Hi,

I'm new to Arduino Uno and was wondering what a 'hybrid' stepper motor actually is. I aquired one a while ago but have never managed to get it running, but now I have an arduino I might actually be able to.

The motor is have is this:
http://uk.rs-online.com/web/p/stepper-motors/1918299/?searchTerm=191-8299&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E2C5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D424552267573743D3139312D383239392677633D4E4F4E4526

And I want to try and use this tutorial:
http://arduino.cc/en/Tutorial/MotorKnob

Now, in the tutorial it gives the option for either unipolar or bipolar but not a hybrid. Is a hybrid a unipolar or bipolar or something completley different. I really need to know before I start getting an array or H bridge.

Any help is greatly appreciated.

Many thanks,
James
Pages: [1]