Arduino control for a 3” rotary table

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Hi Foozer,
Followed your steps, set different pins and named them step,dir,en...no change....changed code to numbering the pins rather than naming them....gave cogging when activated and no cogging when turned off.
Ran a few example sketches like blink etc to make sure Mega was working....seems ok...takes an example sketch no worries.

Think I am insane now...still no success....so I still can't work out why this is not running...nothing leaps out at me that may suggest non compliance.

Cheers.
 
I altered the pins again to46,48,50....no go.
Found an example sketch and uploaded...got the stepper moving in very small increment...but moving just the same...yahoo.
cross examined code and change pin nos again, removed const int with byte...but wouldn't compile.
will post both codes i have been workin on.
on the code with const int....I have enable connected negative ...howeve looking at the code it could be trying to connect to enable positive...I have tried compiling with pin 13 en minus sign -....won't compile...is this a reason why ?


/*
4x4 matrix keypad amd a 20 x 4 LCD.
Edit StepsPerRotation & TableRatio(# of turns for 360 degrees)in line 29
M542 driver
5/2/2015
*/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

byte rowPINS[ROWS] = {11,10,9,8};
byte colPINS[COLS] = {7,6,5,4};

Keypad kpd = Keypad(makeKeymap(keys),rowPINS,colPINS, ROWS, COLS);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);// set the LCD address to 0x20 for a 16 chars and 4 line display
// SCL - 21, SDA - 20, VCC - +5, Gnd - Gnd

//setup vars
const int stepPin = 2; // connect pin 2 to step
const int directionPin = 3; // connect pin 3 to dir
const int en = 13; // Stepper Enable Pin 13 this pin connected to the en- of the driver

const int StepsPerRotation = 400; // Set Steps per rotation of stepper NOTE the driver is set to Half step
const int TableRatio = 90; // ratio of rotary table
const int Multiplier = (StepsPerRotation * TableRatio)/360; // 200*90=18000/360 = 50
const int stepdelay = 150;
float Degrees = 0; // Degrees from Serial input
float ToMove = 0; // Steps to move
float bob = 0;
int cho = 0;

void setup()
{
lcd.begin(20,4); // initialize the lcd
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);


// Print welcome message to the LCD.
lcd.backlight();
lcd.print("Rotary Table Control");
lcd.setCursor(4,2);
lcd.print(" ");
lcd.setCursor(3,3);
lcd.print("updated 2016");
delay(2000);

cho = 0;
char key = kpd.getKey();
lcd.print("Enter Selection:");
lcd.setCursor(0,1);
lcd.print("Degrees = A");
lcd.setCursor(0,2);
lcd.print("Divisions = B");
lcd.setCursor(0,3);
lcd.print("JOG = C");
while(cho == 0)
{
key = kpd.getKey();
switch (key)
{
case NO_KEY:
break;
case 'A':
Degrees=getdegrees();
lcd.clear();
cho = 1;
break;
case 'B':
Degrees=getdivisions();
cho=2;
break;
case 'C':
Degrees=getjog();
lcd.clear();
cho=3;
break;
} // end case
} // end while cho=0
} // end setup

void loop() // MAIN LOOP
{

lcd.clear();
char key = kpd.getKey();
bob = 0;
lcd.setCursor(7,0);lcd.print("Total: ");lcd.print(bob,2); // total steps
lcd.setCursor(0,3);lcd.print("FOR=A REV=B X=C");
while(key != 'C') // C will return to start menu
{
lcd.setCursor(0,0);lcd.print(abs(Degrees),2);lcd.print((char)223);
key = kpd.getKey();
if(key == 'A') // FORWARD
{
bob = bob + Degrees;
ToMove = (Degrees*Multiplier);
digitalWrite(3, LOW);
printadvance();
}
if(key=='B') // REVERSE
{
bob = bob - Degrees;
ToMove = (Degrees*Multiplier);
digitalWrite(3, HIGH); // pin 3
printadvance();
}
} // end while not C loop

setup();
} // end main VOID


float getjog()
{
float Degrees = 0;
float num = 0.00;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(6,0);lcd.print("Jogging");
lcd.setCursor(0,1);lcd.print("A=1 B=10 C=100 Steps");
lcd.setCursor(0,2);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;
case 'A':
Degrees = 1;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'B':
Degrees = 10;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'C':
Degrees = 100;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'D':
num=0.00;
lcd.setCursor(14,2);lcd.print(" ");
lcd.setCursor(14,2);
break;
}
key = kpd.getKey();
}
return Degrees;
}


