Tinkers Projects

Imagine | Develop | Create

Coil Winding MachineMain
Coil Winding Machine0
Coil Winding Machine1
Coil Winding Machine2
Coil Winding Machine3
Coil Winding Machine4
Coil Winding Machine5
Coil Winding Machine6
Coil Winding Machine7
Coil Winding Machine8

I'm will be making a new machine soon that will be able to do more with a better control system. Please send me a message here https://tinkersprojects.com/contact-me/ if you would like to help or get notified of any progress.

This is a coil winding machine to make it easier to wind coil around an object. I have been wanting to make one of these for a while and since there are some projects coming up with coils, I thought this was the best time.

The machine is a very simple design with 3D printed and laser-cut parts with aluminum extrusion as the basic frame. The coils get made using Nema17 motors, all controlled by the PLEX controller with Stepper motor drivers stacked on the Controller.

how the machine works

The machine is very simple, once the object is mounted, wire attached, turned on and homed, the user selects the parameters required and selects run. The machine will then start running. As the objects rotate, the Slide will go back and forth to evenly spread the wire.

This machine could be controlled with GCode but is currently not.

Code for Project

GNU General Public License v3.0
#include <Arduino.h>
#include <gcode.h>
#include <AccelStepper.h>
#include <LiquidCrystal.h>
#include <SimpleMenu.h>
#include <EEPROM.h>
#include <Plex.h>


#define EEPROM_SIZE 20

#define XMultiplier 48.2093663912 // number per 1mm
#define RMultiplier 400 // number per revilution

#define Speed 1000 //200
#define Acceleration 50000000.0

// inputs
#define UpPin 0
#define DownPin 1
#define BackPin 2
#define SelectPin 3
#define xLimitPin 4

// outputs
#define StepPinX 12
#define StepPinR 13
#define DirPin A5
#define XSelect 0
#define RSelect 3
#define enablePin A4

const float pi = 3.14159265359;
int XSpeed = 1000;
int DipSpeed = 1000;

AccelStepper stepperx(1,StepPinX,DirPin);
Plex PLEX;
AccelStepper stepperr(1,StepPinR,DirPin);













/****************************** CONTROL NOT USED YET ******************************/

void HomeMachine();
commandscallback commands[1] = {{"G28",HomeMachine}};
gcode Commands(1,commands);













/****************************** MENUS ******************************/
void About();
void RunProgram();
void SaveSettings();
int numberOfTurns = 100;
int width = 100;
int wireSpacing = 20;

SimpleMenu Menu[6] = {
  SimpleMenu("# of Turns",&numberOfTurns,0,1000),
  SimpleMenu("Width",&width,0,200),
  SimpleMenu("Wire Spacing",&wireSpacing),
  SimpleMenu("Run",RunProgram),
  SimpleMenu("Save",SaveSettings),
  SimpleMenu("About",About)
};

SimpleMenu TopMenu(6,Menu);

void display(SimpleMenu *_menu)
{
  PLEX.lcd.clear();
  PLEX.lcd.print(">");
  PLEX.lcd.print(_menu->name);

  SimpleMenu *next = TopMenu.next();
  if(next != NULL)
  {
    PLEX.lcd.setCursor(1,1);
    PLEX.lcd.print(next->name);
  }
}

void displayValue(SimpleMenu *_menu)
{
    PLEX.lcd.clear();
    PLEX.lcd.print(_menu->name);
    PLEX.lcd.setCursor(0,1);

    if(_menu == &Menu[1])
    {
        PLEX.lcd.print(_menu->getValue());
        PLEX.lcd.print(" mm");
    }
    else if(_menu == &Menu[2])
    {
        int decimalValue = _menu->getValue()%1000;
        int uppervalue = _menu->getValue()/1000;
        PLEX.lcd.print(uppervalue);
        PLEX.lcd.print(".");
        if(decimalValue<10)
        PLEX.lcd.print("0");
        if(decimalValue<100)
        PLEX.lcd.print("0");
        if(decimalValue<1)
        PLEX.lcd.print("0");
        PLEX.lcd.print(decimalValue);
        PLEX.lcd.print(" mm");
    }
    else
    {
        PLEX.lcd.print(_menu->getValue());
    }
    
}












