Show Posts
Pages: [1]
1  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
2  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
3  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
4  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
5  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]