One stepper bresenham question

Hello, I´m about to build an sidereal tracker for astro photography.

Problem in front: I can set my steps variable via the Keypad shield but the main steps are 3.714 steps/second.

I know there is a way to use the bresenham algorythm to solve this problem with the missing 0.286 steps, but I dont know how, when I´m changing the "speed", cause the difference is changing with it...

My settings are:
-LCD Keypad shield
-Arduino Uno
-Nema 11 (1.8°) with 100:1 gearbox
-A4988 in 1/16 step mode

The calculation:

200 Steps x 100 x 16 = 320000 steps/round

a sidereal day has 86160 seconds.

320000 steps/86160 seconds= 3,714 steps/second

Actuall sketch:

#include <AccelStepper.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int adc_key_val[5] ={50, 195, 380, 555, 790 };




int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int isRun;
double speeds = -241.6;
int maxspeed = 1200;

AccelStepper stepper1(1, 16, 15);

void setup() {                    // void means dont expect any return from this command
  lcd.clear();                    // clear the lcd
  lcd.begin(16, 2);               // set up the LCD's number of columns and rows:
  lcd.setCursor(0,0); 
  lcd.print("    Stopped     ");  // display stopped on the LCD
  lcd.setCursor(0,1); 
  lcd.print("Speed ");            // display the value of speed
  lcd.print(speeds);              // display the value of speeds
  lcd.print("   ");
  isRun = 0;

  stepper1.setMaxSpeed(maxspeed); //1245
  stepper1.setSpeed(speeds);      //
}

void loop() {
  adc_key_in = analogRead(0);    // read the value from the sensor 
  key = get_key(adc_key_in);     // convert into key press
 
  if (key >= 0)                  // if keypress is detected
   {
      if (key == 1) {
         speeds += 0.1;
         delay(100);
      }
      if (key == 2) {
         speeds -= 0.1;
         delay(100);
      }
      if (key == 0) {
         speeds += 10;
         delay(100);
      }
      if (key == 3) {
         speeds -= 10;
         delay(100);
      }
      if (speeds>maxspeed) {
         speeds = maxspeed;
      }
      if (speeds<-maxspeed) {
         speeds = -maxspeed;
      }
      if (key == 4) {
        isRun = 1 - isRun;
        lcd.setCursor(0,0); 
        if (isRun == 1) {
          lcd.print("+++ Running +++ ");
        } else {
          lcd.print("    Stopped     "); 
        }
        delay(250);
      }
      lcd.setCursor(0, 1);
      lcd.print("Speed "); 
      lcd.print(speeds);
      lcd.print("       ");
      stepper1.setSpeed(speeds);
      delay(50);
  }
  if (isRun == 1) {
    stepper1.runSpeed();
  }
}

int get_key(unsigned int input)
{
    int k;
    for (k = 0; k < NUM_KEYS; k++)
    {
      if (input < adc_key_val[k])
            return k;
    }
   
    if (k >= NUM_KEYS)
      k = -1;  // No valid key pressed
    return k;
}

Hopefully somebody can help me :slight_smile:

Thank you!

Additional details are needed, and you many need to rethink the motor drive.

The 100:1 drive leads to 0.018 degrees of shaft rotation per full step or 0.009 degrees per half step. How will the shaft rotation be used to drive the camera platform? Is there an additional gear ratio to consider?

One major consideration is that microstepping does not produce accurate fractions of a step. Instead, microstepping is intended to help avoid motor vibrations and resonance effects at certain speeds.

Microstepping also dramatically reduces the torque increment per step, so unless your mechanism is very carefully constructed, the drive may skip steps.

You claim to need 3.714 steps per second, but there is no reason to move the platform every second. Choose a different time step that leads to an integral number of motor steps.

Hey, thank you for your anwer!

I´ll drive the camera "directly" without additional gear ratio from the shaft.
For this I´ll mill an mount.

Because of using a 300mm lens, I don´t want the motor to stop and cause any vibrations or backlash.
In my thoughts it would step often enough for a smooth following of the earth rotation.

Thats the reason for the 1/16 stepping.

There are versions with additional worm gears, but I don´t have the machines to build an accurate one, so I first wanted to try my own thoughts.

Tell me if I have anything wrong.

Thank you!

AccelStepper lets you set speed as a floating point number of steps per second, like:

stepper1.setSpeed(3.71402);