/****************************** MAIN ******************************/
void setup()
{
    Commands.begin();
    
#ifndef __AVR__
    EEPROM.begin(EEPROM_SIZE);
#endif
/*
    pinMode(xLimitPin, INPUT);
    pinMode(UpPin, INPUT);
    pinMode(DownPin, INPUT);
    pinMode(BackPin, INPUT);
    pinMode(SelectPin, INPUT);*/
    pinMode(enablePin, OUTPUT);
    digitalWrite(enablePin,HIGH);

    PLEX.lcd.begin(16,2);
    
    stepperx.setMaxSpeed(Speed/10);
    stepperx.setSpeed(Speed/10);
    stepperx.setCurrentPosition(0);
    stepperx.setAcceleration(Acceleration);
    //stepperx.setPinsInverted(1,0,0); 
    
    stepperr.setMaxSpeed(Speed);
    stepperr.setSpeed(Speed);
    stepperr.setCurrentPosition(0);
    stepperr.setAcceleration(Acceleration);

    LoadData();
    About();  
    Enabled();
    HomeMachine();
    TopMenu.begin(display,displayValue);  
}

void loop() 
{
  if(digitalPressedDelay(UpPin))
  {
    TopMenu.up();
  }
  if(digitalPressedDelay(DownPin))
  {
    TopMenu.down();
  }
  if(digitalPressed(SelectPin))
  {
    TopMenu.select();
  }
  if(digitalPressed(BackPin))
  {
    TopMenu.back();
  }


  if(numberOfTurns<0)numberOfTurns=0;
  if(width<0)width=0;
  if(wireSpacing<0)wireSpacing=0;
}











/****************************** GUI ******************************/

void About()
{
  PLEX.lcd.clear();
  PLEX.lcd.print("Winding  Machine");
  PLEX.lcd.setCursor(0, 1);
  PLEX.lcd.print("Tinkers Projects");
  while(true)
  {
    delay(1);
    if(digitalPressed(SelectPin))
      break;
  }
}


void SaveSettings()
{
    SaveData();

    PLEX.lcd.clear();
    PLEX.lcd.print("     Saved!     ");
    while(true)
    {
        delay(1);
        if(digitalPressed(SelectPin))
        break;
    }

}


void RunProgram()
{
    HomeMachine();

    PLEX.lcd.clear();
    PLEX.lcd.print("Winding  ");
/*
    PLEX.lcd.setCursor(0, 1);
    PLEX.lcd.print("#: ");

/*
    int totalTurns = 0;
    double RealwireSpacing = wireSpacing/100;
    double turnsPreWidth = width/RealwireSpacing;
    double NumberOfLayers = numberOfTurns/turnsPreWidth;
*/
    long x = width*XMultiplier;
    long r = numberOfTurns*RMultiplier;
    stepperx.moveTo(x);
    stepperr.moveTo(r);

    double WidthSpeed = XMultiplier/RMultiplier*(((double)wireSpacing)/1000)*Speed;

    stepperx.setMaxSpeed(WidthSpeed);
    stepperx.setSpeed(WidthSpeed);
      /*  PLEX.lcd.setCursor(3, 1);
        PLEX.lcd.print(WidthSpeed);*/

    while(stepperr.distanceToGo() != 0)
    {
        /*if(digitalPressed(SelectPin))
            break;*/

        if(stepperx.distanceToGo() == 0)
        {
            if(stepperx.currentPosition() == 0)
            {
                stepperx.moveTo(x);
            }
            else
            {
                stepperx.moveTo(0);
            }
        }

        //PLEX.selectD(RSelect);
        stepperr.run();
        //PLEX.selectD(XSelect);
        stepperx.run();
/*
        int totalTurns = 10;//stepperr.currentPosition()/(RMultiplier);
        
        PLEX.lcd.setCursor(3, 1);
        PLEX.lcd.print(totalTurns);*/
        /*
        PLEX.lcd.print(stepperx.currentPosition());
        PLEX.lcd.print(" ");
        PLEX.lcd.print(stepperx.distanceToGo());
        PLEX.lcd.print("       ");

        
        int PercentDone = totalTurns/numberOfTurns;

        PLEX.lcd.setCursor(9, 0);
        PLEX.lcd.print(PercentDone);
        PLEX.lcd.print("%");

        */
    }

    PLEX.lcd.clear();
    PLEX.lcd.print("Finished");
    PLEX.lcd.setCursor(0, 1);
    PLEX.lcd.print("Cut/Remove Coil");



    

    while(true)
    {
        delay(1);
        if(digitalPressed(SelectPin))
        break;
    }

    HomeMachine();
}










