Tips for Arduno software for Rotary Table Controllers

Discussion in 'Software and Programming' started by rodw, Feb 8, 2015.

Help Support HMEM by donating:

  1. Feb 20, 2015 #81

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
  2. Feb 20, 2015 #82

    TorontoBuilder

    TorontoBuilder

    TorontoBuilder

    John

    Joined:
    Jan 4, 2013
    Messages:
    357
    Likes Received:
    82
    Rod, You're awesome. Thanks for working so hard on this.
     
    Scott_M and rodw like this.
  3. Feb 20, 2015 #83

    canadianhorsepower

    canadianhorsepower

    canadianhorsepower

    Well-Known Member HMEM Supporter

    Joined:
    Oct 22, 2011
    Messages:
    1,671
    Likes Received:
    320
    Thanks for this Rod Thm:Thm:

    do we still have to import the LCD library from post 20

    cheers

    Luc
     
  4. Feb 20, 2015 #84

    Scott_M

    Scott_M

    Scott_M

    Well-Known Member

    Joined:
    Apr 13, 2013
    Messages:
    251
    Likes Received:
    76
    Location:
    Medina, Ohio USA
    Hi Rod

    I hacked into my 4th axis and ran from the arduino. Power from the mill and step/direction and 5V from the arduino. This is a 6" Tormach 4th. It has a Nema 23 motor. Running at 65 volts with a current limiting resistor for 2 amps.
    It ran well, I bumped the speed up to 100.
    You are correct , single steps are really small , it really takes a bunch to move a degree.

    I ran into a error when trying to move a specified 30 degrees. It was turning 180. I took some shaky handheld video.

    www.sdmfabricating.com/upload_page/RodV4.MOD

    With the exception of the math error it is very cool !

    Or maybe it was remembering the previous input of 2 in # divisions ?
    The screen did say "of 12" when I had it set to 30 degrees on the DMS page.

    Scott
     
  5. Feb 20, 2015 #85

    Scott_M

    Scott_M

    Scott_M

    Well-Known Member

    Joined:
    Apr 13, 2013
    Messages:
    251
    Likes Received:
    76
    Location:
    Medina, Ohio USA
    More info

    I tried to reproduce the bug and it is reproducible. But I am not sure it is a problem if you know about it and I am not sure anyone would do this.
    Step 1 boot up, set number of divisions to 2 and go, it will go to 180. hit it again it will continue on to 0
    step 2 select out and select to "set angle" enter 030.00.00 and go, it will go to 180

    I do not think a real world situation would have you entering data like that. It would be either all degrees or divisions.
    And if you have too switch , reboot and start fresh.

    I did enter 10.00.00 and it went 10 and then reentered 30 and it went another 30 to 40 so that works fine.

    "Home" works good. If you do not set a home position it will go to where it was when you booted up.

    Very,very nice Rod !! well done.

    Scott
     
  6. Feb 20, 2015 #86

    TorontoBuilder

    TorontoBuilder

    TorontoBuilder

    John

    Joined:
    Jan 4, 2013
    Messages:
    357
    Likes Received:
    82
    runs on mine... 2 keystroke issue indeed solved.
     
    rodw likes this.
  7. Feb 20, 2015 #87

    chucketn

    chucketn

    chucketn

    Senior Citizen

    Joined:
    Dec 17, 2009
    Messages:
    1,300
    Likes Received:
    154
    Occupation:
    Fully retired
    Location:
    Near Jonesborough, TN
    Although it compiled without error this time, I cannot get ver4 to run on my hardware. I do have all the libraries required, and changed the step and direction pins to match my setup. I reloaded Chuck F's sketch and it works so no hardware issues. The menus come up and work but the stepper, she no move!.

    Chuck
     
  8. Feb 20, 2015 #88

    Scott_M

    Scott_M

    Scott_M

    Well-Known Member

    Joined:
    Apr 13, 2013
    Messages:
    251
    Likes Received:
    76
    Location:
    Medina, Ohio USA
    Chuck
    I do not think you can change the sketch to work with your hardware. Rod moved the step pin from 3 to 1 because there was a conflict with pin 3.

    Not entirely sure but that is my guess.

    Scott

    Edit; I just checked the LCD library and the "backlight" pin is pin 3
     
  9. Feb 20, 2015 #89

    chucketn

    chucketn

    chucketn

    Senior Citizen

    Joined:
    Dec 17, 2009
    Messages:
    1,300
    Likes Received:
    154
    Occupation:
    Fully retired
    Location:
    Near Jonesborough, TN
    I'm not having a problem with the LCD, it displays the menu options and I can set the # of divisions. Just the stepper not working. I can hear the stepper buzz, and it kinda twitches when the movement ends.
    I guess if I want it to work, I need to go through both sketches side by side and find where the settings are different for the stepper.

    Chuck
     
  10. Feb 20, 2015 #90

    Scott_M

    Scott_M

    Scott_M

    Well-Known Member

    Joined:
    Apr 13, 2013
    Messages:
    251
    Likes Received:
    76
    Location:
    Medina, Ohio USA
    Chuck

    Pin 3 is being used already by something else. By you trying to use it as well is a "conflict" it is not going to work correctly.
    You won't find the pin conflict in the sketch. It is in the LCD library and cpp file.

    I do not know enough about this stuff to know if you can alter that library without major issues.

    I think you would be much better off moving the step pin to pin 1.

    Scott
     
  11. Feb 20, 2015 #91

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Scott, thanks I'll have a look. I'm trying to keep the steps and angles remembered between the #steps and Angle functions so I don't have to write separate stepping routines for each method (to save memory). I will have missed a conversion somewhere. I thought I'd got them all.

    Great to know we have one actually driving a rotary table :)
     
  12. Feb 20, 2015 #92

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Chuck, I think you'll have the speed/frequency configuraton in the #defines set too fast for your stepper. I've got it set for 2000 steps per stepper revolution. If you have a conventional stepper driver (like the Polou) you need to make some changes.

    ie here
    Code:
    #define STEPPER_STEPS_REV 200 // The number of steps per stepper
    #define MICRO_STEPS 10        // set to 1 if not not using a micostepper driver, otherwise set to # microsteps
    #define DIVIDE_RATIO 90       // The Dividing table ratio (eg 40 or 90)
    
    probably here, where I changed it to 1 for you
    Code:
    #define MICRO_STEPS 1        // set to 1 if not not using a micostepper driver, otherwise set to # microsteps#define MICRO_STEPS 10        // set to 1 if not not using a microstepper driver, otherwise set to 
    Once you get this right, if you still have a problem, increase this number to slow down the stepper (eg. Increase the time between stepper pulses).

    Code:
    long TIMER_DELAY = 80;
     
    TorontoBuilder likes this.
  13. Feb 20, 2015 #93

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Correct, the pins used by the Freetronics board are:
    3, 4, 5, 6, 7, 8, 9 and Analog 0

    This meant I had to move one of the stepper signals off Pin 3
     
  14. Feb 20, 2015 #94

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Luc, you only need to import the additional libraries once. If you've done it before, you don't need to do it otherwise, yes do it. My edited post #1 will clarify this.

    PS the compiler will be very unhappy and tell you if code is missing via a stream of errors...:eek:
     
    canadianhorsepower likes this.
  15. Feb 20, 2015 #95

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Thanks more than happy to test your hardware in return :p
     
  16. Feb 20, 2015 #96

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334

    Scott, it will be a while before I can test this with a stepper but for now, try replacing enterDegrees() with this:
    Code:
    void enterDegrees(void)
    {
      int event = LCD_BUTTON_NONE;
      float tmpSTEPS_PER_REV = (float)STEPPER_STEPS_REV * (float)MICRO_STEPS * (float)DIVIDE_RATIO;
      angleField.setValue(mAngle);
      if(mAngle){
         divisions = (long)((float) MINUTES_IN_CIRCLE / (float) mAngle); 
         stepsPerDiv = (long)(tmpSTEPS_PER_REV *((float)mAngle/(float)MINUTES_IN_CIRCLE));
      }   
      else{
         divisions = 0L;  
         stepsPerDiv = 0L;
      }
      angleForm.defaultField();
      angleForm.show();
      while(event!= LCD_BUTTON_SELECT){
        event = lcd.getButton();
        if(event == LCD_BUTTON_SELECT)
          break;
        if (angleForm.dispatch(event) == FORM_CHANGED) {
            if (angleForm.isCurrent(angleField)) {
              // set the number of divisions here
              mAngle = angleField.value();
              stepsPerDiv = (long)((float)tmpSTEPS_PER_REV *((float)mAngle/(float)MINUTES_IN_CIRCLE));
              divisions = (long)((float) MINUTES_IN_CIRCLE / (float) angleField.value()); 
            }
        }
      }
      if(mAngle)
        goDivide(angleField.value());
    }
    
    Looks like I was not initialising stepsPerDiv on entry to agree with the angle and I've also changed the code to make sure STEPS_PER_REV is a float before it it used
     
    Scott_M likes this.
  17. Feb 20, 2015 #97

    canadianhorsepower

    canadianhorsepower

    canadianhorsepower

    Well-Known Member HMEM Supporter

    Joined:
    Oct 22, 2011
    Messages:
    1,671
    Likes Received:
    320
    Rod
    I must be real stupid can't fixe that LCD error:wall::wall::hDe::hDe::wall::wall:

    can you walk me thrue this PLZ

    Luc
     
  18. Feb 20, 2015 #98

    darkoford

    darkoford

    darkoford

    Member

    Joined:
    Dec 9, 2014
    Messages:
    11
    Likes Received:
    3
    Is it the pin (red)?

    // Pins in use
    #define BUTTON_ADC_PIN A0 // A0 is the button ADC input
    #define LCD_BACKLIGHT_PIN 3 // D3 controls LCD backlight
    // ADC readings expected for the 5 buttons on the ADC input
    #define RIGHT_10BIT_ADC 0 // right
    #define UP_10BIT_ADC 145 // up
    #define DOWN_10BIT_ADC 329 // down
    #define LEFT_10BIT_ADC 505 // left
    #define SELECT_10BIT_ADC 741 // right
    #define BUTTONHYSTERESIS 10 // hysteresis for valid button sensing window
    //return values for ReadButtons()
    #define BUTTON_NONE 0 //
    #define BUTTON_RIGHT 1 //
    #define BUTTON_UP 2 //
    #define BUTTON_DOWN 3 //
    #define BUTTON_LEFT 4 //
    #define BUTTON_SELECT 5 //
    //some example macros with friendly labels for LCD backlight/pin control, tested and can be swapped into the example code as you like
    #define LCD_BACKLIGHT_OFF() digitalWrite( LCD_BACKLIGHT_PIN, LOW )
    #define LCD_BACKLIGHT_ON() digitalWrite( LCD_BACKLIGHT_PIN, HIGH )
    #define LCD_BACKLIGHT(state) { if( state ){digitalWrite( LCD_BACKLIGHT_PIN, HIGH );}else{digitalWrite( LCD_BACKLIGHT_PIN, LOW );} }
    /*
     
  19. Feb 20, 2015 #99

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Which LCD error?

    Try this.
    1. Download LCD.zip
    2. Unzip
    3. Manually move the folder to your Arduino Library folder.
    4. Restart the Arduino IDE

    In my system, the library is in
    \Documents\Arduino\libraries
     
  20. Feb 20, 2015 #100

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    Yes, I started using pins 2&3 like Chuck when I first started with steppers but as soon as I added the LCD shield, I had a conflict so moved the signal on pin 3 to pin 1 and my code will always reflect that change.

    If your backlight is on a different pin, change the #define you've highlighted.
     
    darkoford likes this.

Share This Page