Which would = 361.002744 degrees per 24 hours. I think. :confused:
Of course the Arduino's time base oscillator is not accurate enough for long term timing, you need a real time clock (RTC) for that.

Thank you!

I have some RTCs at home, the longest exposure would be around 5-10 minutes I think.

Does the accelstepper library round the steps up? Or how does it floating steps?

yeah its cause one "real" day has (around) 23h 56min and 4seconds

Does the accelstepper library round the steps up? Or how does it floating steps?

Not sure, I think it takes the steps per second that you enter, takes the reciprocal (1 / x) and multiplies that by 1 million to get the step interval in microSeconds. 1 / 3.71402 * 1000000 = 269250 microSeconds or 1 step every 0.269250 seconds. Keep in mind, Arduino uses float (32 bit) NOT double for FP math, so 6 significant digits (like 3.71402 or 37140.2) is all you get.

Build the mount first, then test whether 1/16th microstepping actually works. You simply cannot assume that it will.

Note that microstepping requires very careful adjustment of the current limit, and a motor that is compatible with the A4988.

Good tip, JR. Motor may not hold steady at 13/16 of a step for 0.269250 seconds.
Microstepping is good for smooth motion but not for holding position between full steps.

Thanks for you help!

I think I'll just test it out.
(the motor is on the way from China)

But some questions:
The motor doesn't stand still for a 'long' time or? Are 0.269250 seconds per step such a long time for holding the motor to lose steps?

About the current I maybe have to say something about my plans on powering it:

The Arduino will be powered directly from my power bank. From there I connected an DC/DC step up (5 to 12V) for the motor.

I connected an 7.5 degree motor for testing and the motor was turning. So I hope the Nema will work also :slight_smile:

I'll let you know when I finished the mount for testing!

Are 0.269250 seconds per step such a long time for holding the motor to lose steps?

Yes. Microstepping is intended for smooth, continuous rotation.

However, more important is that there is very little torque to drive from one stationary microstep to the next. This is part of the reason why the microsteps are not accurate fractions of a full step.

Ah now I understand!

And if I set it to 1/8 steps? Would this be more precisely?

The thing is, as I wrote, I don't want to do one step per second cause of the vibrations and backlash of the gears.

And if I set it to 1/8 steps? Would this be more precisely?

Possibly, but not guaranteed.

Better to use a larger gear ratio on your reducer, if required.

outsider:
Good tip, JR. Motor may not hold steady at 13/16 of a step for 0.269250 seconds.
Microstepping is good for smooth motion but not for holding position between full steps.

I strongly disagree, microstepping is superior, use it and avoid most of the vibration / resonance
issues with no penalty in holding force.

Hey guys!
I ran the first tests yesterday, and it works quiet well!

But i ordered another gearbox (305:1) and combine both, so I dont have to do microstepping.
Lets see what I get from it if it arrives :slight_smile:

Thanks everyone for helping me!

Hey Guys, its working!

From my calculations I had to set 11.14 steps/sec. (on 1/16, 3200 Steps/rev, gearbox ratio 100, additional 3:1 ratio =960000 steps / 86160 sec =11,14)

And I have point stars! - without losing any steps as far as I see

Thanks for all your help!

jremington:
Microstepping also dramatically reduces the torque increment per step, so unless your mechanism is very carefully constructed, the drive may skip steps.

No, this is a complete myth. Microstepping reduces the chance of skipping due to midband resonances,
at low speeds there is no issue at all.

There is no "torque increment per step". At low speed there is holding torque and microstepping
keeps a pretty constant holding torque during slow speed motion, whereas full stepping will risk
jumps at the step points as the motor is 90 degrees away from its optimum torque point immediately
after the step.

Yes, there may be parts of the cycle with microstepping where the holding torque is a little less
than at a full step point, but this matters not at all as steps are skipped due to dynamic torque
or resonance issues long before holding torque is exceeed - go play with a motor and try it.

No, this is a complete myth.

You are either misinformed, or confused about semantics.

Provide measurements then please... I power a stepper and it gives a certain pull-out torque. I set it
microstepping slowly and it still provides that torque. I set it to full steps and it will skip it that kind
of torque load is applied.

All simple experiment to do with a stepper with a handle mounted on the shaft, for instance.

[ Also see: https://www.njr.com/semicon/PDF/application_notes/Microstepping_APP_E.pdf ]