Programming Advice Needed, Arduino Micro

Hello, everyone.

I have set out to build a star tracking camera mount to use for astrophotography. I am using Arduino Micro, Pololu A4988 Driver and a stepper motor. I have attache my stuff and am able to run the motor with basic commands. The boards, the motor and wiring seem to be okay. But the final programming remains.

I am a structural engineer and do have a bit of programming experience as a hobbyist so I am not shy with technical stuff and programming lingo.

The mount works when it rotates with an angular speed that matches the angular speed of the planet (sidereal speed). And to achieve that, the screw moves in a linear fashion.

The issue is that the linear speed of the shaft which is driven by the stepper is not linearly related to the angular speed of the mount. And since the angular speed is of paramount importance, we need to vary the screw rotation speed in order to keep the angular speed at the right value.

The board will be programmed to run for 180 minutes which is when the mount has rotated about 45 degrees.

When I program this into MS Excel, I notice that with full steps (200 per revolution), I need to adjust the speed at various locations in time. The first adjustment, for example, takes place at t+36 minutes at full step (18 deg per minute). At 1/16th micro-step per minute (through the Driver) that initial adjustment needs to be made at t+14 minutes from 4032 steps per minute to 4031 steps per minute, and the subsequent adjustments are more frequent with the micro-stepping than they are with full-stepping.

What I am planning on doing is to perform a few loops at given time minutes. And before I get into that I was wondering if anyone here has any suggestions or knows about how others may have done something like this.

Thanks much in advance.

Farzad

You need a mathematician for a formula. I can do a simple sinus/arctan, but this seems a lot harder to calculate. Is the screw and linear rotation so accurate that you know the exact rotation for a certain hour of a day ? Perhaps you can count how many steps are needed for that moment in time, and advance a step if needed.

So you don't calculate if the next step is in 12 or 13 minutes. You calculate the rotation for that moment and from that the number of steps for that moment. Say at 02:57 you need to have 40311 steps, and you have only made 40310 steps so far, then it is time to make the next step.

Only a (micro) step every 13 minutes ? That is very slow. Perhaps you can use a stepper motor with a gear.

I know some mathematics and this case is pretty difficult because the relationship is not known. To avoid this, many people just use curved screws and avoid the tangent error all together. But because I am able to use a smart technology such as the Arduino Micro, I want to do it better.

I meant to say that if it micro-steps, for the first 13 minutes, the motor has to step 4032 steps per minute. I will edit my post shortly. At full step it will have to do 252 steps per minute until t+50 when the stepping has to change to 251 until t+86 minutes.

I am using a high-pitch screw and might just stay with full steps in order to change the speed less often.

Thanks for reading and providing your input.

Farzad

A change from 252 to 251 is so little. I think microstepping is better for more accuracy. About 70 steps a second with microstepping seems a good number to me for good accuracy. I hope it doesn't introduce vibrations. So you don't need a stepper motor with a gear, the screw does all the gearing for you.

What about my idea to calculate the angle (the number of steps) for a certain time. That way you don't have to think in 'speed' and don't have to think for how many minutes you need a certain speed.

Peter, so you are saying micro-stepping is a good idea and that I can even up the numbers a little bit to make things more straightforward?

I am not sure what you are proposing. Some trigonometry is being used to calculate the required number of steps per minute in order to turn the screw in such a way that the mount can rotate at the desired angular speed (0.2507 degrees/minute sidereal).

Maybe the attached schematic can help clarify the mechanism.

Thanks.

Farzad

I just wanted to show an other approach. A stepper motor makes steps, it doesn't have speed (that is how I see it). And if you need a certain angle at a certain time, you can look at it as if you need a certain amount of steps at a certain time. That is what a stepper motor is mostly used for, go to a position for example 93547 steps forward, and go 93547 steps backward, and it should be in the same position as before.

But I guess you are used to a certain desired angle speed. You should stick to that of course.

When I read about the 252 and 251, I was thinking: "how would you finetune that ?, there is nothing in between". So microstepping seems better, and that results into 70 steps per second, which seems to me like a good number.

Did you select a stepper motor ?

The Arduino has a millis() function for timing. It counts milliseconds in a unsigned long (32-bit) integer. You can use that for timing. Keep in mind that the value will rollover some day, but rollover trouble can be avoided. There are also libraries for timing/scheduling, but perhaps you only need the millis() function. http://arduino.cc/en/Reference/millis http://arduino.cc/en/Tutorial/BlinkWithoutDelay

I have this stepper motor: http://www.pololu.com/product/1208

And I have been able to load a program and run it for test.

It will take a little learning on the steppers and I am doing the study. I will keep your suggestions in mind.

Thanks.

I’ve been working on a unit that is similar to the astrotrac

Here’s the image of it - this one is made with hardboard and now i’m working on one that is all aluminum