float getdivisions()
{
float Degrees = 0;
float num = 0.00;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(0,1);lcd.print("Enter Division:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
lcd.setCursor(16,1);

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
num = num * 10 + (key - '0');
lcd.print(key);
break;

case 'D':
num=0.00;
lcd.setCursor(16,1);lcd.print(" ");
lcd.setCursor(16,1);
break;
}
Degrees = 360/num;
key = kpd.getKey();
}
return Degrees; //num;
}


float getdegrees()
{
//int key = 0;
float num = 0.00;
float decimal = 0.00;
float decnum = 0.00;
int counter = 0;
lcd.clear();
//lcd.init();
char key = kpd.getKey();
lcd.setCursor(0,1);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
lcd.setCursor(15,1);
bool decOffset = false;

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;

case '.':
if(!decOffset)
{
decOffset = true;
}
lcd.print(key);
break;

case 'D':
num=0.00;
lcd.setCursor(15,1);lcd.print(" ");
lcd.setCursor(15,1);
break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if(!decOffset)
{
num = num * 10 + (key - '0');
lcd.print(key);
}
else if((decOffset) && (counter <= 1))
{
num = num * 10 + (key - '0');
lcd.print(key);
counter++;
}
break;
} //end case
decnum = num / pow(10, counter);
key = kpd.getKey();
} //end while not #
return decnum;
} // end getdegrees

void printadvance() // print function
{
lcd.setCursor(6,1);lcd.print("Moving");
lcd.setCursor(4,2);lcd.print("Steps ");lcd.print(ToMove,0);
lcd.setCursor(13,0);lcd.print(bob,2);
rotation(ToMove,0);
lcd.setCursor(6,1);lcd.print(" ");
}

void rotation(float tm, int d)
{
for(int i = 0; i < tm; i++)
{

digitalWrite(3, HIGH);
delay(stepdelay);
digitalWrite(3, LOW);
delay(stepdelay);

}
}

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
 
Example code...I get small movements... // testing a stepper motor with a Pololu A4988 driver board
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 3;
byte stepPin = 2;
int numberOfSteps = 5000;
byte ledPin = 13;
int pulseWidthMicros = 50; // microseconds
int millisbetweenSteps = 50; // milliseconds

void setup()
{

Serial.begin(9600);
Serial.println("Starting StepperTest");
digitalWrite(ledPin, LOW);

delay(2000);

pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);


digitalWrite(directionPin, HIGH);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros);
digitalWrite(stepPin, LOW);

delay(millisbetweenSteps);

digitalWrite(ledPin, !digitalRead(ledPin));
}

delay(3000);


digitalWrite(directionPin, LOW);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros);
digitalWrite(stepPin, LOW);

delay(millisbetweenSteps);

digitalWrite(ledPin, !digitalRead(ledPin));
}

}

void loop()
{

}
 
Short code just to isolate and test motor operation, use pins 2,3,4.
copy, compile, run - -




/*
* dir-, pul-, en-, all to common GND
Pin 2 Step Control
Pin 3 Direction Control
Pin 4 Enable Control
*/
void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(4, LOW); // enable stepper. set HIGH to disable, freespin
digitalWrite(3, LOW); // Direction, Set to HIGH for opposite direction
}
void loop()
{
digitalWrite(2, LOW);
delayMicroseconds(3000); // slow, increase e.g. 4000 to slow down
digitalWrite(2, HIGH);
delayMicroseconds(3000); // decrease number, e.g 2000 to speed up
}

It should turn with just this loaded . . .
 
We HAVE ROTATION....at last.
Now we know the board, drive and motor work.


Cheers
 
We HAVE ROTATION....at last.
Now we know the board, drive and motor work.


Cheers

Found a keypad so cobbled together the pieces. Using an easydriver to run a nema 13 - easydriver wires up similar, step, dir, enable . . .all common neg. So used pin 12 for enable.

Had a little display menu carryover but
lcd.clear();
lcd.setCursor(0,0);
added before
lcd.print("Enter Selection:"); cured it . .
Works like a champ here. With stepdelay set at 1 get a slight chatter, smooth at 2 -

D is not working as the go back, but for now it's a no nevermind . .
 
Hi Foozer, tried 4 iterations of your code adjusted in the original version, can't get it running...check and once again no errors seem to jump out at me.