/****************************** MACHINE CONTROL ******************************/

void Enabled()
{
  digitalWrite(enablePin,LOW);
}

void Disabled()
{
  digitalWrite(enablePin,HIGH);
}

void HomeMachine()
{
  PLEX.lcd.clear();
  PLEX.lcd.print("Homing");

    stepperx.setMaxSpeed(Speed/3);
    stepperx.setSpeed(Speed/3);

  PLEX.selectD(XSelect);
  while(PLEX.digitalReadC(xLimitPin) == LOW)
  {
    stepperx.move(-10);
    stepperx.run();
  }
  
  stepperx.setCurrentPosition(0);
  stepperr.setCurrentPosition(0);
}












/****************************** OTHER ******************************/

int pinStillPressed = -1;
int Currentdelay = 500;
bool digitalPressed(byte pin)
{
    bool ispressed = LOW;
    while(PLEX.digitalReadC(pin) == HIGH)
    {
        pinStillPressed = -1;
        Currentdelay = 500;
        ispressed = HIGH;
        delay(3);
    }
    return ispressed;
}

bool digitalPressedDelay(byte pin)
{
    bool ispressed = LOW;
    unsigned long timeStarted = millis();
    while(PLEX.digitalReadC(pin) == HIGH)
    {
        ispressed = HIGH;
        if(timeStarted+Currentdelay<millis())
        {
            pinStillPressed = pin;
            Currentdelay -= 50;
            break;
        }
    }

    if(pinStillPressed == pin && PLEX.digitalReadC(pinStillPressed) == LOW)
    {
        pinStillPressed = -1;
        Currentdelay = 500;
    }

    if(Currentdelay<5)
        Currentdelay = 5;

    return ispressed;
}

bool digitalPressed(byte pin, bool PreedValue)
{
    bool ispressed = LOW;
    while(PLEX.digitalReadC(pin) == PreedValue)
    {
        pinStillPressed = -1;
        Currentdelay = 500;
        ispressed = HIGH;
        delay(3);
    }
    return ispressed;
}





void SaveData()
{
    EEPROM.write(0,100);
    EEPROM.put(1, numberOfTurns);
    EEPROM.put(5, width);
    EEPROM.put(10, wireSpacing);
    
#ifndef __AVR__
    EEPROM.commit();
#endif
    
}

void LoadData()
{
    if(EEPROM.read(0) == 100)
    {
        EEPROM.get(1, numberOfTurns);
        EEPROM.get(5, width);
        EEPROM.get(10, wireSpacing);
    }
    
}

I'm will be making a new machine soon that will be able to do more with a better control system. Please send me a message here https://tinkersprojects.com/contact-me/ if you would like to help or get notified of any progress.

This is a coil winding machine to make it easier to wind coil around an object. I have been wanting to make one of these for a while and since there are some projects coming up with coils, I thought this was the best time.

The machine is a very simple design with 3D printed and laser-cut parts with aluminum extrusion as the basic frame. The coils get made using Nema17 motors, all controlled by the PLEX controller with Stepper motor drivers stacked on the Controller.

how the machine works

The machine is very simple, once the object is mounted, wire attached, turned on and homed, the user selects the parameters required and selects run. The machine will then start running. As the objects rotate, the Slide will go back and forth to evenly spread the wire.

This machine could be controlled with GCode but is currently not.

Related Projects