Very interesting, Mark, and thanks for sharing.

I have seen a device like this which is commercially available. And I am considering the approach myself after I get the original one running.

You are incorporating a lot more hardware than I thought would be needed.

Your device still is affected by the tangential error situation. Have you used it for photography yet? How did you deal with the error?

Farzad

Have you the ability to calculate the cumulative number of steps at each minute (or other suitable interval) on your PC - perhaps with Excel or some other program. If you could then include those numbers in your program the Arduino would just make the motor move the appropriate number of steps for every interval.

You may want to consider inaccuracy in the Arduino's clock - they don't run at exactly 16MHz and may gain or lose time over 180 minutes.

...R

Robin,

Thanks for the input.

Yes, I already have calculated the variations and am ready to program the Arduino once I figure out how to do that. I need to vary the number of steps at irregular intervals of time or perhaps as was suggested earlier, provide the total number of steps within those intervals.

I have also compared full step variations and variations based on different micro-stepping. Not surprisingly, the number of variations increases as the steps become more micro. I have picked a high pitch screw as well and to increase the smoothness of the operations. It could be that the a good balance between screw pitch and the micro-stepping might be a better answer. I will definitely be experimenting with the micro-stepping when my system is assembled and ready to see if micro-stepping is necessary.

I have attached my calculations for anyone who is interested. At this point I am not sure how I will communicate the movements of the motor to the controller. It seems that I can order micro-stepping through controller programming alone and or I can do it through the driver.

Farzad

Tangential error2.xlsx (350 KB)

Khosrownia: At this point I am not sure how I will communicate the movements of the motor to the controller. It seems that I can order micro-stepping through controller programming alone and or I can do it through the driver.

Use the A4988 stepper driver to actually cause the micro-stepping to happen - then as far as your program is concerned there are just more steps per revolution.

If you are happy to have your PC connected to the Arduino all the time the movement is happening the control system becomes very simple - do all the work on the PC and just send information whenever a step or series of steps is needed.

If you want the Arduino to operate without the PC attached you either have to build all the step information into the program or store it on an SD Card attached to the Arduino.

I don't think you have given a very clear idea of the sorts of variations in step speed that you need (I confess I have not looked at your calculations). I imagine that the variations follow a simple pattern, for example getting a little bit faster for the first half of the period and a little slower during the second half, rather than jiggling about all over the place.

...R

Khosrownia: Very interesting, Mark, and thanks for sharing.

I have seen a device like this which is commercially available. And I am considering the approach myself after I get the original one running.

You are incorporating a lot more hardware than I thought would be needed.

Your device still is affected by the tangential error situation. Have you used it for photography yet? How did you deal with the error?

Farzad

The hardware you see is an Arduino nano, easy driver, pushbuttons and a stepper motor. I also recently added an optical switch for setting zero point on rewind.

This setup also suffers from tangent error, still working on that code. I tried a few shots but with hardboard there was way too much slop. Now I'm working on a aluminum version, will post when it's done

I'm sure it would be cheaper to just buy one, but this is more fun.

Regards Mark

Robin,

The intent is to program the Arduino and then take it into the field and have it operate on its own. I don't see how operating it is going to be different if hooked to a pc or unhooked. Does it not operate with the internal programming?

The pattern of change is not uniform. It is known that as the time goes by the tangential error becomes larger therefore more adjustment will be needed. I think we start with one speed and then gradually slow down.

If you are not able to open Excel file and are interested in seeing the process let me know and I will give you a pdf.

Farzad

Mark,

The best versions of this tries to remember how many steps the motor took and then it reverses automatically to that many steps. It is going to be dark out there and I am not sure how optical sensors would work.

My design eventually is going to calibrate itself first by slightly opening and closing until it finds some resistance and then will count the number of steps to where it was stopped in order to return back at command. And since mine will be designed to travel no more than 45 degrees or near 180 sidereal minutes, it will also be designed to stop and return to original position if it hits that mark even though I know that I will probably never want to run this for 3 hours!

You have a good design going. You are avoiding some construction errors and creating others. One suggestion I have for you is to have the fixed arm beneath the deck instead of on top of it. That way you have more clear space for the rods to operate.

This costs people like you and me a lot, and we are doing it just because it is fun to do. I am in the process of learning how to design my own PCB to which I simply will plug the Arduino Micro and the Pololu A4988. I am using Eagle and it is loads of fun.

Farzad

Robin2:

Khosrownia: At this point I am not sure how I will communicate the movements of the motor to the controller. It seems that I can order micro-stepping through controller programming alone and or I can do it through the driver.

If you want the Arduino to operate without the PC attached you either have to build all the step information into the program or store it on an SD Card attached to the Arduino.

Robin,

