unipolar to bipolar code change

Hi all,im building a coil winder from this site :Arduino Stepper Motor Drive Coil Winder
is there any way to change the code to use an normal bipolar driver,ie step and direction pins for the polulu drivers?,the code on the site is for a unipole stepper,i only have bipolars.thanks in advance.

Please post the program.

...R

#define yellow 9  //Q1
#define orange 10  //Q2
#define brown 11  // Q3
#define black 12 // Q4

#define SW0 2
#define SW1 3
#define SW2 4
#define SW3 5

#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// set the LCD address to 0x27

int i, j;

void setup()  {

  pinMode(SW0, INPUT);
  pinMode(SW1, INPUT);
  pinMode(SW2, INPUT);
  pinMode(SW3, INPUT);

  digitalWrite(SW0, 1); // pull up on
  digitalWrite(SW1, 1); // pull up on
  digitalWrite(SW2, 1);
  digitalWrite(SW3, 1);

  lcd.init(); // initialize the lcd
  lcd.backlight();

  pinMode(black, OUTPUT);
  pinMode(brown, OUTPUT);
  pinMode(orange, OUTPUT);
  pinMode(yellow, OUTPUT);
  all_coils_off();

  lcd.clear();
  lcd.home();
  lcd.print( "M3vuv coilwinder.");

  delay(500); // wait for 1 seconds
  lcd.setCursor(0, 1); // is Home
  lcd.print("Well,Ready to go!");
  
  lcd.print( "M3vuv coilwinder");
  j = 0;

}

void loop() {

  // set turns
  if (!digitalRead(SW0) == 1)   {
    delay(50);
    j = 0;
    lcd.clear();
    lcd.home();
    lcd.print("Turns = 0  ");
    while (!digitalRead(SW0) == 1)   {
      delay(500);
      if (!digitalRead(SW1) == 1) j = j + 1;
      if (!digitalRead(SW2) == 1) j = j + 50;
      lcd.setCursor(8, 0);
      lcd.print(j);
    } // end while
    lcd.setCursor(0, 1);
    lcd.print("Ready to wind.");
  }

  if (!digitalRead(SW3))  {
    lcd.clear();
    lcd.home();
    lcd.print("Turns 0  ");
    for (i = 1; i <= j; i++)   {
      reverse(200);
      lcd.setCursor(6, 0);
      lcd.print(i);
    }
    all_coils_off();
    lcd.setCursor(0, 1);
    lcd.print("Finished ");
  }

} // end loop


void all_coils_off(void)  {
  digitalWrite(black, 0);
  digitalWrite(brown, 0);
  digitalWrite(orange, 0);
  digitalWrite(yellow, 0);

}

void reverse(int i) {
  while (1)   {
    digitalWrite(black, 1);
    digitalWrite(brown, 0);
    digitalWrite(orange, 0);
    digitalWrite(yellow, 1);
    delay(analogRead(0) / 4 + 5);
    i--;
    if (i < 1) break;

    digitalWrite(black, 0);
    digitalWrite(brown, 1);
    digitalWrite(orange, 0);
    digitalWrite(yellow, 1);
    delay(analogRead(0) / 4 + 5);
    i--;
    if (i < 1) break;

    digitalWrite(black, 0);
    digitalWrite(brown, 1);
    digitalWrite(orange, 1);
    digitalWrite(yellow, 0);
    delay(analogRead(0) / 4 + 5);
    i--;
    if (i < 1) break;

    digitalWrite(black, 1);
    digitalWrite(brown, 0);
    digitalWrite(orange, 1);
    digitalWrite(yellow, 0);
    delay(analogRead(0) / 4 + 5);
    i--;
    if (i < 1) break;
  }
}

It would be good to keep the standalone functionality of the sketch but include the stepper librarys and use it with polulu drv drivers,simply because i have these and bipolar motors in my junk bow,unipolar steppers seem expensive here in the uk.

forgot to say my steppers are bipolar 6wire hybrids.

Perhaps convert to AccelStepper library, which confines the details of how many wires and such like to the constructor only, the main code is agnostic to the motor and driver type.

m3vuv:
It would be good to keep the standalone functionality of the sketch but include the stepper librarys and use it with polulu drv drivers,simply because i have these and bipolar motors in my junk bow,unipolar steppers seem expensive here in the uk.

Much as I expected it would probably be easier to rewrite the program from scratch. Converting code from bipolar to unipolar is probably easier :slight_smile:

And it's not a great program in the first place.

These links may help
Stepper Motor Basics
Simple Stepper Code

also look up the AccelStepper library

...R

any idea how to do it?

m3vuv:
any idea how to do it?

In the 9 minutes between my Reply #6 and your Reply #7 I doubt if you studied the links I gave you - for that very purpose.

...R

I did study the links but still dont have a clue, do i try and copy and paste lumps of the code?, im still not sure what parts do what.,any pointers,ive no trouble modding the sketch,ie timings txt on the lcd etc but dont know how to string it together.

m3vuv:
I did study the links but still dont have a clue, do i try and copy and paste lumps of the code?,

Start by trying the code from my link without any change except (if necessary) to match with your Step and Direction connections.

If it works (it should) then study the code so you understand how it works. Then think about how you would extend it to achieve the behaviour that you need.

If it does not work then post the program that YOU uploaded to your Arduino and a photo of a simple pencil drawing showing how you have connected everything. (Note that a photo of your hardware will not be adequate).

...R

PS ... If you just want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

this is the motor i have,see attached datasheet,it looks like it can be run as a unipolar,i just need how to go from 8 wires as per the sort of schematic i posted from 8 wires to 6,i dont want to alter the code unless i have to as the control part of things work fine,ive altered the code to use another button,so button 1 is set,button 2 is ones of turns button 3 is tens and ive added another for hundreds of turns,set the turns press go and off it goes elashing the leds and counting down.

57BYGH420.PDF (50.6 KB)

winder3.jpg

I have never tried it but I believe you make a 6-wire motor into a unipolar motor by joining the wires from the centres of the coils so that you effectively have a 5 wire motor.

However you will then need a suitable unipolar driver and I am not able to advise about that.

...R

Hi robin,its a unipolar driver ive built so thats fine,looks like its all good then,should fingers crossed i should have it finished in the morning,ive a flyback transformer to rewind on my scope, hence the motive to build it,i didnt fancy winding 2000+ windings by hand!,cheers Paul m3vuv.