Saturday, April 16, 2016

Adventures in Building a Stepper-based Autofocuser

Sequence Generator Pro has many powerful capabilities for automating the process of capturing images. One of these is the ability to use a motorized focuser to automatically focus based on the apparent sizes of the star images. This is important because the focal position can shift significantly during a session, especially if the temperature is changing and the optical tube undergoes thermal expansion or contraction. Fortunately, here in Utah the temperature usually remains pretty stable at night once the sun goes down, but this is not always the case. So until now I have tended to focus at the beginning of my session, perhaps refocus before going to bed, and then just take my chances. Obviously it would be better to refocus periodically, especially if the temperature is changing. SGP has the capability to do that if you have hardware that is supported.

When I first began using SGP, I attempted to autofocus with the Orion Accufocus + Shoestring Astronomy FCUSB controller I have used for a long time. While this system works fine for remote, manual focusing, this is a DC focus motor with some hysteresis, meaning that focus positions are not terribly reproducible. Shoestring has an ASCOM driver with an option to mimic an absolute position-capable focuser (which a DC focuser is not, but can sometimes approximate if well adjusted). I guess some people have been able to make that work, but I couldn’t successfully do automatic focusing with the DC motor, and in fact when I tried I tended to make my focus a lot worse.

So I looked into stepper motor driven autofocus systems. In contrast to DC motor-based systems, stepper-based systems retain absolute focus positions so can repeatedly return to the same focal distance (within limits, of course). Commercial stepper-based systems tend to be relatively expensive, however; the least expensive systems I found in online searching cost more than $400.

Googling also found a “do-it-yourself” solution, MyFocuserPro, developed by Robert Brown in New Zealand and posted on SourceForge as "Arduino ASCOM Focuser Pro DIY." This system is controlled by an Arduino Nano, which has an on-board USB port to talk with the computer that controls the session. This project was attractive to me because it looked considerably easier to do than the PicGoto I had already done, and because it comes complete with a Windows-based control application and most importantly, ASCOM drivers that would allow me to use it with Sequence Generator Pro or other control software. On the other hand, I am a complete novice to Arduino-controlled systems and went into this not even knowing how to load code into an Arduino. 

One of the difficulties with this project is that it comes with a huge range of options in Arduinos, motor controllers, stepper motors, wifi vs. Bluetooth vs. IR vs. USB, etc. Frankly, it was pretty confusing. So deciding on which options I wanted was a big issue. I initially decided to go with the recommended “HW203_DRV8825” option, which uses an Arduino Nano and a DRV8825 motor power board and a high-torque, extensive microstep-capable NEMA17-PG27 stepper motor. Because I have experience with vero board and none with making my own printed circuit boards, I decided to go the vero board route. I wanted a temperature probe so I could refocus when the temperature changes, but didn’t care about an LCD display too much, so I decided to build the “minimal” option + temperature probe.

I started ordering parts, mostly from Ebay and mostly coming from China. I rounded it out with a bunch of parts from Mouser. It is simply amazing what you can get in electronic parts for very little money. More than half the total cost was for the stepper motor, and the whole thing adds up to less than $100 (and I could have done better, had I been a little more careful). As I started assembling things, I realized I really would need pushbuttons to focus at the scope, and before long I had ordered the rest of the parts for the “Full” option with pushbuttons and an LCD display.

The board was pretty straightforward to assemble, but I made a few mistakes. One of these involved forgetting one trace cut on the vero board, which left the “receive” pin on the Arduino shorted to ground. Needless to say, when I powered it up I couldn’t talk to the Arduino! I also tried to use a 5 V LED in a place where a 12 V LED was called for, and I discovered that 5 V LEDs burn out under those conditions.

Then I loaded up the Arduino programming environment and started testing, and started having problems. As I mentioned above, at first I couldn’t even talk to the Arduino. I thought maybe that was because I was trying to program from Mac OSX El Capitan and there are apparently known problems running Arduinos under the El Capitan operating system. So I loaded the Windows software in my Windows 7 VMWare virtual machine and had the same problems. That's when I discovered the forgotten trace cut. Once that was sorted out, the LED/pushbutton test worked and the test of the temperature probe worked, but I could never get the stepper to move or get any characters on the LCD. After fumbling around and not getting anywhere, I eventually decided to go on the SourceForge discussion group and start asking questions.


This is when I discovered another wonderful thing about the MyFocuser Pro project: Robert Brown gives absolutely phenomenal support! He has patiently walked me through troubleshooting that has established that the DRV8825 board and the LCD are both bad (I probably damaged the DRV8825 in my initial fumbling around, and the LCD came with a short on the board that fried it, so I guess in a sense it was defective from the beginning). But these parts are so cheap that there is essentially no risk (at least if you are patient). I finally have the Windows application talking to my board and reading temperatures, but still can’t move the motor (because the motor board is dead). I have now mounted my parts in a project box and am waiting for the new DRV8825 and LCD components to arrive on the slow boat from China. I’m confident that with Robert’s help I’ll soon have this thing working. I’ll post pictures once I get it all going (but be forewarned that my “fit and finish” are not too pretty!).