I already replied to your suggestions. But I am now wondering about the SD card capability you have mentioned. What device do I need to attach to the Arduino and how would it work? It would be a great feature of my final design.

Thanks

Khosrownia: The intent is to program the Arduino and then take it into the field and have it operate on its own. I don't see how operating it is going to be different if hooked to a pc or unhooked.

All I meant is that if the Arduino is connected to the PC the data can be stored on the PC and sent as needed - and a much smaller program would be sufficient on the Arduino. It sounds like you don't want to bring a PC with you, so that rules out that option.

[I am now wondering about the SD card capability you have mentioned. What device do I need to attach to the Arduino and how would it work? It would be a great feature of my final design.

You can buy shields for the Arduino that have SD Card connectors or you can make one up with a bit of veroboard and some stiff copper wire for contacts - which is what I did. There is an SD Card library. You could write the SD Card file on the PC and then read it on the Arduino. The only downside is that the SD Card library needs a 512 byte buffer which eats up the limited memory on an Arduino.

You could use the SD Card without using the FAT file system and its large buffer but then it would not be compatible with a PC.

Another storage option would be a serial EEPROM chip.

...R

Khosrownia: Mark,

The best versions of this tries to remember how many steps the motor took and then it reverses automatically to that many steps. It is going to be dark out there and I am not sure how optical sensors would work.

My design eventually is going to calibrate itself first by slightly opening and closing until it finds some resistance and then will count the number of steps to where it was stopped in order to return back at command. And since mine will be designed to travel no more than 45 degrees or near 180 sidereal minutes, it will also be designed to stop and return to original position if it hits that mark even though I know that I will probably never want to run this for 3 hours!

You have a good design going. You are avoiding some construction errors and creating others. One suggestion I have for you is to have the fixed arm beneath the deck instead of on top of it. That way you have more clear space for the rods to operate.

This costs people like you and me a lot, and we are doing it just because it is fun to do. I am in the process of learning how to design my own PCB to which I simply will plug the Arduino Micro and the Pololu A4988. I am using Eagle and it is loads of fun.

Farzad

Hi Farzad,

I guess i never really explained the purpose of the optical sensor, It's used to detect when the arm rewinds back to the beginning(zero point, arms parallele) . It's a tiny thru beam switch. Very repeatable and none contact. It looks like this one

Picture doesn't really show it but the bottom arm is fixed and the electronics and stepper board pivots on it - this forms an isoceles triangle with the upper arm

A year ago i knew nothing about machining, now i'm able to machine most of the parts i need from scrap aluminum and brass. As part of this project i bought a taig lathe with a milling vice so i can do some limited small operations. My background is electronics and computers so this mechanical stuff is quite the learning curve

Having fun and looking for non cloudy nights

Regards Mark

Sounds like a fun part of your project. I might look into it myself for other projects.

It is good that you have a milling machine. I wished I could have one but I live in an apartment, unfortunately. I have bought my screws (5/16 and 1/4) and need to machine the end of the 5/16 so it can fit the coupling I am using with the stepper motor. Then I have to design a special nut for this screw that can pivot on my board (per original schematic I shared). And the machine shops are in the industrial areas of the town, hard to get a hold of and so on. I am not ready to run mine yet any ways.

Incidentally, I intend to invent a system that allows me to fully calibrate my tracker indoors before taking it out on a clear night. You might want to do something like that.

I don't know if you are on Facebook or not, but I have started a page for the purposes of this work and is called: Homebuilt Astrophotography Tracking Mount. There isn't much in it yet, and you are welcome to post there if you like.

If your electronics are all done you should think about a permanent PCB for all the wiring.

Farzad

Khosrownia: Sounds like a fun part of your project. I might look into it myself for other projects.

It is good that you have a milling machine. I wished I could have one but I live in an apartment, unfortunately. I have bought my screws (5/16 and 1/4) and need to machine the end of the 5/16 so it can fit the coupling I am using with the stepper motor. Then I have to design a special nut for this screw that can pivot on my board (per original schematic I shared). And the machine shops are in the industrial areas of the town, hard to get a hold of and so on. I am not ready to run mine yet any ways.

Incidentally, I intend to invent a system that allows me to fully calibrate my tracker indoors before taking it out on a clear night. You might want to do something like that.

I don't know if you are on Facebook or not, but I have started a page for the purposes of this work and is called: Homebuilt Astrophotography Tracking Mount. There isn't much in it yet, and you are welcome to post there if you like.

If your electronics are all done you should think about a permanent PCB for all the wiring.

Farzad

Hi Farzad,

I looked/costed getting a machine shop to machine parts but they wanted too much money for basic stuff so i opted for being my own lathe

I like the calbration idea, something i might implement once i get the basics down. What would you calibrate against ?

Final design might have a PCB depending how it goes. It seems every time i want to test the clouds roll in

I will look for your facebook page

Regards

Mark