/*
4x4 matrix keypad amd a 20 x 4 LCD.
Edit StepsPerRotation & TableRatio(# of turns for 360 degrees)in line 29
M542 driver
* dir-, pul-, en-, all to common GND
Pin 2 Step Control
Pin 3 Direction Control
Pin 12 Enable Control
*/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

byte rowPINS[ROWS] = {11,10,9,8};
byte colPINS[COLS] = {7,6,5,4};

Keypad kpd = Keypad(makeKeymap(keys),rowPINS,colPINS, ROWS, COLS);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);// set the LCD address to 0x20 for a 16 chars and 4 line display
// SCL - 21, SDA - 20, VCC - +5, Gnd - Gnd
//setup vars


const int StepsPerRotation = 400; // Set Steps per rotation of stepper NOTE the driver is set to Half step
const int TableRatio = 90; // ratio of rotary table
const int Multiplier = (StepsPerRotation * TableRatio)/360; // 200*90=18000/360 = 50
const int stepdelay = 2;
float Degrees = 0; // Degrees from Serial input
float ToMove = 0; // Steps to move
float bob = 0;
int cho = 0;

void setup()
{
lcd.begin(20,4); // initialize the lcd
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(12, LOW); // enable stepper. set HIGH to disable, freespin
digitalWrite(3, LOW); // Direction, Set to HIGH for opposite direction




// Print welcome message to the Lcd;
lcd.backlight();
lcd.print("Rotary Table Control");
lcd.setCursor(4,2);
lcd.print(" ");
lcd.setCursor(3,3);
lcd.print("updated 2016");
delay(2000);


cho = 0;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Selection:");
lcd.setCursor(0,1);
lcd.print("Degrees = A");
lcd.setCursor(0,2);
lcd.print("Divisions = B");
lcd.setCursor(0,3);
lcd.print("JOG = C");
while(cho == 0)
{
key = kpd.getKey();
switch (key)
{
case NO_KEY:
break;
case 'A':
Degrees=getdegrees();
lcd.clear();
cho = 1;
break;
case 'B':
Degrees=getdivisions();
cho=2;
break;
case 'C':
Degrees=getjog();
lcd.clear();
cho=3;
break;
} // end case
} // end while cho=0
} // end setup

void loop() // MAIN LOOP
{

lcd.clear();
char key = kpd.getKey();
bob = 0;
lcd.setCursor(7,0);lcd.print("Total: ");lcd.print(bob,2); // total steps
lcd.setCursor(0,3);lcd.print("FOR=A REV=B X=C");
while(key != 'C') // C will return to start menu
{
lcd.setCursor(0,0);lcd.print(abs(Degrees),2);lcd.print((char)223);
key = kpd.getKey();
if(key == 'A') // FORWARD
{
bob = bob + Degrees;
ToMove = (Degrees*Multiplier);
digitalWrite(3, LOW);
printadvance();
}
if(key=='B') // REVERSE
{
bob = bob - Degrees;
ToMove = (Degrees*Multiplier);
digitalWrite(3, HIGH);
printadvance();
}
} // end while not C loop

setup();
} // end main VOID


float getjog()
{
float Degrees = 0;
float num = 0.00;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(6,0);lcd.print("Jogging");
lcd.setCursor(0,1);lcd.print("A=1 B=10 C=100 Steps");
lcd.setCursor(0,2);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;
case 'A':
Degrees = 1;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'B':
Degrees = 10;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'C':
Degrees = 100;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'D':
num=0.00;
lcd.setCursor(14,2);lcd.print(" ");
lcd.setCursor(14,2);
break;
}
key = kpd.getKey();
}
return Degrees;
}


float getdivisions()
{
float Degrees = 0;
float num = 0.00;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(0,1);lcd.print("Enter Division:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
lcd.setCursor(16,1);

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
num = num * 10 + (key - '0');
lcd.print(key);
break;

case 'D':
num=0.00;
lcd.setCursor(16,1);lcd.print(" ");
lcd.setCursor(16,1);
break;
}
Degrees = 360/num;
key = kpd.getKey();
}
return Degrees; //num;
}


