Go Down

Topic: 28BYJ-48 5-Volt Stepper (Read 87 times) previous topic - next topic

celem

I haven't tried either of your sketches yet but you have been busy. Given your comments about heat and 12-volt operation apparently you are putting a lot of stress testing with your stepper(s).

sbright33

What is the expected life of a stepper?  I have discovered that 8v 6xNiMh or 12v is fine so long as you turn off the power when it's not moving.  Or between steps when it's moving slowly.  The 64:1 gear ratio keeps most external torque from changing the current phase in the sequence when the power is off.  My functions prove this concept.  Notice my parameters in the function calls look like this:  4500 is 45 degrees.  4525 is 45.25 degrees.  3050 is 30.50 RPM.  The slow functions take RPHour.  Just multiply RPM*60 if you prefer to use that instead.  You can even step by 2.00 degress for example without microstepping.  1/2 stepping?  1/8 stepping?  The 8-step size is not a whole interval of 2.00, but you can step 180 times and it will be 360 degrees of rotation anyway.  degrpm() supports ramping.  Or just use degrpm8() if 1/11th of a degree is good enough for you.  The only thing to add is speed ramping to achieve the highest RPM in degrpm8.  I figure it's not important because we're only moving a short distance anyway. 

Does anyone have code to translate an arbitrary angle to X and Y motors?  In other words 45 degrees would mean moving each motor 1 microstep at a time alternating evenly between them.  0 degrees is all X.  90 degrees all Y.  I don't want to move one motor 30 steps and the other 40 that would look jaggy.  Arctan gives you the ratio, but I need more than that.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

sbright33

I have added the ability to measure a torque load and stop when it reaches the end of pulling a string for example.
Also Serial.printing turns or degrees as it is running.
Increased resolution to +-1/22 degrees in degrpm8().
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

celem

sbright33 - your sketch posted on January 13, 2012, 06:51:43 PM is missing declarations for cw() and ccw().

Also, has your testing with microsecond delays determined an optimal delay in microseconds after doing the stepper write?

celem

#19
Jan 14, 2012, 11:17 pm Last Edit: Jan 14, 2012, 11:19 pm by celem Reason: 1
I rewrote my original stepper test to utilize direct port manipulation. I hesitated in doing this until I was positive that writes to PORTB were not going to mess up the crystal on PB6 & PB7 - it does not. DO NOT TRY THIS SKETCH unless your setup is identical to the sketch. The PORTB writes only write to Digital pins 8-to-13. If you use different pins then you MUST rewrite the sketch. Read the other warning in the sketch. This sketch only been tested on an Arduino NANO.

Code: [Select]

// WARNING: USE AT YOUR OWN RISK!!!
// Do not use this script if your Arduino doesn't use a Atmega328 or Atmega168
// It is only been tested on an Arduino NANO
// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, which is readily available on eBay, using a ULN2003
// interface board to drive the stepper.
//////////////////////////////
// The Atmega328p chips used on the Arduino board have three ports.
// We are interested in port B:
// We are using Arduino Digital bits 8-11, which map to Atmega328p PB0-PB3
// B (digital pin 8 to 13)
// NOTE: as tested by anescient, there's no harm in writing to PORTB as long as DDRB[6:7] are 0
// Read: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261361330
////////////////////////////////////////////////
// The speed and direction of the stepper motor is determined
// by adjusting a 1k-ohm potentiometer connected to Arduino pin A2.
// When the potentiometer is rotated fully counterclockwise, the motor
// will rotate at full counterclockwise speed. As the potentiometer is
// rotated clockwise, the motor will continue to slow down until is
// reaches its minimum speed at the the potentiometer's midpoint value .
// Once the potentiometer crosses its midpoint, the motor will reverse
// direction. As the potentiometer is rotated further clockwise, the speed  
// of the motor will increase until it reaches its full clockwise rotation
// speed when the potentiometer has been rotated fully clockwise.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                       // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 0;     //variable to set stepper speed
int potPin = 2; //potentiometer connected to A2
int potValue = 0; //variable to read A0 input


//////////////////////////////////////////////////////////////////////////////
void setup() {
 //declare the motor pins as outputs
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
 Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

 potValue = analogRead(potPin);     // read the value of the potentiometer
 Serial.println(potValue);          // View full range from 0 - 1024 in Serial Monitor
 if (potValue < 535){               // if potentiometer reads 0 to 535 do this
   motorSpeed = (potValue/15 + 5);  //scale potValue to be useful for motor
   clockwise();                     //go to the ccw rotation function
 }
 else {                             //value of the potentiometer is 512 - 1024
   motorSpeed = ((1024-potValue)/15 + 5); //scale potValue for motor speed
   counterclockwise(); //go the the cw rotation function
 }
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)

void counterclockwise (){
 // 1
 PORTB = 0b0001;
 delay(motorSpeed);
 // 2
 PORTB = 0b0011;
 delay(motorSpeed);
 // 3
 PORTB = 0b0010;
 delay(motorSpeed);
 // 4
 PORTB = 0b0110;
 delay(motorSpeed);
 // 5
 PORTB = 0b0100;
 delay(motorSpeed);
 // 6
 PORTB = 0b1100;
 delay(motorSpeed);
 // 7
 PORTB = 0b1000;
 delay(motorSpeed);
 // 8
 PORTB = 0b1001;
 delay(motorSpeed);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
//delay "motorSpeed" between each pin setting (to determine speed)

void clockwise(){
  // 1
  PORTB = 0b1000;
 delay(motorSpeed);
 // 2
 PORTB = 0b1100;
 delay(motorSpeed);
 // 3
 PORTB = 0b0100;
 delay(motorSpeed);
 // 4
 PORTB = 0b0110;
 delay(motorSpeed);
 // 5
 PORTB = 0b0010;
 delay(motorSpeed);
 // 6
 PORTB = 0b0011;
 delay(motorSpeed);
 // 7
 PORTB = 0b0001;
 delay(motorSpeed);
 // 8
 PORTB = 0b1001;
 delay(motorSpeed);
}


Now if I can determine the optimal "motorspeed" value then I can optimize the stepper's functionality.

Go Up