Stepper Position Sensing and Control

Thanks for all the input. Several weeks back I ordered a 0.9 stepper motor, a Seeed motor shield, and an optical sensor. I have the basic code started and I'm fabricating a heading wheel to mount on it that will also trip the optical sensor at a calibration point.

The wiring of the motor is basic enough and I have that taken care of. Likewise the wiring of the optical sensor. The basic code to run the motor is easy enough as is the code to do the calibration. I have almost everything either working on my test bench with one exception.

That exception being the continuous rotation past North in either direction. Not a show stopper, but I just haven't come up with a satisfactory way to deal with it yet. The flight sim software feeds me a compass bearing in the form of 1 to 360 degrees. I am reading the changes and doing the simple math to move the stepper from prior read to current read by the calculated number of steps. In most cases the step is no more that 1 or 2 degrees in either direction, but on occasion either do to high rates of turn or program lag the steps can be slightly bigger.

So I am trying to come up with the best way to deal with crossing North where the prior read might be 359 and the current read is 001, or in the other direction, the prior read might be 002 and the current read 360. I need the first to calculate +2 and the second to calculate -2.

Thoughts?

As for gauge or part sources, I have purchased several parts from bone yards, but not gauges. My sim is somewhat generic and will emulate about 6 different aircraft. As such the variation in operating ranges needed on the gauges makes hardware based gauges somewhat problematic unless I can come up with easily interchangeable face plates. As such I am only looking at mechanical gauge builds for a very limited portion of the sim, the Wet Compass being one of them.

Thanks!
Tom G.