float getdegrees()
{
//int key = 0;
float num = 0.00;
float decimal = 0.00;
float decnum = 0.00;
int counter = 0;
lcd.clear();
//lcd.init();
char key = kpd.getKey();
lcd.setCursor(0,1);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
lcd.setCursor(15,1);
bool decOffset = false;

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;

case '.':
if(!decOffset)
{
decOffset = true;
}
lcd.print(key);
break;

case 'D':
num=0.00;
lcd.setCursor(15,1);lcd.print(" ");
lcd.setCursor(15,1);
break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if(!decOffset)
{
num = num * 10 + (key - '0');
lcd.print(key);
}
else if((decOffset) && (counter <= 1))
{
num = num * 10 + (key - '0');
lcd.print(key);
counter++;
}
break;
} //end case
decnum = num / pow(10, counter);
key = kpd.getKey();
} //end while not #
return decnum;
} // end getdegrees

void printadvance() // print function
{
lcd.setCursor(6,1);lcd.print("Moving");
lcd.setCursor(4,2);lcd.print("Steps ");lcd.print(ToMove,0);
lcd.setCursor(13,0);lcd.print(bob,2);
rotation(ToMove,0);
lcd.setCursor(6,1);lcd.print(" ");
}

void rotation(float tm, int d)
{
for(int i = 0; i < tm; i++)
{

digitalWrite(3, HIGH);
delay(stepdelay);
digitalWrite(3, LOW);
delay(stepdelay);
}
}

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
 
Something in sketch you posted that's in error. Probably something lost in the cut and paste [like a few ",s], anywho you know what works, everything works separately but not so much together - So what,s changed from separately to combined?

attached a zip file of the script combined items inclusive. Works here, should work for you . . Have a daughters washing machine broken thing to do today so won't be able to look over your combined script till later in the day.

View attachment Arduino_Rotary_Table_Control_XRayXRay_2017.zip
 
99% success with cheating,
Hi Foozer...Kids are more important than anything else....good luck with the washing machine.

Played around this morning adding and subtracting bits of code...use some of Foozer's and hashed it around a bit....Success with first upload....yahoo...just one glitch....set 90 Degrees on the controller and rotary table turnbs 45 degrees does same for every abngle setting...cuts it in half.

Spent rest of the day so far changing parameters for Table Ratio, Steps per Rotation etc, checking over and over the sketch.....wont turn table past 400 step setting with table ratio reduced from 90...back to 72 or 36....adding in the calculation etc...no success.

I have cheated a bit now to get 90 degrees to turn 90 degrees....did this by editing 360 degrees on sketch back to 180 degrees ....table now turns to whatever degree setting I choose...Awesome.

Would still like to get the sketch fixed without the cheat but I have looked and looked with my untrained eye and can't see anything oout of place.

Here is the sketch......big thanks and appreciation to all those involved....I learned heaps as well....patience from people won out in the end.


/*
4x4 matrix keypad amd a 20 x 4 LCD.
* dir-, pul-, en-, all to common GND
Pin 2 Step Control
Pin 3 Direction Control
Pin 4 Enable Control
*/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'.','0','#','D'}
};

byte rowPINS[ROWS] = {11,10,9,8};
byte colPINS[COLS] = {7,6,5,4};

Keypad kpd = Keypad(makeKeymap(keys),rowPINS,colPINS, ROWS, COLS);
//LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x20 for a 16 chars and 4 line display
// SCL - A5, SDA - A4, VCC - +5, Gnd - Gnd
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

//setup vars
const int stp = 2; // connect pin 2 to step
const int dir = 3; // connect pin 3 to dir
const int en = 12; // connect pin 12 to en
const int StepsPerRotation = 200; // Set Steps per rotation of stepper NOTE the driver is set to Half step
const int TableRatio = 90; // ratio of rotary table
const int Multiplier = (StepsPerRotation * TableRatio)/180;
const int stepdelay = 2000;
float Degrees = 0; // Degrees from Serial input
float ToMove = 0; // Steps to move
float bob = 0;
int cho = 0;

void setup()
{

lcd.begin(20,4);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(12, OUTPUT);

// Print welcome message to the LCD.
lcd.backlight();
lcd.print("Rotary Table Control");
lcd.setCursor(4,2);
lcd.print(" ");
lcd.setCursor(3,3);
lcd.print("updated 2016");
delay(2000);
// lcd.begin;();
cho = 0;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Selection:");
lcd.setCursor(0,1);
lcd.print("Degrees = A");
lcd.setCursor(0,2);
lcd.print("Divisions = B");
lcd.setCursor(0,3);
lcd.print("JOG = C ");
while(cho == 0)
{
key = kpd.getKey();
switch (key)
{
case NO_KEY:
break;
case 'A':
Degrees=getdegrees();
lcd.clear();
cho = 1;
break;
case 'B':
Degrees=getdivisions();
cho=2;
break;
case 'C':
Degrees=getjog();
lcd.clear();
cho=3;
break;
} // end case
} // end while cho=0
} // end setup

