# Interrupt Driven Rotary Table controller



## rodw (Nov 30, 2015)

You can read the thread where this is documented form go to woe during the development here:
http://www.homemodelenginemachinist.com/showthread.php?p=273830#post273830
 if you need more help but this thread is designed to provide a simple easy to install solution of version 10 of my Rotary Table controller.

I am going to assume you already have installed the Arduino IDE on your PC. Don't worry if you don't have an Arduino at this stage.

All you have to do is to find the Arduino folder in "My Documents". On my PC it was in this folder *C:\Users\Rod\Documents\Arduino* and unzip the attached file into it. I am guessing that you have a different name to me so it will be a bit different on your PC  Please substitute my name with yours....

So you should now have the following folders in the Arduino folder
*C:\Users\Rod\Documents\Arduino\libraries
C:\Users\Rod\Documents\Arduino\RotaryTable10*

In the *Libraries* folder you should find the following folders
*C:\Users\Rod\Documents\Arduino\libraries\LCD
C:\Users\Rod\Documents\Arduino\libraries\TimerOne-r11
*

In the *C:\Users\Rod\Documents\Arduino\RotaryTable10* folder you will find the following files:
*EEPROMAnything.h
RotaryTable10.ino*

Assuming you have the Arduino IDE installed on your PC if you double click on
*RotaryTable10.ino* and it should open in the IDE.







Click the Button marked with the Red Arrow to verify that the script will compile. This does not require an Arduino attached to your PC so you can get it compiling before you spend your money.

Then, grab yourself these things:
1. An Arduino Uno or equivalent
2. A Freetronics LCD display; see http://www.freetronics.com.au/collections/display/products/lcd-keypad-shield
3. A stepper controller
4. A stepper motor. NEMA 23 is a good size for a 6 inch Rotary table
5. Power supply (minimum 24 volt in my experience, around 80% of what you stepper driver is rated for - I use a 48 volt power supply).

With the LCD attached to your Arduino, plug your Arduino into a USB port, check your system is properly configured and hit the button pointed to by the blue arrow.  The script will be recompiled and downloaded to your Arduino. The Arduino screen should light up after this process.

Connect up your stepper controller to the Arduino. making sure you are working on the low voltage side of the controller. You need to provide 5 volt power, ground and a step and direction port. The Arduino has enough current to drive the stepper controller.

Then connect power to the high voltage side of your controller and connect the wires correctly to your stepper motor.

Check the Setup menu and set up the step and direction ports to agree with those you chose when connecting your Arduino to the Stepper controller. Also set the various pulse parameters to suit your hardware.

Check the maxHz and MinHz settings in the setup folder. Start at around 5,000 and 9,000 (for Max and Min respectively or accept the defaults).

Makee sure you save the setup.

You should not need to touch the code to get it going as everything is set in the setup menu and stored in the EEPROM  memory forever on the Arduino.

Note that the script also supports linear devices and multiple devices. via the new device function in setup. This simply creates a new numbered setup in the EEPROM. You can load devices at will to swap between devices when setup.

The main feature of this controller is that it uses interrupts for high performance and this also allows it to ramp up and down to speed so that it can overcome inertia by running slowly at maximum torque and ramping up to speed.

There are heaps of dividing functions, jogging and continuous turning. Some people have modified this script to alter the speed while continuous turning but on a 90:1 rotary table like mine, the maximum speed you are going to get is about 4 RPM so it is a bit pointless attempting to change the speed IMHO.

Anyway, I'm sure I've overlooked some stuff but please try this and report back. Just remember if you are not using a Freetronics LCD display and keyboard you are on your own! 

View attachment RotaryTable10.zip


----------



## rodw (Dec 1, 2015)

Here are links to hardware that will work (and you can grab both in the one order)
Freetronics Arduino Compatible board : http://www.freetronics.com.au/collections/arduino/products/eleven#
Freetronics Keyboard and LCD: http://www.freetronics.com.au/collections/display/products/lcd-keypad-shield#

Any Arduino UNO Compatible board will work. I have used the board above, a genuine UNO and a Chinese Clone without any dramas.
As stated above, the LCD display on this link is the one the LCD library is designed for.


----------



## xpylonracer (Dec 12, 2015)

Hi Rod

I Downloaded your Rotary Table 10 program but get an Error message when Verifying sketch, Error:

 Temp1_RotaryTable10.zip\RotaryTable10\RotaryTable10.ino:1:23: fatal error: BoolField.h: No such file or directory
 #include <BoolField.h>
                       ^
compilation terminated.
exit status 1
Error compiling.

Any idea if it's me, my computer or the sketch ?

Emgee


----------



## rodw (Dec 13, 2015)

xpylonracer said:


> Hi Rod
> 
> I Downloaded your Rotary Table 10 program but get an Error message when Verifying sketch, Error:
> 
> ...



The error message shows the compiler cannot find an include  file. You have not installed the LCD library which should be in 
C:\Users\YourName\Documents\Arduino\libraries\LCD

Please read the first post carefully and follow the instructions as the missing file is included in the Zip file.


----------



## mulac321 (Jan 27, 2016)

hi Rodw, amazing work. i wrote a programme to do this for a pic, but yours is far superior. 
my controller has a common anode (5v) pin and 3 pins for step pulse and enable. i think this means my controller requires the inputs to go low to step. is this compatible with your programme? i think it is backwards to most stepper controllers.


----------



## rodw (Jan 28, 2016)

mulac321 said:


> hi Rodw, amazing work. i wrote a programme to do this for a pic, but yours is far superior.
> my controller has a common anode (5v) pin and 3 pins for step pulse and enable. i think this means my controller requires the inputs to go low to step. is this compatible with your programme? i think it is backwards to most stepper controllers.



Thanks Mulac.

I don't think you will have any problem. I might be wrong, but I don't think this code has any concept of low and high signals. This is because if it has to move 100 steps, there are 200 distinct states which alternate on and off. The worst you could be out is therefore one step because the first state change is ignored as you started on the wrong foot so to speak. In this case, changing the definition for the variable "state" would start you off on the right foot.


----------



## rodw (Oct 17, 2016)

Mike has a great video of this working here:
https://youtu.be/thxf7Uw0q2Y

Thanks Mike!


----------



## John S (Oct 17, 2016)

rodw said:


> Mike has a great video of this working here:
> https://youtu.be/thxf7Uw0q2Y
> 
> Thanks Mike!



At 1:50 he makes the unit move 3 divisions or 120 degrees.
On the first move one chuck jaw is vertically down, subsequent moves should leave one jaw still vertically down but on the last move the jaws are well out ??


----------



## Toolguy (Oct 17, 2016)

I was wondering about that too.


----------



## rodw (Oct 18, 2016)

John S said:


> At 1:50 he makes the unit move 3 divisions or 120 degrees.
> On the first move one chuck jaw is vertically down, subsequent moves should leave one jaw still vertically down but on the last move the jaws are well out ??



It can only be missed steps from poorly configured hardware, (maybe too low a voltage) as the software is spot on and proven by a number of other users.


----------



## Johno1958 (Feb 14, 2017)

Hi Rodw.
First of all thank you for all the time and effort documenting a great program.
That said I can't for the life of me get it to work lol. I am using Saintsmart uno and 1602 lcd six button shield and a tb6560 driver. I can load the sketch no worries but I dont seem to be able to get the driver part working. I have the liming sketch up and running ok. My question is I can't seem to find a wiring diagram .Is there one posted?
Cheers
john


----------



## rodw (Feb 15, 2017)

Johno1958 said:


> Hi Rodw.
> First of all thank you for all the time and effort documenting a great program.
> That said I can't for the life of me get it to work lol. I am using Saintsmart uno and 1602 lcd six button shield and a tb6560 driver. I can load the sketch no worries but I dont seem to be able to get the driver part working. I have the liming sketch up and running ok. My question is I can't seem to find a wiring diagram .Is there one posted?
> Cheers
> john



John, first of all, I have never used the Sainsmart but a few people have used it with this sketch. I think that you may need to modify the LCD library in the keyboard sensing code and its been documented bys others in my other thread linked to in the first post. However by the sounds of it you have got this part working. If the displays and menus work, it will be fine!

So its always best to start with basics in the Arduino core library before you use a complex program. Maybe this one. https://www.arduino.cc/en/Reference/Stepper

So once you know you have a working stepper driver, install my sketch and configure the settings including the step and direction pins in the setup menu. If you have not done that, it probably is the reason why nothing moves.

There is not much to the wiring. step+ and dir+ go to the relevant digital pins and step- and dir- go to the Arduino ground. Attach the high voltage for the stepper to your controllers stepper power terminals. I'm not sure of the TB6660
but in some cases you need active low wiring so check your documentation. I've never had to do that with the Arduino though.


----------



## Johno1958 (Feb 15, 2017)

Hi Rod
Yes you are right .I never configured the step and dir pins. I will read through your thread again as I glossed over a lot of  parts which were flying well over my head.
I do find this project very interesting.
Thanks
John


----------



## rodw (Feb 15, 2017)

Johno1958 said:


> Hi Rod
> Yes you are right .I never configured the step and dir pins. I will read through your thread again as I glossed over a lot of  parts which were flying well over my head.
> I do find this project very interesting.
> Thanks
> John



Glad you got it going.


----------



## rodw (Jun 29, 2017)

Hmm Captain_Obvious reported a not so obvious bug in my software that bit where a rotary table has a coarse resolution. Where say a division required  say 100.333 steps per division, the number was rounded to 100.0. This meant on say 36 divisions around a complete circle, the final division could end up being 12 steps short.

I don't currently have any working hardware to test this on but I know it compiles.

Here is a replacement GoDivide procedure. Can those using this sketch cut and paste this into your config to replace the existing goDivide procedure and see if it is working correctly?


