Star Tracker - Project question

Hi guys, I'm building a star tracker for long exposure photography. I'm using a stepper motor to drive the tracking motion and have the code for it working fine.

My question is, I'm looking to add in an angle sensor and compass sensor to aid in aligning with the south celestial pole. But I'm concerned this may interrupt my stepper motor driving.

I've uploaded my stepper code for you to see. (I use an app on my phone to control the inputs to arduino).
Is it likely that adding in some code for calculating angle and direction from those 2 sensors going to interrupt my stepper speed? Or am I pre-empting a problem that doesn't exist?

If it will be a problem can anyone suggest a method of doing things which will not interrupt the stepper?

Bluetooth_Stepper_motor_control.ino (1.35 KB)

There are plenty of posts about doing more than one thing at a time, using millis to control one thing with time while you do other stuff. This is what the mysterious "blink without delay" is all about, but I would have thought you would have the polar alignment sorted out before you started tracking, and therefore not part of the problem.

Polar alignment can be done manually, though indeed odd that's not where you started.

As long as reading the sensor is fast, it should not have an effect on your steppers. Just make sure you don't add in long calculations or so.

You can't expect a consumer grade compass sensor to be accurate to better than 1 degree, and tilt sensor accuracy must also be considered.

Would that be good enough for proper alignment with the Earth's rotation axis?

Yeah you are right in that polar alignment is the first of step of astrophotography. However because I live in town and cannot visually see the pole, I need some rough guidance of where to aim.

Figured some cheap sensors would get me in the ball park. (within a degree or 2 would be close enough very widefield stuff which is mainly what I do).

I can use drift aligning to get accurate alignment however that takes a good 15-30min to do properly. But with sensors, I can hopefully setup once and do a drift alignment. record the angles/ heading and then use that to setup in the future and be reasonably confident its accurate.

Can I run this as 2 separate pieces of code. Run alignment with sensors first and then switch to stepping mode for the driving? I think having the readout from the sensors all the time might be handy as it will tell me if my alignment has moved during the night but really don't want to have any interruption to the timing on my steps of the stepper.

How would l go about writing it as 2 separate loops? and how do I change between those loops? Or would you just do it all in one?

jasp05:
Can I run this as 2 separate pieces of code. Run alignment with sensors first and then switch to stepping mode for the driving? I think having the readout from the sensors all the time might be handy as it will tell me if my alignment has moved during the night but really don't want to have any interruption to the timing on my steps of the stepper.

Of course.
OTOH if you want your stepper timing to be the most precise, use timer interrupts. That will also prevent other things from being late for the next step.

How would l go about writing it as 2 separate loops? and how do I change between those loops? Or would you just do it all in one?

Not. You loop will look like this:

loop() {
  bool aligned = checkAlignment(); // Read the sensors: returns true if properly aligned; false if not.
  if (aligned == false) {
    adjustAlginment(); // Correct aligment.
  }
  trackStars(); // do your star tracking with your stepper motor.
}

These functions are supposed to return fast - much faster than the interval between steps of your star tracking stepper motor(s).
If reading sensors may take a large part of that interval, consider using a timer interrupt to do your trackStars() function - assuming that this one does return fast. I suppose the adjusting alignment is also done in steps, and that this function also returns fast.