Tips for Arduno software for Rotary Table Controllers

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.
Just wanted to publically say "BIG THANKS" to Rod for producing the code. I ve downloaded it today and looked over the content. I can see there has been a bucket load of work thats gone into writing it.

I've loaded the code to the UNO. Still waiting on the screen.

Q. Does anyone have a diagram of the external wiring? If not, no biggie, will read through the code again and grab the important pins from it.

Cheers
Michael

Michael, glad you like it.

Step and direction use a pin each. You also need to connect ground to the stepper controller for each of these signals and you may need to send +5v to an enable pin in some stepper controllers.

I think from memory, you can set the pins for step and direction in the setup section and it will be saved to the EEPROM. It took me a long time before I realised that the random movement in the stepper motor when downloading the script was because I was using the same pins as the USB serial port....

Remember, it also can do linear movements but nobody has tested that section of it and because it supports multiple setups, you can use it on different machines. I had in mind to use it for a power feed in my mill.
 
Just a quick note guys, in my video the segmented demonstration shows the axis move past 120 degrees. This was a minor setup error by me in that I didnt change the microstepping from 2 to 10. In short, i couldnt be arsed re-doing the video so it stayed in.
 
I have assembled a stepper drive along with the Arduino and LCD for a rotary table. I downloaded all the necessary files. The program compiles fine and loads without any warnings or errors. What I’m running into is, no matter what I change in the parameters the outcome is only the same. It moves only one direction and the steps per increment are always the same. It seems that it ignores all my changes. Does anybody have any ideas on what the problem is?
 
I have assembled a stepper drive along with the Arduino and LCD for a rotary table. I downloaded all the necessary files. The program compiles fine and loads without any warnings or errors. What I’m running into is, no matter what I change in the parameters the outcome is only the same. It moves only one direction and the steps per increment are always the same. It seems that it ignores all my changes. Does anybody have any ideas on what the problem is?

Make sure you are actually saving the data in the setup menu.
Sounds like you have a mismatch between the setup and your actual wiring. If the direction port is wrong in setup, you would probably still be able to turn one direction only.
 
Hi RodW

I’m using a SainSmart LCD. I had to change the Pins to 12 and 13 for it to move both directions. That works fine now. I still am not seeing any change when I change the MICRO_STEPS or DIVIDE_RATIO. The motor turns a little over 9 turns no matter what I change. This is my present setup.

Thanks.
Mark

#define STEP_PIN 13
#define DIR_PIN 12
#define MINUTES_IN_CIRCLE 1296000 // Number od seconds in a 360 degree circle
#define MAX_LONG 2147483646 // The biggest number we can use with a long
#define CONFIG_VERSION "RT4" // The Sigature to tell us we've saved stuff in the EEPROM
#define NO_DEVICE_SIG "XXX" // The Sigature to tell us we've got nothing in the EEPROM
#define DEV_ROTARY 0 // Device Type - Rotary Table
#define DEV_LINEAR 1 // Device Type - Linear device mm

#define SUB_VER 1 // Change on each version
#define STEPPER_STEPS_REV 200 // The number of steps per stepper
#define MICRO_STEPS 32 // set to 1 if not not using a micostepper driver, otherwise set to # microsteps
#define DIVIDE_RATIO 6 // The Dividing table ratio (eg 40 or 90)
#define MM_PER_REV 2 // Travel per mm
#define MAX_STEPPER_HZ 10000 // Maximum frequency for this stepper
#define MIN_STEPPER_HZ 5000 // Minimum frequency for this stepper
#define TIMER_DELAY 80 // 80 MIcroseconds between interrupt ticks
#define JOG_STEP_ANGLE 1800L // 0.5 degrees (30 seconds)