```
void goDivide(long gAngle)
{
   long thisDiv = 1; 
   int event = LCD_BUTTON_NONE;
   int flag = 0;
   float tmpSTEPS_PER_REV = (float)globals.stepsPerRev;
   float remainder;
   float divLeftOver = 0.0;
   long adjustSteps = 0;
   
   stepsPerDiv = (long)(tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder = (float) (tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder -= (float)stepsPerDiv;
   divisions = (long)((float) MINUTES_IN_CIRCLE / (float) gAngle);
   printDivideVals(thisDiv,gAngle);
   while(event != LCD_BUTTON_SELECT){
      event = lcd.getButton();
      switch(event){
        case LCD_BUTTON_LEFT:
          flag++;
          thisDiv--;
          divLeftOver -= remainder;
          if(thisDiv < 1)
            thisDiv = divisions;
          digitalWrite( globals.DirPin, ANTICLOCKWISE );
          break;
        case LCD_BUTTON_RIGHT:
          flag++;
          thisDiv++;
          divLeftOver += remainder; 
          if(thisDiv > divisions)
            thisDiv = 1;          
          digitalWrite( globals.DirPin, CLOCKWISE );
          break;       
    }
    if(flag){ 
      if(abs(divLeftOver) >= 1.0){
        adjustSteps = 1;
        if(abs(divLeftOver) == divLeftOver)  
          divLeftOver -= 1.0;    // Positive value >= 1.0
        else
            divLeftOver += 1.0;  // Negative Value <= 1.0
      } else
          adjustSteps = 0;
    }   
    setSteps((stepsPerDiv + adjustSteps) * 2, 1);
    printDivideVals(thisDiv,gAngle);
    flag = 0;
  }
}
```

So what the code attempts to do is to now is to save the fractional steps in a variable called *remainder *(say 0.33 in our 100.33 example). This is accumulated in each step in the variable *divLeftOver *every time a division is made. If this variable is <= 1.0 or >=1.0, it is adjusted by 1.0 closer to zero and the number of steps in the current division is incremented by 1. That way, we should end up back on track when we complete a complete circle.

Please provide your feedback.


----------



## Captain_Obvious (Jun 29, 2017)

Hello again,

I tried the new script but I don't know what went wrong. As soon as I start the division or the angle program, the stepper motor just runs continuously, briefly stopping at the given number of divisions. None of the buttons do anything except for the reset button. I'm not anywhere near advanced enough to analyze to script myself. All the other functions work just like they did before.

Attached is the misbehaving script. 

View attachment rotaryscript.zip


----------



## Cogsy (Jun 29, 2017)

Hi Rod,
I don't have the hardware to test either, nor do I have a lot of experience programming in C but looking at the code in your if(flag) I saw this line: _if(abs(divLeftOver) == divLeftOver)_ , which is comparing floats for equality. I realise it's the same variable and you're just taking the absolute value, but because of the abs function return I think you still run the normal risks of float equalities here. I've been stung by it before so it just sort of jumped out at me, so I thought I'd mention it.


----------



## Foozer (Jun 30, 2017)

Freetronics shield is ordered so can test it as you wrote it . . .


----------



## rodw (Jun 30, 2017)

Guys, I'm not sure what I got wrong. I'll have another look at this. Cogsy, yes I hate working with floats too. What I wanted to do is to determine if divLeftOver is a positive or negative number and there are other ways to do that. 

Before I started, I modified the code to eliminate a couple of lines of duplicated code so I might have then stuffed up the working code...


----------



## Captain_Obvious (Jun 30, 2017)

OK, no worries. I appreciate you taking the time to do this in the first place.


----------



## Foozer (Jun 30, 2017)

Obvious - Which pin are you using to read the buttons? Far as I can tell the LCD library to run 'event = lcd.getButton()' wants it to be A0


----------



## Captain_Obvious (Jun 30, 2017)

The buttons are soldered parallel to the LCD shield buttons. I haven't changed anything in the code, so I imagine A0 is the default for the LCD shield. The buttons work perfectly fine browsing through the menus and the jog function works just like it used to and so does the continous running function. 

I'm only having problems with the division and angle programs. After selecting the number of divisions or the angle and pressing select to start, the program starts running and no button will stop it. I have to reset to get it to stop. This was not an issue with the original script. Only now that I replaced the goDivide routine with the new one, this problem appeared.


----------



## Wizard69 (Jul 2, 2017)

Ive been following this thread loosely since its start.   I haven't commented much due to no hardware to even try anything out on.  However i have noticed people having problems with floating point.  This is not uncommon in the Computer Sciences industry as there are all sorts of gotchas.  

This has me wondering if any body has tried using integers to count arbitrary numbers of fractional degrees?   This can be likened to how banking apps count in cents via integers values instead of using floating point.   So you take a circle and divide it up into one hundredths or one thousands of a degree and do you calculations based on the fractional degrees you selected.  

So if you want to work in 1/100ths of a degree you effectively have 36000 parts in a circle.  Gear reductions impact this as do steeper counts per rev and could result in Integer overflow and may require 32 bit integers.  The goal though is one count equals 1/100th of a degree.  

Frankly guys my algebra is rusty!   I just have to wonder if floating point in your calculations is worth the trouble they cause.  There are whole books written on the use of floating point in computers due to all the things that must be considered to get the right results.   

I hope this doesn't distract i just don't gave hardware to test any thing I'm thinking about right now.


----------



## Foozer (Jul 3, 2017)

For S&G while awaiting for the freetronixs shield to arrive, tried the Sainsmart button shield. It init's by the lcd library the same [LCD() : LiquidCrystal(8, 9, 4, 5, 6, 7)], has the same button return values, however, to quote "the program starts running and no button will stop it." 


Shall see what comes up when the freetronics shield arrives . . .


----------



## rodw (Jul 3, 2017)

It looks like I had a misplaced closing bracket as these two lines were outside of the while loop.


```
setSteps((stepsPerDiv + adjustSteps) * 2, 1);
      printDivideVals(thisDiv,gAngle);
```
In the original code, these lines were both repeated in each case statement but if I had of left the code this way I would have two fairly large blocks of repeated code so I did not want to waste the memory. So by setting a flag in the case statements, I added another if statement that can be used for both case statements (eg for both left and right buttons).


So try this: 

```
void goDivide(long gAngle)
{
   long thisDiv = 1; 
   int event = LCD_BUTTON_NONE;
   int flag = 0;
   float tmpSTEPS_PER_REV = (float)globals.stepsPerRev;
   float remainder;
   float divLeftOver = 0.0;
   long adjustSteps = 0;
   
   stepsPerDiv = (long)(tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder = (float) (tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder -= (float)stepsPerDiv;
   divisions = (long)((float) MINUTES_IN_CIRCLE / (float) gAngle);
   printDivideVals(thisDiv,gAngle);
   while(event != LCD_BUTTON_SELECT){
      event = lcd.getButton();
      switch(event){
        case LCD_BUTTON_LEFT:
          flag++;
          thisDiv--;
          divLeftOver -= remainder;
          if(thisDiv < 1)
            thisDiv = divisions;
          digitalWrite( globals.DirPin, ANTICLOCKWISE );
          break;
        case LCD_BUTTON_RIGHT:
          flag++;
          thisDiv++;
          divLeftOver += remainder; 
          if(thisDiv > divisions)
            thisDiv = 1;          
          digitalWrite( globals.DirPin, CLOCKWISE );
          break;       
    }
    if(flag){ 
      if(abs(divLeftOver) >= 1.0){
        adjustSteps = 1;
        if(abs(divLeftOver) == divLeftOver)  
          divLeftOver -= 1.0;    // Positive value >= 1.0
        else
            divLeftOver += 1.0;  // Negative Value <= 1.0
      } else
          adjustSteps = 0;
      setSteps((stepsPerDiv + adjustSteps) * 2, 1);
      printDivideVals(thisDiv,gAngle);
    }   
    flag = 0;
  }
}
```


----------



## Foozer (Jul 3, 2017)

Have operation with my little testing platform  
From: "the program starts running and no button will stop it."
To: "the program starts running and the button will stop it."

Question is: The <Contin> UP/DWN Starts menu choice is one direction only, plus being slow I don't really get the item. You have the Jog function which also has a Cont choice that runs both directions . . .

Next thing to do is to load it to the rotary table gizmo and see how she does . .


----------



## rodw (Jul 3, 2017)

Foozer said:


> Have operation with my little testing platform
> From: "the program starts running and no button will stop it."
> To: "the program starts running and the button will stop it."
> 
> ...



Glad we made progress. We do need it attached to a RT to test for lost steps. Where is Captain_Obvious?

If you have problems, try replacing

```
if(abs(divLeftOver) == divLeftOver)
```
with

```
if(divLeftOver > 0.0)
```