void loop() // MAIN LOOP
{
lcd.clear();
char key = kpd.getKey();
bob = 0;
lcd.setCursor(7,0);lcd.print("Total: ");lcd.print(bob,2); // total steps
lcd.setCursor(0,3);lcd.print("FOR=A REV=B X=C");
while(key != 'C') // C will return to start menu
{
lcd.setCursor(0,0);lcd.print(abs(Degrees),2);lcd.print((char)223);
key = kpd.getKey();
if(key == 'A') // FORWARD
{
bob = bob + Degrees;
ToMove = (Degrees*Multiplier);
digitalWrite(3, LOW);
printadvance();
}
if(key=='B') // REVERSE
{
bob = bob - Degrees;
ToMove = (Degrees*Multiplier);
digitalWrite(3, HIGH);
printadvance();
}
} // end while not C loop
// lcd.begin();
setup();
} // end main VOID


float getjog()
{
float Degrees = 0;
float num = 0.00;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(6,0);lcd.print("Jogging");
lcd.setCursor(0,1);lcd.print("A=1 B=10 C=100 Steps");
lcd.setCursor(0,2);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;
case 'A':
Degrees = 1;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'B':
Degrees = 10;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'C':
Degrees = 100;
lcd.setCursor(14,2);lcd.print(Degrees);
break;
case 'D':
num=0.00;
lcd.setCursor(14,2);lcd.print(" ");
lcd.setCursor(14,2);
break;
}
key = kpd.getKey();
}
return Degrees;
}


float getdivisions()
{
float Degrees = 0;
float num = 0.00;
char key = kpd.getKey();
lcd.clear();
lcd.setCursor(0,1);lcd.print("Enter Division:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
lcd.setCursor(16,1);

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
num = num * 10 + (key - '0');
lcd.print(key);
break;

case 'D':
num=0.00;
lcd.setCursor(16,1);lcd.print(" ");
lcd.setCursor(16,1);
break;
}
Degrees = 360/num;
key = kpd.getKey();
}
return Degrees; //num;
}


float getdegrees()
{
//int key = 0;
float num = 0.00;
float decimal = 0.00;
float decnum = 0.00;
int counter = 0;
lcd.clear();
//lcd.begin();
char key = kpd.getKey();
lcd.setCursor(0,1);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
lcd.setCursor(15,1);
bool decOffset = false;

while(key != '#')
{
switch (key)
{
case NO_KEY:
break;

case '.':
if(!decOffset)
{
decOffset = true;
}
lcd.print(key);
break;

case 'D':
num=0.00;
lcd.setCursor(15,1);lcd.print(" ");
lcd.setCursor(15,1);
break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if(!decOffset)
{
num = num * 10 + (key - '0');
lcd.print(key);
}
else if((decOffset) && (counter <= 1))
{
num = num * 10 + (key - '0');
lcd.print(key);
counter++;
}
break;
} //end case
decnum = num / pow(10, counter);
key = kpd.getKey();
} //end while not #
return decnum;
} // end getdegrees

void printadvance() // print function
{
lcd.setCursor(6,1);lcd.print("Moving");
lcd.setCursor(4,2);lcd.print("Steps ");lcd.print(ToMove,0);
lcd.setCursor(13,0);lcd.print(bob,2);
rotation(ToMove,0);
lcd.setCursor(6,1);lcd.print(" ");
}

void rotation(float tm, int d)
{
for(int i = 0; i < tm; i++)
{
digitalWrite(2, HIGH);
delayMicroseconds(1000); // slow, increase e.g. 4000 to slow down
digitalWrite(2, LOW);
delayMicroseconds(1000); // decrease number, e.g 2000 to speed up
}
}

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
 
const int StepsPerRotation = 200; // Set Steps per rotation of stepper
//NOTE the driver is set to Half step

set to 400 along with flipping the switch on the driver to 400 - half steps . .

Washing machines sheet metal Blah, thing bit me twice . . .
 
Didn't work Foozer....no response from anything...I think I have tried every possibility accept the right one.

Bad luck about your getting bit by a washing machine....hope you have had a tetanus shot lately.
 