struct globals_t // Size = 40 bytes
{

 
Hi RodW

I’m using a SainSmart LCD. I had to change the Pins to 12 and 13 for it to move both directions. That works fine now. I still am not seeing any change when I change the MICRO_STEPS or DIVIDE_RATIO. The motor turns a little over 9 turns no matter what I change. This is my present setup.

I think you have totally missed the level of sophistication in this script. You do NOT configure it by editing the code. Thats what the setup menu is for. So rollback to the original code. Modify it for your LCD if required. Then compile and download it.

Then from within the menu structure on the Arduino, select Setup, configure it for your hardware including the pins you are using. Save the setup. It is then saved in flash RAM and retrieved on startup. You should be right to go.

Note that multiple devices are supported and these are numbered from 0. This lets you use the same electronics for multiple devices. Linear devices that just go back and forth can also be configured. Eg.for a motor drive for a miling table X axis.
 
#define STEP_PIN 1
#define DIR_PIN 2

Am a novice with arduino, however those two pins [1, 2] are interrupt pins. Would seem that changing the pin numbers as done to 12, 13 [non-interrupt] will defeat the purpose of the timer interrupt driven scheme.
 
#define STEP_PIN 1
#define DIR_PIN 2

Am a novice with arduino, however those two pins [1, 2] are interrupt pins. Would seem that changing the pin numbers as done to 12, 13 [non-interrupt] will defeat the purpose of the timer interrupt driven scheme.

No, that doesn't matter as we are using timer interrupts which are tied to the clock, not a physical port. I think the real problem is that the config remains incorrectly configured with a mismatch between physical ports and what is stored in eeprom that is sent to the stepper controller. If you think about it, any pin will work for the direction signal and the stepper will go left or right depending on whether the port is high or low. But if you are changing the direction value on the wrong port, it will be permanently stuck in either forward or reverse motion.
 
But if you are changing the direction value on the wrong port, it will be permanently stuck in either forward or reverse motion.

Time to hook up my little cigar box stepper test and load your program

if (setupForm.isCurrent(sDirPinField)) {
globals.DirPin = sDirPinField.value();

input value from sDirPinField becomes DirPin [High, Low] value becomes actual direction ? - - Oh Boy . . .
 
RodW

I got my controller configured and everything works fine now. Thanks for your help and your great program.

Mark
 
Time to hook up my little cigar box stepper test and load your program

if (setupForm.isCurrent(sDirPinField)) {
globals.DirPin = sDirPinField.value();

input value from sDirPinField becomes DirPin [High, Low] value becomes actual direction ? - - Oh Boy . . .

Long time since I've looked at this code. What you are looking at is code using the 3rd party LCD class that drives the menus and data entry in one of the libraries. Classes are part of C++ and did not exist in the original C language.

So if the current field being edited is the direction pin field, get the value from the LCD class and store it in the globals structure. LOW and HIGH are defines in the Arduino and are the same as TRUE and FALSE which is a fancy way of saying 1 or 0.

So now we know the pin to write direction to. All globals are stored in a structure so it is super simple to read and write them all to the EEPROM.

So in a rotary table, we are interested in moving CLOCKWISE or ANTICLOCKWISE which are DEFINED to be LOW and HIGH. Different tables may have a different default rotation direction so we can change the definition around by swapping the CLOCKWISE/ANTICLOCKWISE LOW and HIGH defines.

So in theory the code should become more readable even if it is compact and efficient as there is no room for verbose code!

So Foozer, finally, the last procedure in the file is the actual timer interrupt service routine (ISR). It is attached in the setup routine and taken from the default setup in Hz. THe trick here is that a Hz is one cycle per second so that implies 2 passes through the ISR, one for off and one for on. Thats why i have some conversion routines as it makes more sense to configure a stepper motor in Hz as this is how the data sheet is written.

Here endeth the lesson. Good luck!
 
RodW

I got my controller configured and everything works fine now. Thanks for your help and your great program.

Mark

Glad you got it going. I was thinking that if you compiled and ran the default program, the EEPROM would be overwritten with the default data. If you subsequently edited the globals in the code and recompiled, the EEPROM data did not get overwritten. Because the data existed in EEPROM, it would be retrieved and stored over the top of your globals data.
 
So in theory the code should become more readable even if it is compact and efficient as there is no room for verbose code!

So Foozer, finally, the last procedure in the file is the actual timer interrupt service routine (ISR).

Here endeth the lesson. Good luck!

Got it, naw I don't, but it's percolating . .

Didn't like having to write over and over the stepper commands in the script so wouldn't exactly call it a library but made a cpp to hold the blash blah blah then in script one line does it
Stepper.CW(dirR,stepR,rateR);
Stepper.CCW(dirR,stepR,rateR);

void StepperXY::CW(int pin1, int pin2, int pin3) // pin1 dir, pin2 step, pin3 rate microseconds
{
pinMode(pin1, OUTPUT); // dir
pinMode(pin2, OUTPUT); // step
digitalWrite(pin1, HIGH); // CW
delayMicroseconds(5);
if (digitalRead(pin1) == HIGH) // probably not needed
{
digitalWrite(pin2, !digitalRead(pin2));
delayMicroseconds(pin3);
}
}

It's always fun to learn something new, just keep the aspirin coming .
 
Got it, naw I don't, but it's percolating . .

It's always fun to learn something new, just keep the aspirin coming .

I try and avoid using delay() as it locks the Arduino to see whats going on. Here's how I did it after displaying the welcome screen while still servicing the keyboard.

Code:
   while(1){  // Delay 2 seconds without using delay();
     currentMillis = millis();
     if(currentMillis - previousMillis > interval) {
        previousMillis = currentMillis;
        break;  
     }
     event = lcd.getButton();
   }

Rolling right back to Version 2 of my script, you can do it with interrupts in 200 lines of code. Still uses the LCD library. I think V1 had about 150 lines of code to prove the interrupt approach would work.

This simpler example will make it much easier to learn whats going on. Here's the minimalist ISR routine. In the ZIP file it still includes the original sample code to flash the LED so I knew what was going on but I've removed that below as its a distraction.

Code:
void timerIsr()
{
    // Toggle LED
  if(steps){
      state = state ^ 1;
      digitalWrite( stepPin, state );
      steps--;
  }

So for each alternate call to the ISR, we need to swap between LOW or HIGH to make the stepper move. We do that with the state variable
Code:
state = state ^ 1;
This line does a Bitwise XOR (Exclusive OR) with 1
so:
0 XOR 1 = 1 and
1 XOR 1 = 0

which is a lot simpler (and faster) than
Code:
if(state ==1) 
   state = 0
else 
   state = 1;
Remember, speed is king in the ISR!

View attachment RotaryTableChuck2.zip
 
I try and avoid using delay() as it locks the Arduino to see whats going on. Remember, speed is king in the ISR!

Getting dark earlier so it's time to look back into interrupts . .
Oh ya - Your program works on my little cigar box stepper test platform - Had to get the values from freetronics and rig up the voltage divide for the buttons - Turn it on, push some buttons and away it goes . . .

I know i'm missing something - if I run
for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, !digitalRead(thisPin));
delayMicroseconds(600);
)
It's only 1/2 revolution whereas

for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, LOW);
delayMicroseconds(600);
digitalWrite(thisPin, HIGH);
delayMicroseconds(600);
}
is a full turn - But what it is I don't see . . .
 