The <Contin> menu allows you to change direction with the left and right arrow buttons. This is consistent with the divide functions (that allow you to go backwards  in case you have another operation (or forgot one). Use carefully as backlash could be a problem.


----------



## Foozer (Jul 3, 2017)

@200 steps per rev and 36:1 table ratio seems to perform repeatable jogs . . . Your program resolution exceeds the accuracy of my little rotary so a missed step be like picking a grain of salt from the sugar shaker. Captain_Obvious is set up for the fine measurements . . . Captain_Obvious ?

<Contin>  Kicked it, now she is working - 

Jog Angle  XX0 - 00 - 00  XX not changing - Left-Right moves cursor, Up-Down no change from zero.


----------



## Captain_Obvious (Jul 4, 2017)

Hi, I've been a bit busy for the past few days, but I tried the new script and the division seems to work perfectly now. I tried divisions 3, 21, 37, 61 and 360. All holes lined up.

I'll do some more testing later and I will write down the results but for now it seems that we have nothing to worry about. Again, thanks a bunch for the effort, rodw!


----------



## rodw (Jul 4, 2017)

Thanks guys, I really appreciate your testing. I will update the zip file at the beginning of this thread and post here when I'm done

Foozer, I suspect your keyboard problem could be due to different resistance values between my Freetronics and your sainsmart keyboards. You may need to tweak the values in the LCD library class to suit your hardware. Thats not my code so you are on your own.....

Also, I've found that the keys on these displays wear out very quickly so it could be a sticking or faulty button. The keyboard code has been tested, is rock solid and has not been touched


----------



## Captain_Obvious (Jul 4, 2017)

I put my lathe dividing head together as it will be from now on and did some (hopefully) final testing. All functions of the script seem to work as intended. No problems with button functionality or anything else. I tried several divisions, 4, 7 ,10, 21, 36, 43, 45 and 61. I had no problems with any of them. I also tried a few angle programs and they worked fine. Jog and continuous running work fine as well.

The setup is basically the same, a cast iron backplate on the lathe spindle with a piece of paper glued to it. Poking holes in the paper with a small carbide needle attached to the tool holder of the lathe. Circle diameter roughly 100mm or so. I saw no division errors looking through a 5x eye loupe.

Since I've been having trouble with this setup from day one, I'm not through testing it yet, but it certainly looks very promising so far. However it seems my main problem in the beginning was a bunch of poor quality stepper drivers that eventually died or started malfunctioning otherwise. Now I have Leadshine drivers and generally higher quality components in the system instead of the cheapest possible Chinese clone crud.


----------



## Foozer (Jul 4, 2017)

rodw said:


> Foozer, I suspect your keyboard problem could be due to different resistance values between my Freetronics and your sainsmart keyboards.



Mayhaps be, it's just that one place config - jog step - jog angle that declines to cooperate on the first two digits. [10's & 100's]. Have a freetronics shield coming so shall see . . Sheets say the resistor values are the same - But have murphys law following me the past week or so, truck tans blew a bearing, brides car blew a cam position sensor, my [cough] hot rod blew the ignition ignitor  - I got the laughter of a mad man in lock up - - Looked at the LCD cpp file, of course, the button differentiation is determined by a map, say what? Guess I could alter it to some
if(analogRead(pin) == value  stuff or just go with a glitch I need not worry about.
Like Obvious have a paper set up waiting for me to poke some holes in.

Hey it's the 4th, what else is there to do but have some fun . .


----------



## Foozer (Jul 4, 2017)

Not the best camera for this, for this, tis terrible . . .
Don't realize how different the setups are until you do change overs. Started with my own script that uses Chucks math engine wrapped with a NES controller for input [CNC Shield controller], then to Chucks directly [button shield, easy driver], then to Rods [button shield, easy driver]. Picked odd number 39 for testing first three tries then 78 for the last . . . Straight edge across the radials lines up. Easy Driver gave up the smoke during last pass, borderline running the stepper @ .7a
All in all, holes started and ended where they should have, appear evenly spaced and the 78 run put one 'tween the others as expected . . .
...
[couple spots in the backing plate had existing holes so piercing looks funny . . ]


----------



## rodw (Jul 5, 2017)

Foozer said:


> Jog Angle  XX0 - 00 - 00  XX not changing - Left-Right moves cursor, Up-Down no change from zero.



Foozer, This old post explains how to modify the LCD code for the sainsmart
http://www.homemodelenginemachinist.com/showpost.php?p=273830&postcount=219


----------



## Foozer (Jul 5, 2017)

rodw said:


> Foozer, This old post explains how to modify the LCD code for the sainsmart
> http://www.homemodelenginemachinist.com/showpost.php?p=273830&postcount=219




Thanks, the lcd.cpp file is perty straighforward,  'cept for the 
// Button mapping table generated by genlookup.c
static unsigned char const buttonMappings[] PROGMEM = {
    2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
    1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0};

Part of me wants to know what that actually means, the other part say's forget it, stick in the verbose coding . . That can be changed to suit variance in resistor values. Up/Down button reads work every place 'cept that for  that one usage. 

Any event if this dunderhead can get your sketch to run, anyone can get it to run . . .


----------



## rodw (Sep 1, 2017)

Foozer said:


> Thanks, the lcd.cpp file is perty straighforward,  'cept for the
> // Button mapping table generated by genlookup.c
> static unsigned char const buttonMappings[] PROGMEM = {
> 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
> ...



Foozer, Sorry I missed this. The original author of the LCD library published his source on github. Chack th esource and you'll probbaly find the URL. From memory, he used a program to generate that code (and the source for the generator was in his repository).


----------



## Foozer (Sep 1, 2017)

rodw said:


> Foozer, Sorry I missed this. The original author of the LCD library published his source on github. Chack th esource and you'll probbaly find the URL. From memory, he used a program to generate that code (and the source for the generator was in his repository).




Thanks, I'll take a look . .

Robert


----------



## rodw (Sep 2, 2017)

Foozer said:


> Thanks, I'll take a look . .
> 
> Robert



This post of mine links to the github source of the LCD library

http://www.homemodelenginemachinist.com/showpost.php?p=261783&postcount=20


----------



## Foozer (Sep 2, 2017)

rodw said:


> This post of mine links to the github source of the LCD library
> 
> http://www.homemodelenginemachinist.com/showpost.php?p=261783&postcount=20



That took me to the genlookup - Oh Boy  >> (bitshift right) stuff to wrap my brain around. Can't be any worse than gcode G2,G3 commands . . .

Robert


----------



## JMe (Sep 15, 2017)

Hi from Belgium,
RodW, i upload your software to an Uno chinese clone, seems to work perfectly but, after 32 seconds (tested 5 times) without touching any key, the characters disappear and i may see just a blue screen ? Touching any key, display is back and all is OK ?

The blind keyboard (4+1) is not very user friendly for this application, to say a minimum.

Anyway, good software job.

Jacques

Please, forgot my comment, very easy to remove this "ScreenSaver" ;-)


----------



## rodw (Sep 16, 2017)

Yes  the LCD library has a screensaver built in. There is a command to disable it so look through the setup code.
I never found it distracting.


----------



## Stieglitz (Oct 16, 2017)

Thanks Rod this looks like something I will need soon.
Cheers
Allen


----------



## fugalguido (Nov 22, 2017)

xpylonracer said:


> Hi Rod
> 
> I Downloaded your Rotary Table 10 program but get an Error message when Verifying sketch, Error:
> 
> ...



Rod,

I get the same thing, I clicked the Rotarytable10.ino . Doesn't load the library BoolField.h Any ideas?


----------



## rodw (Nov 23, 2017)

fugalguido said:


> Rod,
> 
> I get the same thing, I clicked the Rotarytable10.ino . Doesn't load the library BoolField.h Any ideas?



Please read post #4 which explains why you are getting that error. Review the first post again as it tells you what to do. Also, when you get it going, be sure to modify the code as per the later bug fix on GoDivide()


----------



## fugalguido (Nov 23, 2017)

rodw said:


> Please read post #4 which explains why you are getting that error. Review the first post again as it tells you what to do. Also, when you get it going, be sure to modify the code as per the later bug fix on GoDivide()



I did read post#4 previously, which why I knew that it didn't load the library. I had to manually load the library into the java folder. On previous Arduino programs that I have used it loaded the libraries automatically. Your program did load the Eprom library  automatically, so I am confused why it didn't load the rest of the libraries.  Now when I verify the code I get;

Users/montemeredith/Downloads/RotaryTable10/RotaryTable10/RotaryTable10.ino: In function 'void goDeviceMenu()':
/Users/montemeredith/Downloads/RotaryTable10/RotaryTable10/RotaryTable10.ino:955:31: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
           addDevice("NEW Dev?");
                               ^
/Users/montemeredith/Downloads/RotaryTable10/RotaryTable10/RotaryTable10.ino:962:33: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
           loadDevice("LOAD Dev?");
                                 ^
/Users/montemeredith/Downloads/RotaryTable10/RotaryTable10/RotaryTable10.ino:969:35: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
           eraseEeprom("ERASE All?");


Sketch uses 28946 bytes (11%) of program storage space. Maximum is 253952 bytes.
Global variables use 906 bytes (11%) of dynamic memory, leaving 7286 bytes for local variables. Maximum is 8192 bytes.

Is this still a problem?

On the GoDivide bug where is it described? And why wasn't in the revision 10 update or did it appear after that was released?


----------



## rodw (Nov 23, 2017)

The Eeprom library is probably a standard Arduino library so a version was probably already installed.
The other libraries are unknown to the Arduino environment so they had to be unzipped into a folder as per the first post. 
I have not provided a library but a complete working environment including some libraries so the autoinstall cannot work.
Something has changed in the current Arduino development environment and  some compiler warnings are now generated. 
The warnings should not be a problem on a UNO but I note from your last post from the available memory that you are using a much larger capacity Arduino so I guess it is also a 32 bit board. If this is the case, the warning could bite you. Say an internal pointer is a 16 bit long on a UNO and now it is 32 bits long, the current code could generate an invalid memory address. This new support for 32 bit processors could be the reason why the Arduino developers chose to tighten up the compiler warnings (eg what as once valid could be a problem today so they issue a warning)
The hardware requirements are listed on post #1 of this thread. Use different hardware and there are no guarantees this will work correctly. 
The bux fix is listed on post #25 of this thread


----------



## cd_edwards (Nov 26, 2017)

I wish to thank you for this. I had been looking at creating something like this for my milling machine X axis.. Now I don't. 
I've got it to compile and was surprised it actually compiled on a Arduino Pro board. 16mhz, using 98% of memory. I will however end up using possibly my Tau 32bit board instead. Got this from a kickstarter and it should be plenty fast enough to run this.


----------



## rodw (Nov 26, 2017)

cd_edwards said:


> I wish to thank you for this. I had been looking at creating something like this for my milling machine X axis.. Now I don't.
> I've got it to compile and was surprised it actually compiled on a Arduino Pro board. 16mhz, using 98% of memory. I will however end up using possibly my Tau 32bit board instead. Got this from a kickstarter and it should be plenty fast enough to run this.



Thanks for the feedback. I'm glad its working for you. If you were going to build it into a dedicated hardware box,  I would not waste a 32 bit CPU on it. Please give me your feedback on your linear application as I have not seen anybody use it that way.


----------



## Mumford (Jun 23, 2018)

Hello,

  I am new to the site so please excuse my noobness. First off, thank you for posting the code and making this project available to all. I am having an issue with getting the DIV to work correctly. When I select the number of divisions and press direction, the motor makes twelve full revolutions and stops. I am able to run CONT by holding the direction button down which stops when I release the button. I feel like I am close, but I must have a setting wrong somewhere. I am using a NEMA 34 motor with Arduino UNO with a SainSmart LCD shield, SainSmart Micro Stepper Driver with Pulse per rev is set at 5000 (I have tried all settings, and this seemed to sound the best) and I have tried all amp settings from 1 to 4.5 without any noticeable differences. I tried to change the settings on the LCD in setup to reflect the pins I used on the Arduino (2 and 3) where the DIR will change to 3, but the Steps revert back to 1 even when I change it and choose Save =Yes.  Thank you for any help you can offer.


----------



## Scott_M (Jun 23, 2018)

Hi Mumford
I used the Sainsmart shield as well. Here is what I did.  This was quoted from another post here https://www.homemodelenginemachinist.com/threads/heavy-duty-arduino-dividing-head-project-finished-.24719/



Scott_M said:


> OK, found it ( took awhile )
> 
> Find where you keep your libraries and open the LCD folder, in it open the file LCD.cpp in notepad. Change the backlight pin from 3 to 10, save and close. That should be all you need to get the Sainsmart working with the Freetronics library.
> See photo
> ...


----------



## rodw (Jun 23, 2018)

If you really get stuck with pin assignments, there are some equates in the top of the main code. I've got a feeling you'd need to overwrite the first few bytes  of the flash memory from a different sketch or it will keep reading values from there. Look in the Arduino docs for an example of writing to flash memory. (We put a signature in the first few bytes to ensure it contains valid data so it needs to be wiped out to reinitialise). Or just accept the default pin values.

The amp settings on your controller are determined by your stepper motor. If your amps are less than the motor rating, it will loose torque but still function.. So keep it as high as your stepper allows.


----------



## Mumford (Jun 23, 2018)

Thank you Scott_M and RodW for your help. Unfortunately, I am unable to overwrite the original sketch with any other programs or changes. I just get error messages like avrdude: verification error; content mismatch and problem uploading to board programmer is not responding. I will need to figure this new problem out before I can try any new fixes. Thank you again.


----------



## Shehan Perera (Jul 27, 2018)

#rodw

Can you please give us the wiring diagram.


----------



## Shehan Perera (Jul 27, 2018)

Captain_Obvious said:


> Hi, I've been a bit busy for the past few days, but I tried the new script and the division seems to work perfectly now. I tried divisions 3, 21, 37, 61 and 360. All holes lined up.
> 
> I'll do some more testing later and I will write down the results but for now it seems that we have


----------



## Stieglitz (Jul 27, 2018)

Hi Rod,Thanks so much.


----------



## rodw (Jul 27, 2018)

Shehan Perera said:


> #rodw
> 
> Can you please give us the wiring diagram.



I don't appreciate multiple requests via PM and on multiple threads. Your PM was devoid of manners. There is only 4 wires required to drive a stepper motor driver from an Arduino, 2 of them are +5v and -5v. If you can't work it out, you should not be attempting this project.


----------



## Captain_Obvious (Jul 27, 2018)

Shehan Perera said:


> Canyo
> 
> 
> Code pls



The code is already posted on this thread and it is not written by me.


----------



## Shehan Perera (Jul 27, 2018)

Thank you rodw and captain_obvious 

Great work


----------



## Shehan Perera (Jul 27, 2018)

Mumford said:


> Hello,
> 
> I am new to the site so please excuse my noobness. First off, thank you for posting the code and making this project available to all. I am having an issue with getting the DIV to work correctly. When I select the number of divisions and press direction, the motor makes twelve full revolutions and stops. I am able to run CONT by holding the direction button down which stops when I release the button. I feel like I am close, but I must have a setting wrong somewhere. I am using a NEMA 34 motor with Arduino UNO with a SainSmart LCD shield, SainSmart Micro Stepper Driver with Pulse per rev is set at 5000 (I have tried all settings, and this seemed to sound the best) and I have tried all amp settings from 1 to 4.5 without any noticeable differences. I tried to change the settings on the LCD in setup to reflect the pins I used on the Arduino (2 and 3) where the DIR will change to 3, but the Steps revert back to 1 even when I change it and choose Save =Yes.  Thank you for any help you can offer.


----------



## ignator (Jul 27, 2018)

Shehan Perera said:


> Can you tell me about pin connections.
> I am new to this field


Shehan, just like learning to use a lathe or mill, you take 'baby step' with Arduino. Look for a tutorial on using the UNO with the LCD display and keyboard. This will initiate your understanding of the wire connections between the UNO and any of the many devices that can be connected. Have you done the very first Arduino sketch that blinks a LED on the UNO board? Some copies (of the UNO) do not have that LED installed. The next sketch is the same, but with an external LED and resistor. This is a needed 'stepping stone' to understand what Arduino is about and the coding that the IDE (Integrated Development Environment) provides to enable non computer science, electrical engineers the ability to use microcontrollers.


----------



## Anatol (Jul 27, 2018)

Hi All,
Rod - congratulations on a great project. I'm not making it currently, but I have decades of experience in mechatronics. 
I see many this thread are baffled or asking questions which reflect a lack of experience, and responders are reacting with patience (mostly) and cannot be blamed if readers don't read all the posts or follow instructions. As noted, electronics is not simple, even though those who stayed to profit from selling you stuff try to tell you it is.  So I'd like to offer a couple of suggestions to electronics 'newbies'.

 In Rod's OP he said - " Power supply (minimum 24 volt in my experience, around 80% of what you stepper driver is rated for - I use a 48 volt power supply)." I would always provide a motor - or any inductive load - with the rated voltage. As voltage drops, current increases, and this results in heat - bad for coils. Make sure the power supply can provide double the rated max current demand of  the motor (pay attention to 'peak' ratings).  If the motor stalls (in some way that does not trigger an emergency shutdown), you will release the 'magic smoke' from the power supply.  And don't forget your flyback diodes!

Breadboards (or protoboards, as in the pics) can be great for prototyping, but are prone to bent contacts inside and so can be a source of frustrating intermittent faults. Don't jam big wires in, and don't carry them around unprotected. I would transfer all circuitry to a soldered perfboard as soon as the circuit is tested and working. Knowing how to make a reliable solder joint is fundamental. Sheilds, (blank boards that plug into the sockets of the Arduino) are a great way to avoid extra straggly wires. And on the subject of wires - only use solid wire for on-board connections. Use stranded wire for wires that will move/bend/vibrate - or your project will not last. If you get really ambitious, you can use a CAD program to lay out a PCB (printed circuit board) - but don't do this before you'r absolutely sure of your circuit. 

More generally, an Arduino is a microcontroller, it deals in digital data (ones and zeros or ons and offs), which is a specialised form of electronics in which most of the information in the signal is thrown away. Newbies to electronics imagine voltage is the only number that matter. This is an oversimplification. Current flow seems a much more obscure concept for people to grasp. But it is fundamental.

Analog signal electronics and power electronics are very different realms from the digital. An analog circuit does not transfer data, it sings. I mean this in all seriousness - in analog electronics there is no input and output or on and off, there are resonances which are perturbed. Most of the stuff hanging on the outside of Arduino is like this to some extent.

For those in USA, I suggest Allelectronics, an electronics surplus house with good prices. I think they're currently offering UNOs for a few bucks. I've bought from them for years.


----------



## Anatol (Jul 27, 2018)

and another thing ! 
Very important

while your Arduino is connected to both the stepper controller and its power supply, and also your computer, you have two power supplies. You MUST MUST MUST make sure all the ground lines in your circuit - power and signal - are tied together, or you may FRY parts of your computer. UNLESS your power circuit is totally electrically isolated from the signal/data side via optoisolators (or electromechanical relays).

The theoretical reason for this is as follows: Voltage is potential DIFFERENCE wrt an arbitrary refernence, which is what 'ground' is. DC circuits are closed worlds. When signal wires between two circuits with separate grounds are connected, havoc can ensue. 

Think of it this way - each circuit is a bubble with its own atmospheric pressure, say one is at 1 atmosphere and the other is at 10. When two bubbles join, there will be a huge flow from the higher pressure to the  lower pressure bubble.

At some point you will disconnect your Arduino from your computer, at which point you will require a smoothed 5v external power supply  (or 7-10 v supply, depending on the input you choose), in addition to your stepper motor power supply.


----------



## Shehan Perera (Aug 6, 2018)

rodw said:


> You can read the thread where this is documented form go to woe during the development here:
> http://www.homemodelenginemachinist.com/showthread.php?p=273830#post273830
> if you need more help but this thread is designed to provide a simple easy to install solution of version 10 of my Rotary Table controller.
> 
> ...



Uploaded code.
But buttons not working?
Used generic LCD key pad shield


----------



## rodw (Sep 1, 2018)

Sorry, its been quite a while since I've been on this forum and missed the last couple of  posts. Anatol, thank you very much for your compliment and additional descriptions.

For others like Shehan Perra, I don't know how many times I have said that the Arduino is not Plug and Play, The required hardware is listed. If you choose to use some other hardware, then you are on your own. Don't ask me for help.

If you don't know how to modify the code (and the answer is on this forum), then buy the required hardware or find another simpler script. This script uses advanced high performance code that works. Its well written and documented in the source. Its not really a beginner Arduino project as it pushes the limits of the Arduino.


----------



## haiduongoy (Sep 9, 2018)

thank to you


----------



## stragenmitsuko (Sep 12, 2018)

I printed the first post in this thread , and followed the instructions to the letter .
It all works like a charm and I had it going in abt 10 minutes .
That includes installing the IDE and arduino clone driver .

BIG thumbs up for RodW .

Do I need to cut n paste the bug fix in the code , or has the rotary10.zip file been updated and can it be used as is ?

Pat


----------



## stragenmitsuko (Sep 12, 2018)

I think my previous post was a bit to optimistic . 

I have what looks to be a sainsmart clone lcd shield . 




I tried it with a "button test " sketch , and they all work as intended . 
Left returns a left , select returns a select etc . 

But with the rotary table sketch , the "left" button is not functional , and the "select" button seems to act as a left .  It's a hardware/software incompatible  issue I'm sure . 

And I know I'm on my own  . 
I'll try to figure it out and report back if I can find it . 
I'll probably start by checking resistor values . 

Anyone else had this behaviour ... feel free to give me hint . 
I did modify the backlight pins as suggested , and that makes the backlight turn off when the screensaver kicks in . 
But offcourse , it doen nothing to the button problem . 

I wouldn't mind buying the freetronics display shield  , but the shipping cost is outrageous .
It cost more for shipping it then the actual price . 

Pat


----------



## Scott_M (Sep 12, 2018)

Hi Pat
do you mean you changed the backlight pin assignment from 3 to 10 as explained here ? 
That was all I needed to do to get the Sainsmart shield to work. I also tried a DFRobot shield and could not get it to work. It was awhile ago but I think I remember googleing the difference between the two and think it is fixable. I think.
The Sainsmarts do work.

Scott


----------



## stragenmitsuko (Sep 12, 2018)

Yes , the backlight pin from 3 to 10 does what it should . 

As for the shield itself , looking at the schematics , both sainsmart and freetronics 
use thesame resistor values for the buttons . 2K ; 330E ; 620E ; 1K ; and 3K3 . 
But the dfRobot uses a 2K2 resistor instead of a 2K . That is the cause of the problem . 
For now I soldered a 22K in parallel to the 2K2 , wich results in a value of 2K . 

That makes my "left" and "select" buttons operational . 
Most lilely it's all it takes . 
I'm sure it can also be solved in software , but I'm not good with software . 

Trying to figure out the menu structure now , and wich button does what . 

I'll post a picture and "schematic"  when I'm sure it works . 

Pat


----------



## Scott_M (Sep 12, 2018)

Sounds like you have a handle on it. Good luck and have fun.

Scott


----------



## stragenmitsuko (Sep 18, 2018)

As promised I report back here with my findings .
I had to make a small modification to the df Robot shield to make it freetronics/sainsmart compatible .

Basicly what happend is that the designers of the freetronics display shield used a non common resistor .
2K  . No that uncommon , but the std value is 2K2 .




The df robot shield designers decided  probably to save a few pennies and used a std 2K2 resistor instead .
Remember ,  this is a 3$ shield , s&h included . I'll never understand how they are able to build it
at that price .
No problem really , it still works , and various test sketches read the buttons correctly .
However the different resistor throws the two lower voltages  off just enough for Rod's sketch not to recognise them .
I fixed it by adding a 22K resistor in parallel to the 2K2 resistor wich results in a 2K value .
This makes all the buttons function as they should .
The resistors are hidden inder the lcd , you can't see them in t he picture .
Just above the RST button , you can see the 22K I added .


This also can be solved in software . At least it should be .
I can calculate the voltages for each button , and even the expected ADC counts both with a 2K or with a 2K2 resistor .
And then it should be just a couple of numers somewhere  need to be changed .

I think it's the piece of code copied below that reads and maps the buttons .
Copied it from the lcd.cpp wich is in the library .
But I just can't understand how it works . Maybe someone who does could explain it to me .

It's academic , I'll most likely build a custom display shield with a much larger lcd , and offcourse I'll use the correct
resistors there . But still , I like to learn things and understand what I'm doing .


Pat



// Button mapping table generated by genlookup.c
static unsigned char const buttonMappings[] PROGMEM = {
    2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
    1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
};
#define mapButton(value) (pgm_read_byte(&(buttonMappings[(value) >> 5])))

/**
 * \brief Gets the next button press, release, or idle event.
 *
 * If no buttons are pressed, this function will return LCD_BUTTON_NONE.
 *
 * When a button is pressed, this function will return one of
 * LCD_BUTTON_LEFT, LCD_BUTTON_RIGHT, LCD_BUTTON_UP, LCD_BUTTON_DOWN,
 * or LCD_BUTTON_SELECT.  While the button is pressed, this function
 * will return LCD_BUTTON_NONE until the button is released.  When the
 * button is released, this function will return one of
 * LCD_BUTTON_LEFT_RELEASED, LCD_BUTTON_RIGHT_RELEASED,
 * LCD_BUTTON_UP_RELEAED, LCD_BUTTON_DOWN_RELEASED,
 * or LCD_BUTTON_SELECT_RELEASED.


----------



## TorontoBuilder (Jan 14, 2019)

rodw said:


> Sorry, its been quite a while since I've been on this forum and missed the last couple of  posts. Anatol, thank you very much for your compliment and additional descriptions.
> 
> For others like Shehan Perra, I don't know how many times I have said that the Arduino is not Plug and Play, The required hardware is listed. If you choose to use some other hardware, then you are on your own. Don't ask me for help.
> 
> If you don't know how to modify the code (and the answer is on this forum), then buy the required hardware or find another simpler script. This script uses advanced high performance code that works. Its well written and documented in the source. Its not really a beginner Arduino project as it pushes the limits of the Arduino.



I've been away from this forum for years what with life and all. I came back because I recalled this project and wanted to move from a simple stepping collet chuck to a rotary table design. 

Great work Rod making this available to people. I sure appreciate your efforts.


----------



## rodw (Jan 14, 2019)

Welcome back John. I must say I'm  a bit the same. I've migrated to Linuxcnc


----------



## TorontoBuilder (Jan 14, 2019)

rodw said:


> Welcome back John. I must say I'm  a bit the same. I've migrated to Linuxcnc


Nice, one of my bucketlist items is to build a cnc router and I did download and play with cnc software, but the laptop I had it on went kaput. 

Am I correct to suppose that linuxcnc can be used to control single axis items like rotary table, or even just to control travel on a table that has a stepper motor attached?


----------



## rodw (Jan 14, 2019)

Yes, I'm going to use language based on the latest development branch of Linuxcnc as its changed a bit from the current release. Linuxcnc can support up to 9 joints (or motors) and these are mapped to axes. It is possible to map 2 or more joints to the one axis so they work in unison (as per a gantry on your router) and the homing sequence will square the gantry. It is possible to control a one axis machine without resorting to go code. Today, I've just installed a version of Linuxcnc on my windows machine using Virtualbox. This won't work to drive a real machine but it does allw you to run all of the supplied  simulations which are useful for development


----------



## jaws0535 (Jan 21, 2019)

I ran it. working fine. however, the jog mode does not return a different direction. There is a nuisance in the code.

Can you review it and publish it. I thank you.


----------



## rodw (Jan 21, 2019)

jaws0535 said:


> I ran it. working fine. however, the jog mode does not return a different direction. There is a nuisance in the code.
> 
> Can you review it and publish it. I thank you.



Please read the hardware dependencies in the first post.  Your keyboard hardware is different to what I used and the Arduino environment is not plug and play. Others have worked around the problem.


----------



## jaws0535 (Jan 21, 2019)

I'm sorry the error is caused by me. Careless. works perfectly.


----------



## rodw (Jan 21, 2019)

jaws0535 said:


> I'm sorry the error is caused by me. Careless. works perfectly.



Great, thanks for letting us know


----------



## curtistdc (Mar 26, 2019)

Rod,
My name is Scott and I have been following this post for quite a while. Thank you for all of the time and effort you have put into this project.  I have finally collected all of the parts I need to make this work for my application.  I plan on using a Hass 5c collet stepper indexing head for use on my cnc mill.  I have got the Hass head to index like it should and it works great.  I now just need to figure out how to interface it to my cnc mill.  It is a VMC with a fanuc control.  I plan on doing the same thing as Scott did by using a remote switch to index the head.  I have some available M codes I can use on my machine to call for the arduino to make the step move.  The problem I have is that when I request an m40 code in the g code The cnc will activate a relay which will simulate a right button push.  That m40 relay then stays active until the cnc gets a signal to de activate m40.  The machine will not progress with nc code until this condition is met.  I have looked though your code and I have not found what looks like a finish movement signal.  If I can capture that signal and activate a relay to end m40 that will let the nc code continue.  I would appreciate if you could point me in the right direction and maybe give me a little help with the code part of it.  I am not super savvy on the arduino side of things.  It could be as simple as a potentiometer going to an analog input that changes the length of time before the arduino activates a pulse to de activate the M40 code.  I think that you would want to use interrupts to time this so that the processor is not counting and waiting for that time period. I would appreciate any help you can give me
Thanks
Scott


----------



## Captain_Obvious (Mar 27, 2019)

curtistdc said:


> Rod,
> My name is Scott and I have been following this post for quite a while. Thank you for all of the time and effort you have put into this project.  I have finally collected all of the parts I need to make this work for my application.  I plan on using a Hass 5c collet stepper indexing head for use on my cnc mill.  I have got the Hass head to index like it should and it works great.  I now just need to figure out how to interface it to my cnc mill.  It is a VMC with a fanuc control.  I plan on doing the same thing as Scott did by using a remote switch to index the head.  I have some available M codes I can use on my machine to call for the arduino to make the step move.  The problem I have is that when I request an m40 code in the g code The cnc will activate a relay which will simulate a right button push.  That m40 relay then stays active until the cnc gets a signal to de activate m40.  The machine will not progress with nc code until this condition is met.  I have looked though your code and I have not found what looks like a finish movement signal.  If I can capture that signal and activate a relay to end m40 that will let the nc code continue.  I would appreciate if you could point me in the right direction and maybe give me a little help with the code part of it.  I am not super savvy on the arduino side of things.  It could be as simple as a potentiometer going to an analog input that changes the length of time before the arduino activates a pulse to de activate the M40 code.  I think that you would want to use interrupts to time this so that the processor is not counting and waiting for that time period. I would appreciate any help you can give me
> Thanks
> Scott



Now I'm by no means any kind of an Arduino expert, but would it not be possible to just make a digital pin go high when the code is not active, AKA signal is not being sent to the stepper motor?


----------



## curtistdc (Mar 27, 2019)

Yes that is what I am looking for but, as I am picking through the code I am having a hard time thinking how I an going to do it.   Something along the lines of if stepper not true then bring pin whatever high for a pulse to deactivate the M40 code.  I am going to dive back in and see if I can figure something out.
Thanks


----------



## Scott_M (Mar 27, 2019)

Hi Scott
Scott here, can't you address it in the code ? I am not that savvy with custom macros but can't you call the m40 conditionally ? Like for 5-6 seconds ( long enough to make your rotary move ) and then have it return from M40. Or is there another M code that will cancel it. Like we cancel a canned cycle or cutter comp ?

Scott


----------



## curtistdc (Mar 27, 2019)

I had not thought about a macro. My machine has macro a and I have not tried to write a macro before but that is a thought.  There is not another m code to cancel m40, it waits for a 24 volt signal to trigger a change in the ladder to cancel it.  There may be a way to do it with a macro but I need to do a little research and see. From my limited understanding of macros you can use variables programed into the diagnostic parameters which could be used for a time limit.  I will look at my fanuc manual and see what I can find out about that. 

Have you had good lock with the setup you did with the proximity switch?
Thanks
Scott


----------



## Scott_M (Mar 27, 2019)

Hi Scott
Actually we had to bail on the prox switch. It developed a serious debounce issue that I could not resolve. I went to a mechanical N.O. switch and piggybacked it to the shield switch.
It has been rock solid since. It really brought some new possibilities to a "vintage" machine.

Scott


----------



## curtistdc (Mar 27, 2019)

Did you try to tie it into the A0 pin directly with the same value resistor?  I am only asking because I am in the process of mounting five buttons on the face of the machines control enclosure and I tried simulating the five switches on the shield with a resistor array matched to the resistors on the shield.  I had problems because I was getting feedback from the resistors on the shield and the voltage values were not correct when both were wired into the A0 pin.  My next step is going to break the connection to the A0 pin from the shield.  I plan on mounting the arduino and display inside the Machines control with just the lcd showing though so there wont be a need for the shield buttons anyways.

as for the macro idea I did some reading in the fanuc manual and you  can change some internal registers on the cnc control with a macro but I think that the one for the m40 code may not be one of them.   I posted a question about this type of thing elsewhere maybe the fanuc gurus can shed some light on the problem.


----------



## Scott_M (Mar 28, 2019)

Hi Scott
I was using a digital pin for the prox. I had tried it with and without pull-up resistor - internal and external. Would get random triggers.


Scott


----------



## Captain_Obvious (Mar 28, 2019)

Did you try a small value capacitor from the signal pin to ground? I had a random trigger issue with an Arduino based device. It would trigger every time a fluorescent lamp turned on of off nearby. A small capacitor solved the issue. It was a genuine Arduino Nano.


----------



## Scott_M (Mar 28, 2019)

No I did not.
But it has been working well now with the mechanical switch so I doubt I will try it.


----------



## curtistdc (Mar 29, 2019)

I think I have a solution for this application.  I used a digital write command within the go divide section to send pin 10 high momentarily to cancel the m40 command from the cnc.  I tried to use the millis compare system but kept getting errors from the compiler in a strange section of the code and I could not figure out why.  So I went against what I believe to be the correct method and used a delay command in between pin 10 high and pin 10 low with a 100 ms pulse.  I know this stops the processor from working during the delay but bench testing showed no sign of problems.  Everything seemed to work properly.    The next step is to hook everything to the cnc machine and se how it works. 

I  would ultimately like to write a macro for the machine so that I can input the number of divisions into a macro variable and the nc code will index until it reaches the desired number of divisions.  Need to do some macro studying.
Scott


----------



## rodw (Apr 25, 2019)

Curtis, sorry I totally missed all of the activity on this thread about your idea to use a Fanuc Macro. I'm not 100% sure from your description about what you need to do to tell Fanuc to reset the output relay. On thing you could consider doing is use a a hardware interrupt that sensed the relay turning on (RISING). 
https://circuitdigest.com/microcontroller-projects/arduino-interrupt-tutorial-with-examples
Let that interrupt set a global variable (FanucM40) that godivide() could monitor. Let godivide save that variable in a static variable (last_FanucM40) so it knows if its changed since the last time through the while loop

Very roughly  a bit like this maybe...

```
static int volatile FanucM40;
// in godivide()
  int FanucM40_changed;
   while(event != LCD_BUTTON_SELECT){
      event = lcd.getButton();
     if(FanucM40 && !last_FanucM40){ // M40 set
          event = LCD_BUTTON_RIGHT;
          FanucM40_changed = 1;
     }
      switch(event){
        case LCD_BUTTON_LEFT:
          thisDiv--;
          if(thisDiv < 1)
            thisDiv = divisions;     
          digitalWrite( globals.DirPin, ANTICLOCKWISE );
          setSteps(stepsPerDiv * 2, 1);
          printDivideVals(thisDiv,gAngle);
          break;
        case LCD_BUTTON_RIGHT:
          thisDiv++;
          if(thisDiv > divisions)
            thisDiv = 1;     
          digitalWrite( globals.DirPin, CLOCKWISE );
          setSteps(stepsPerDiv * 2,1);
          printDivideVals(thisDiv, gAngle);
          break;

      }
   last_FanucM40 = FanucM40;
   if FanucM40_changed{  /we've processed this button press so safe to reset M40
       //Reset M40 signal
       FanucM40_changed = 0;
   }
}
```


----------



## rodw (Apr 25, 2019)

And you could extend this by adding a toggle switch that put 5 volts from the Arduino to a digital input so you could decide if you wanted to move left or right in godivide on a M40. Mounted horizontally, this switch would be quite intuitive.


----------



## rodw (May 5, 2019)

Well, finally here is an upgrade. In the Zip file, there are 3 files:

RotaryTable11.ino - The latest version with the bug fix for correct stepping interpolation discussed earlier
LCD.h - Replaces the file in the LCD library folder.
LCD.cpp  - Replaces the file in the LCD library folder
The changes 2 & 3 are to support a greater range of LCD/keyboard shields
In LCD.h  uncomment the#definef you have a DFROBOT compatible shield

```
// if a DFROBOT display (with 2.2k ohm resistor on input buttons) uncomment the line below
//#define DFROBOT
```

This will use the correct key map and also the correct pin for the backlight via some conditional code in LCD.cpp


See this URL for details on the DFRobot: https://wiki.dfrobot.com/Arduino_LCD_KeyPad_Shield__SKU__DFR0009_
Chances are that if you have a keyboard that does not work with the rotary table controller, this will fix it.

For the curious, I ran a simple sketch that printed the keyboard values to the serial monitor, downloaded the genlookup.c from the original repository https://github.com/rweather/arduino-projects
edited it and compiled it using gcc on a linux box

```
gcc -o genlookup genlookup.c
```
and changed the permissions of the binary file genlookup to: read/write/*execute*
Then I piped the ouptut to a text file to insert into LCD.cpp and it worked!

```
genlookup > genlookup.txt
```

Let us know if this works for you. Sorry but the forum does not allow me to update the first post.

A friend looks like he's talking me into adding a rotary encoder support for easier data entry so you never know, this might improve with age. If I've got a spare interrupt left after adding the encoder, I may add support for an external relay that can be triggered on a CNC machine with a  M40 command from gcode.


----------



## stragenmitsuko (May 5, 2019)

Glad to see this beautifull project is still evolving and improving . 

Pat


----------



## rodw (May 5, 2019)

Pat, thanks for the encouragement. I hope the new LCD shield support makes it more valuable for people on the other side of the world. Any feedback will be appreciated.


----------



## rodw (May 5, 2019)

Hmm, that was easy. It looks like external relays are now supported. I won't share it yet as I have not tested it with real hardware unless somebody really wants to try it but a hardware interrupt on pin 2 fires if it receives a 5 volt signal and after indexing is completed, pin 13 is briefly enabled (currently for 0.3 seconds) signifying the indexing move has been completed. To implement this you'd need two relays (optoisolated preferred). One relay would be triggered on the external device and it would switch 5 volts from the Arduino power supply to pin 2.

Another relay would be attached to the Arduino PIN13 and Arduino GND. It would switch field power on the external device to an input signifying the machine could continue. Apparently some machjines (eg with Fanuc controls) are provided with macro relays that can be triggered with something like an M40  in gcode.

You could also do this from LinuxCNC/Tormach PathPilot out of the box with a M64/M65 followed by a M66 wait on input something like

```
M62 P0  (turn on digital output 0)
G4 P0.1  (pause to catchup to avoid breaking blending)
M66 P1 L1 Q10  (wait for 10 seconds for digital output 1 to go true at end of indexing)
M63 P0 (turn off digital output 0)
```

Of course you'd need to add a bit of error handling. The Linuxcnc docs say "If the timeout is exceeded, the wait is interrupted, and the variable #5399 will be holding the value -1."

I wonder where Scott is....


----------



## stragenmitsuko (Jul 20, 2019)

Rod , has this software ever been tested on a nano ?
I've been experimenting with a nano , and a custom made display/button shield with a larger display and better quality switches .

It all works at first sight , but  when entering setup to assign the step and dir pins etc when I save the entire
systems locks up . Even the reset does nothing . All I can do is pull the power to reset the device .
And offcourse the parameters arent saved .

I tried to modify the parameters in the skecth before compiling , and upload that .
Didn't work on the nano I was using , kept going back to the stored parameters .

I then tried a brand new nano , and uploaded the modified sketch , and this time the parameters
are correct . But I have thesame behaviour as before , can't modify them .

Seems to be some kind of eeprom issue ?  Looks like it can't or won't erase


On my  uno , the one with the modified df robot shield ,  it all works fine .
The save of the setup returns to the startup screen and  the processor continues working .

Strange because the nano uses thesame 328p processor .


Edit , uploaded a couple of pictures to show what I'm trying to do .

The original shield is there to compare size. Arrowed switches are also illuminated , but the camera doesn't seem to like blue leds . 







Little pcb bolted to the display holds the various parts for contrast and display backlight .
I added an 7805 so the nano doesn't have to supply the current for all the leds and the backlight .


----------



## rodw (Jul 20, 2019)

I have never tried the nano.
I think there are probably 2 issues here. Re not saving the data, there is a signature written to the first 3 bytes of the EEPROM to tell it it has valid data. So this signature need to be erased by another script or changed.
Incrementing the  signature in the #defines will force an overwrite. I only changed this number if the globals structure was altered

```
#define CONFIG_VERSION       "RT4"        // The Signature to tell us we've saved stuff in the EEPROM
#define NO_DEVICE_SIG        "XXX"        // The Signature to tell us we've got nothing in the EEPROM
```

This script pushes the global memory to its limit and I had to shorten text displayed to make it fit.
If the nano has less global memory or less efficient initialisation code that reduces the amount of available code space, you will get memory overruns and unpredictable behaviour. This is the most likely explanation for hanging. 
Ideally all the menu strings should be PROGMEM variables to reduce the consumption of global memory but this requires modification to the third party menu library I used. I did not have much luck changing it.


----------



## stragenmitsuko (Jul 22, 2019)

At first sight i'de say its a bootloader issue . 
My uno and my nano's both hve thesame meg328P chip . 
So that can't be the problem . 
So I tried uploading the software , but this time I used Nano(old bootloader)  in the arduino gui . 
When saving the setup parameters , the arduino stilll  locks up   but the parameters seem to be saved as they should .
I'll do some further testing and keep you posted .


----------



## MarkHar123 (Aug 3, 2019)

I have been using the program from rodw for a couple of years now. I'm working on a back gauge for my leaf brake and now I need the Linear portion of this program. From the very beginning I have not been able to change any of the parameters in the program from using the LCD  keypad (SainSmart) on the Arduino UNO. All changes I have made were to the Arduino program sketch. So, today I upgraded my Sketch to the new Version 11 from rodw including the library changes and now my SainSmart display will not allow the buttons to work correctly. The 'right' button is the only one that will work.  If I plug in a Osepp LCD keypad, that one works. Can you help with these 2 problems please?


----------



## rodw (Aug 3, 2019)

Did you uncomment the definition in LCD.h as per my instructions in Post#93? As far as I know the Sainsmart is identical to the DFRobot in relation to resistor values used.
You should be able to create a new device in settings and define a linear device and swap between your brake and your rotary table.

The menu options are there, take the time to fully explore each menu option. There is no need to change #defines in the code.


----------



## MarkHar123 (Aug 3, 2019)

Yes. I uncommented #definef and it made no difference.


----------



## rodw (Aug 3, 2019)

Could try these LCD files instead of the ones provided earlier?
DFROBOT is enabled
It looks like I did not finish off the code so LCD.cpp was not selecting code based on the #define you uncommented and always used DFROBOT settings. Sounds like that is wrong for your screen..
Tested on a DFRobot. If this does not work, comment the #define out again and try again
If it still does not work, you need to compare your resistor values against the ones here
https://www.dfrobot.com/product-51.html

Once you have a keyboard working., 
left arrow to <config> 
press down arrow
To create a new device, from <config> left arrow to <Devices> press down arrow and  add a new device (up arrow to yes and select). 
Devices are numbered from Zero
Left arrow to get to <Setup> down Arrow to select.
Find DevTyp option in this menu and set to  Linear and select.
Then configure your device and save it.

If you get stuck, bump the CONFIG_VERSION up by 1. This will force the script to erase the EEPROM on the next startup but it can be erased from the device menu. We usuualy only need to do this if the globals structure changes.


----------



## MarkHar123 (Aug 4, 2019)

I think I'll take a break from this for awhile. I've spent hours trying to get this to work. I went back to version 10 of your software and installed the old Libraries to get the Rotary part working again. Has anybody used the Linear feature before?


----------



## MarkHar123 (Aug 7, 2019)

I am able to get into the setup parameters but can not change some of them for the Linear function. When I do get into the Setup parameters there are no numbers there for Dis/Rv, T/Rat and JgMM. I can cursor left and right but clicking Up and Down does nothing. Adds no numbers. Am I still doing something wrong here?


----------



## stragenmitsuko (Aug 13, 2019)

A bit of feedback : 

RotaryTable11.zip  downloaded from post#93 compiles and uploads as it should . 
I have made my dfrobot board  sainsmart/freetronics compatible by modifying the hardware  and all works as expected . 
The backlight pin is still dfrobot , and as expected does not work with the freetronics settings . 
Did not try the dfrobot settings as I no longer have a real dfrobot board . 

Then I downloaded the LCD11.zip and commented the define dfrobot . 
That gives me a compile error . Somthing like { expected . 
Did not persue this  . 

To my knowledge sainsmart and freetronics use thesame resistor values , but sainsmart has a different backlight pin . 
Dfrobot has a 2K2 resistor instead of the 2K and thesame backlight pin as the sainsmart does . 


That aside , I mentioned a nano problem when writing to eeprom . 
I noticed when compiling and uploading the sketch : 
Uno : 28478 bytes ( 88%) of memory 
Nano : 28478 bytes (92%) of memory  . 
Altough they both use thesame processor , something is different . 
I also have to set my nano to "old bootloader" otherwise it will not upload . 
But it does work . 


Pat


----------



## rodw (Aug 13, 2019)

Ooops on line 353 of LCD.cpp, I should have deleted one more comment. 
It should read as per the second last line 

```
#ifdef DFROBOT
static uint8_t const buttonMappings[] PROGMEM = {
    2, 0, 3, 3, 0, 0, 0, 4, 4, 0, 0, 0, 1, 1, 0, 0,
    0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
#else
static unsigned char const buttonMappings[] PROGMEM = {
    2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
    1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
};   // deleted the comment
#endif
```

These mappings are created with a utility in the original LCD library as mentioned earlier.

Also the backlight pin should be able to be enabled on different hardware with a change to around line 31 (// = comment)

```
//#define LCD_BACK_LIGHT         3        // Default LCD backlight is on D3 - Freetronics
#define LCD_BACK_LIGHT          10        // Default LCD backlight is on D3 - DFROBOT and others
#define LCD_BUTTON_PIN          A0        // Button state is on A0
```
So you just need to uncomment one line and recomment the other. 

And the memory usage of the nano is probably going to break the script due to memory overruns. The bootloader must be bigger.

The bootloader is burnt to the chip using am Atmel Risp programmer. I have used one of these to download a script when I've busted the USB on an Arduino. There will be instructions around on how to do this and also how to make your own Risp programmer. This may increase available RAM as the bootloader is no longer there but I really don't know.

And yes, most boards except Freetronics use the 2k2 resistor.


----------



## curtistdc (Dec 9, 2019)

rodw said:


> Hmm, that was easy. It looks like external relays are now supported. I won't share it yet as I have not tested it with real hardware unless somebody really wants to try it but a hardware interrupt on pin 2 fires if it receives a 5 volt signal and after indexing is completed, pin 13 is briefly enabled (currently for 0.3 seconds) signifying the indexing move has been completed. To implement this you'd need two relays (optoisolated preferred). One relay would be triggered on the external device and it would switch 5 volts from the Arduino power supply to pin 2.
> 
> Another relay would be attached to the Arduino PIN13 and Arduino GND. It would switch field power on the external device to an input signifying the machine could continue. Apparently some machjines (eg with Fanuc controls) are provided with macro relays that can be triggered with something like an M40  in gcode.
> 
> ...




Rod, This is Scott and I am back to playing around with this project again.  I am done farming for the year and can dedicate some time to getting this to work with my Milling machine with the fanuc control.  I have successful got it wired up the the mill and am able to make it index wit a m40 signal from the fanuc control.  After the indexing operation finishes the delay pulse I sent from within the code sends a pulse that cancels the M40 comand and the mill continues with the program.  It work about 80% of the time and as I suspected there is a problem with using the delay command in the arduino code.  Occasionally it triggers the end of m40 during a indexing movement.   So I came back to the forum and read the posts since I got busy with work.  It sounded like you had been working on this problem while I was busy. 

 So right now I am piggybacking on the right button push switch with a m40 index command from the fanuc relay.  The command to cancel m40 comes from a dfrobot relay shield that is hooked to the d10 pin.  It sounds like you are doing the same thing with pin 2 (start) and pin 13 (index done).  My problem is my poor coding with the delay function i believe.  I would appreciate if you could share the work you had done so I could try it out.  I am assuming I could change from pin d10 to d13 in the code and use pin 2 instead of my piggyback on the right button.  I really appreciate all of the trouble you have gone to with this project
Thanks
Scott


----------



## rodw (Dec 10, 2019)

Scott, I'll have to dig out the code to see what I ended up doing. I only ever bench tested it. I was trying to incorporate a rotary encoder into the menu but it really is designed for a keyboard so I don't think I could make it work nicely.


----------



## curtistdc (Dec 10, 2019)

Thanks rod, I tried implimenting what you had mentioned a couple of posts prior to the one I replied to but ended up with compiler errors. I appreciate your help thanks
Scott


----------



## metalrus (Jan 9, 2020)

My system consists of CW250 controller,HF100W-SF-24 power supply,57BYG-310D stepper motor, Arduino Uno,Sainsmart LCD,and used rotary table 10 . The LCD display shows the menu for the program, but the steppermotor makes a noise and doesn't rotate. When i tested the stepper with a independent circuit it rotates just fine. What can i look for? Need Help.


----------



## RM-MN (Jan 10, 2020)

I'm no expert but two things come to mind for why a stepper motor makes noise and doesn't rotate.  One is too fast of pulses and the motor can't keep up.  The other is reversed leads on one of the coils so the motor steps one way and then tries to step back.  I'd try reversing the polarity of one set of motor leads first.


----------



## rodw (Jan 11, 2020)

I suspect you are trying to drive the stepper faster than it is able to do so.  In frequency. settings, reduce the frequency. Too many people have used this script for it to be a software issue. It has to be a configuration or wiring  issue.


----------



## metalrus (Jan 11, 2020)

Rod i sent the company my proposed wiring diagram before i built this wooden turntable, like a lazy susan and they said everything looks ok. Could it be the rotary table 10 code? I could go through the entire menu on the sainsmart lcd.


----------



## rodw (Jan 11, 2020)

What is the value in the setup menu for MaxHz?
Try halving it and make sure MinHz is less than that number.
This is what determines stepper speed and at the beginning of a move, it ramps up from minHz to MaxHz then ramps down the other way at the end. Low speeds have more torque.

The other possibilities are:
1. Not enough Torque to turn your table.
2. Stepper Voltage too low (which causes 1)

So looking at your parts, it looks like you have a Stepper driver that will handle 60 volts which your NEMA23 stepper will easily handle but you are only feeding it 24 volts.  If you double the power to 48 volts, you will more than double the torque.


----------



## Rickus (Jan 12, 2020)

Good Lord!  Bunch of rocket scientists.  The only stepper I know of is the Two Step!!!


----------



## metalrus (Jan 12, 2020)

Rod i am new at this code stuff, can you tell me where i can find this MaxHz. Is there a line number in the Rotary Table 10 code? I removed the stepper from the turntable and have the same results.


----------



## curtistdc (Jan 20, 2020)

I have got my 5C HAAS index head working with the mill!  I have implemented a M40 command from the Fanuc 0mc control to activate an index move.  an arduino driven relay then resets the m40 index move and continues on with the code.  I am going to try and ad a link to a video of it at work.  The part is a 72 to 1 worm gear being cut with a thread mill.  Thanks Rod for all your work on this project what used to take me an hour and now be done in 8 min.


----------



## jdurnya (Jan 21, 2020)

very nice  is that hardinge indexer cnc ? or did you convert it ... would love to see more pics / specs of that

JOe


----------



## curtistdc (Jan 21, 2020)

Its a Haas 5c indexing head.  I think they were a copy of the Hardinge one.  Its driven by a stepper motor and was originally controlled by a haas driver.  My system uses the Arduino code from this thread and a relay shield.  With some small changes to the code the arduino sees a relay cycle generated by the cnc with a M40 command in the code.  when the index is done it then sends a signal back to the cnc to cancel M40 and continue.  The driver is a Gecko controller driven by a 48 volt power supply.


----------



## jdurnya (Jan 21, 2020)

thanks for the details !   any slop in that ?   any chance of taking some close ups of the stepper mechanical connection to the indexer ?   maybe i can fab one up using one of my manual hardinge ones..

thanks !
Joe


----------



## curtistdc (Jan 21, 2020)

jdurnya said:


> thanks for the details !   any slop in that ?   any chance of taking some close ups of the stepper mechanical connection to the indexer ?   maybe i can fab one up using one of my manual hardinge ones..
> 
> thanks !
> Joe


I will take some pictures of the mount on it I have two more that don't have motors on them I will get some pics for you. If I remember correctly hardinge made them for Haas I think


----------



## jdurnya (Jan 21, 2020)

thank you !!


----------



## reloader (Mar 15, 2021)

Hello,

as I told in my short introduction, I built an arduino rotary stepper with the version "rotary 11" of rodw.
The LCD Key shield worked just from the start, but my stepper did not run.
Later, I changed the Dir and Step pins to the positions 2 and 3. That seems to work.
But now, every run starts with a frequency burst and ends with a frequency burst.
After setting down the motor frequency, the stepper seems to work correct. I noticed, that the program did not work fine, when I run divisions like 7.
Going deeper into the program, i changed the step pin in the step correction.

But there was a remaining problem, that the stepper runs quick and slows down after a while.
So it was time to use my oscilloscope to test my construction.
First step was to test the arduino. Everything was ok. Then I tested the driver. 
The leadshine digital driver switches  between different microstep settings. This seems to be the main problem.

But also the arduino output changes frequency from 1000 Hz to approx. 650 Hz after some time.

So I will have a deeper look at the driver problems first.


best regards

Edgar


----------



## rodw (Mar 15, 2021)

reloader, be sure you are using the version in post #103 and make the change in post #107. The code is robust and enough people have used it to know its bug free now.
You may be getting interference from the serial port data re the burst. I can't quite remember which pins it uses.
In my experience, steppers loose steps when they get hot. What voltage are you running them at?
The Leadshine probably does step morphing so at constant velocity it will reduce the microstepping to the motor to maximise torque. In fact, I would expect it would do that for sure.

I never checked the Arduino frequency but I would be surprised if it was not constant unless it had a flaky crystal on board. The doc say "nearly perfect accuracy compared to software timers" see khoih-prog/TimerInterrupt


----------



## stragenmitsuko (Mar 15, 2021)

I can confirm that the code runs flawlessly . I use an old A3977 based stepper driver .
It's a 1/16 single chip driver . Not the best driver n the world , but for this application
it is more then enough .
I've used it many times over the past year without even a glitch .





						Arduino indexer , full project
					

It must have been more then a year since I've learned about the arduino indexer software .  This was immediatly classified in my head archive as a great project , wich I would  certainly do someday .  I have a drawer full of those projects in the back of my head .   So I started collecting all...




					www.homemodelenginemachinist.com
				




I also use the leadshines digital drive  DM556 on my experimental cnc , machIII parallel port .
As far as I can tell they're not morping drives .

Pat


----------



## reloader (Mar 15, 2021)

Hello Rod,

thank you very much for your quick answer. Yes, I use the program from # 103, but I did not make the changes from #107.

As I read before, the Digital pins 0 and 1 are influenced by the usb dta transfer.

I checked the output of the arduino with my cheap digital LCD oscilloscope and it has the nice feature to measure the frequency of the signal.
So I could see the change in frequency . But this effect dissapeared after an arduino reset.

I also made some mistakes with the driver settings, because I did not see, that there was a additional switch for halve and full current on the digital driver.

I will have a closer look at my construction tomorrow.

best regards

Edgar


----------



## reloader (Mar 16, 2021)

Hello,

I thougt about a new strategy to solve my problems.
I will install the originial rotary 11 again with the driver pins 1 and 2.
Then I will search, where this pins are on my strange AZ delivery LCD shield. It seems soo ,that the locations of pin 1 and 2 are complete different to other LCD shields. I hope, this will work for me.

best regards

Edgar


----------



## reloader (Mar 16, 2021)

Hello,

i must say, that I am a little bit helpless. I installed the origin rotary 11, checked that the changes in the LCD library were done.
Then set the Dir pin with the LCD shield at 2 and the step pin at 1.
But the step pin 1 was not saved!
 Now I have the funny situation, that Dir Pin is 2 and step Pin is 2 and the stepper still runs!
and the arduino still plays the frequency change modus.


best regards

Edgar


----------



## reloader (Mar 16, 2021)

Hello,

attached you will  find some photos of my 7 division run.
You can see the first, the 5th, the 7th and the 9th division.

Please have a look at the frequency. The signal comes direct from the step Pin.
Any help is wellcome.

best regards

Edgar


----------



## reloader (Mar 17, 2021)

Hello Rod,

I do not understand, what you mean with the changes in post#107?

If I delete a comment, the program will not be changed. How does the arduino knows, what LCD shield is used? I could not see this in the program.

Today I loaded the older version rotary 10.
Also with this version, I could not change the step pin to 1. So I think, that the LCD library does not fit 100% to my LCD shield.

You may know, that your program is very complex for an arduino beginner.
I had big problems to understand why a rotation needs 1296000 seconds!

You defined minutes in a circle, comment this as second for a circle, but I think, you mean arc seconds of a full circle.

best regards

Edgar


----------



## [email protected] (Apr 21, 2021)

Shehan Perera said:


> #rodw
> 
> Can you please give us the wiring diagram.


Hi Shehan, did you ever get a wiring diagram?


----------



## AndrewMcW (May 23, 2022)

Hi folks, at the risk of necroposting : regarding the problems that Edgar/reloader has been having...
"...to know its bug free now. "
Bloke I used to work with used to say "There is always one more bug!", and so it is with the RotaryTable11 sketch:






So trying to change the Step pin will never work - there is no code block to handle it it ; changing the Dir pin will cause the globals.StepPin to be re-initialized (as well as actually changing the Dir pin)

I believe the correct code would be:





Hope it helps someone!

Cheers - Andrew


----------



## rodw (May 23, 2022)

Hmm, it indeed looks like you have found a bug


----------



## emco11 (Jul 6, 2022)

Hi Rod,
my name is Wolfgang and I live in Germany.
I have rebuilt your indexer. I am not a programmer. In principle everything works, except the selection <contin>, if I select that and then stop with <set> this hangs up the whole and works only after a reset.
Do you have an idea what could be the reason?
I am working with the 11th version where I downloaded from this thread.

best regards,
Wolfgang


----------



## rodw (Jul 6, 2022)

There is a 12th version. I uploaded it here.
However, if the keyboard is not working, it is because of an incompatible keyboard/LCD shield that uses a different resistor value.
You could try editing LCD.cpp and use this key map instead of whats there.

```
static uint8_t const buttonMappings[] PROGMEM = {
    2, 0, 3, 3, 0, 0, 0, 4, 4, 0, 0, 0, 1, 1, 0, 0,
    0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
```

I had saved this back when I wrote V 12. I'm not sure if it will fix the issue. Its generated by a C program to speed up keyboard response.


----------



## emco11 (Jul 8, 2022)

Hi Rod,
first of all thank you very much for the answer.
I have tested with a DFRobot module. There it works. Unfortunately, my used module the holes are not equal and is but already installed.
Now my question would be, can you explain to me how that works with the generation of the key map that I can create from my board?
Since I have no idea. A small to do list would be very helpful.

best regards,
Wolfgang


----------



## stragenmitsuko (Jul 8, 2022)

It's  resistor value issue . Check posts 69 and 71 . 
I had thesame issue and it's easily solved .


----------



## stragenmitsuko (Jul 8, 2022)

Rod , what' new in version12 ? 
I'm running version 11 .
Pat


----------



## rodw (Jul 8, 2022)

I really have no Idea.It will not include the bug fix of Andrew in post #136


----------