Didn't resolve the issue...I think I have tried every combination.
Looks like I have picked up a software bug.....thought it might have been a loose connection resetting and starting the rotation by itself....not so have it switched on and it's doing a dance without any input from me....Ghost's in the machine....mmmm don't know where to look for that to be resolved.

Cheers.
 
I never checked to see if a call out of 90 actually gave a 90 degree. If the controller is switched to 400 steps per revolution [half steps] and the sketch is at 200 per revolution that 90 will come out as 45..
Ghost in the machine? Disconnect all and reconnect all, make sure all share a common ground . .
No tetanus shot, If dings and scratches affect the workings don't need to be doing the workings that cause ding and scratches . Good immune system, the nicks never bother me . .Well that one on the wrist underside likes to remind me it's there every time I put my hand into my pocket . .
 
Ghost in the machine could well be a bad earth,,,,seams okay now but those Dupont wires aren't holding up to good with all the unplugging and plugging.....keeping an eye on it and will sort out better cable when it's all sorted.
I'm still thinking and looking at the code to see if I can get out of using 180 and not 360

cheers.
 
use 360 . . .

M542 driver - SW5, "OFF" - - SW6,7,8, "ON" 400 steps [half stepping for a 1.8 degree stepper]
code line in sketch
const int StepsPerRotation = 400; // Set Steps per rotation of stepper NOTE the driver is set to Half step
 
I did the 360, switches and 400 steps...no go...only runs with 200 steps and 180, I've tried every combination since yesterday.

Mounted properly in box with decent wiring...no more ghost's in the machine.

I'm pleased... runs good tho some tweaks would be good....like in degrees in doesn't stop on 360 or even 355...keeps running...no bigy., couple of minor things that those who no how to code might look at one day.

As I have said before I do appreciate the assistance that everyone has put in and grinning and chuffed that it works....will be a great asset for my projects....now to catch up on sleep....cheers.
 
Just an update...had heaps of trouble...rotary table was possessed...would start by itself, change direction without any input from me...go from degrees to jog etc...would just spin at anytime it wanted to.
I checked wiring multiple times and re uploaded sketch a few times...didn't fix the problem till one day it dawned on me that the controller might be picking up interference...disconnected the VFD near it and sure enough no more problems...the poltergeist left the area :}
This is the first time I have actually witnessed an electronic devise affected by another electronic devise with no connection between them, this is probably why i had so much trouble along the way.... Controller is now fastened to a bracket about a meter from the VFD ....makes me wonder whether a 12 volt to 240 volt plug in inverter for cars would have an effect on a Tesla auto drive function.....anyway all is good now

Cheers.
 
Glad to hear it's all sorted, a very tricky problem to diagnose!

....makes me wonder whether a 12 volt to 240 volt plug in inverter for cars would have an effect on a Tesla auto drive function

The inverter may well chuck out a cloud of electromagnetic interference but on such a critical system the car would be very thoroughly shielded to prevent interference, just like all aircraft systems are. You could even mostly shield your controller simply by fully enclosing it within a suitably ferrous box (just some mild steel plate would work pretty well) to give you some piece of mind that it's not going to go crazy on you again..
 
Hi Al, interesting that you say a ferrous enclosure...my enclosure is aluminium.non ferrous, however still a metal...why is this so ? wouldn't the aluminium act as a shield the same as steel...I would have expected this to happen in a PVC enclosure.
Yes I guess your right about self driving cars having to be heavily shielded...lets hope so.

I haven't messed with the controller today...the frustration over days and weeks has been driving me nuts....but I still have the problem of the sketch not working more than 200 steps and a table ratio of 90, next problem to solve but having a break from it for a bit while at least it's stable now...waiting for some ebay parts to arrive to put together a new controller and swap this one out...might get the original sketch to work this time.

Cheers.
 
From my understanding, the metal needs to be ferrous to interact with the magnetic field (other than to generate an induced current, where it only needs to be a metal) to 'interrupt' (not really the right word) the magnetic field. You can do the experiment yourself just to see - grab 2 decently powerful magnets and arrange them with like poles facing each other so they repel, then drop a piece of plate between them and you will see both will stick to each side of the plate, even though without the plate they wouldn't get close to each other. Basically the magnetic fields are no longer interacting with each other and are effectively blocked by the metal. So the theory is a fully enclosed ferrous box would interrupt magnetic influence from any direction and shield your electronics. I haven't done the experiment myself but I am under the impression non-ferrous will not 'interrupt' the field in this manner. I really should try it myself just for curiosity's sake I guess...
 
Back
Top