Getting dark earlier so it's time to look back into interrupts . .
Oh ya - Your program works on my little cigar box stepper test platform - Had to get the values from freetronics and rig up the voltage divide for the buttons - Turn it on, push some buttons and away it goes . . .

I know i'm missing something - if I run
for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, !digitalRead(thisPin));
delayMicroseconds(600);
)
It's only 1/2 revolution whereas

for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, LOW);
delayMicroseconds(600);
digitalWrite(thisPin, HIGH);
delayMicroseconds(600);
}
is a full turn - But what it is I don't see . . .

Because the first example writes to the stepper pin half as often as the second.

Eg first loop has 1 x digitalWrite (either on or off each iteration)
second loop has 2 x digitalWrites (both on and off each iteration)

Good luck with it.
 
Hello In all, Fight Contributions I am quite dull What you can

I Need Help An Old Norwegian, I Have a rotary table Ratation 1:72 Having read through the forum for a few days now, Don mostly but not the relationship between 1:72 ratation And Nema motor 23 looks we are talking about 200 step 400 step . Can anyone help me What motor should I buy and possibly how to change code in arduino ?? I have all the parts in place but can not find this out with engine and ratation, HAS TB6560 3A stepper motor driver that I thought I'd use. If eny have the file for 1:72 ratation and can giwe me Tips which motor to use , I can do it *_*

Thanks All
And I am very grateful for the help here

Call me a dummy but at this trips I checkmate
 
If you go.to this thread
http://www.homemodelenginemachinist.com/showthread.php?t=25091

, the installation is set out step by step. Pretty much any NEMA23 will have enough power to turn a rotary table.provided.if has enough volts. I found 19v was not enough and went to 48v. Most steppers are 200 steps per rev. I get my steppers from steppersonline who I think have an .eu site. Is get a 4 wire 2.8 amp stepper with your controller

Once the software is installed, go to the setup menu to set the software.to agree with your Arduino pins etc.
 

Latest posts

Back
Top