Arduino Focuser

Autofocus software completely updated:
Uses multiple v-curves to calculate best focus position.  Approaches the best focus position without direction changes, eliminating the need for backlash compensation. (based on the theory presented by Larry Weber and Steve Brady - of FocusMax)
*******    Just want to try it?   Use the lite version    *******
Use with AdruinoCode_Lite.  Has all the same autofocus capabilities without the keypad, rotary encoder and LDC on the Arduino.  It may even work with other stepper drivers.  Ultimately, I would like to make this ASCOM compliant.
Automatically obtain several V-curves to allow for best focus position calculation.  (Actual star, a bit over-exposed)

YouTube Video

After obtaining several v-curves, "Goto Focus" moves to the calculated best focus position as seen below. 

YouTube Video

 Video of Autofocus software with star simulator -- complete process:
1) finding initial rough focus point  
2) analyzing intial fine v-curve to establish linear portion and define min/max HFR to use for calculations
3) obtain additional v-curve to use for calculation
4) moving to the best focus point.

Autofocus - Version 3

Arduino Connections:
Rotary Encoder:
    A --> pin 2(green)
    B --> pin 3(red)
    C --> gnd (black)
Speed selection for Manual Mode
   Arduino pin 14 (A0) to ground increases speed by programmed amount
   Use yellow from RJ-11 to rotary encoder box with momentary switch (nl. open) connects gnd when pushed
LCD display (NetMedia Serial 4x20 Red)
    Rx* --> pin 1
    LED+ --> 12v
Pololu Stepper driver(A4983) #1202:
   To Arduino:
    DIR --> pin 4
    STEP --> pin 13
    ENABLE --> pin 15 (A1)
    MS1 --> pin 16 (A2) (MS1 and MS2 HIGH for 1/8 step)
    MS2--> pin 17  (A3)
    Vcc --> 5v on Arduino and LCD(allows for single power 12v power supply)
    1B,1A,2A,2B --> stepper
    VMOT --> 12 v
Keypad connections are listed in the Arduino code
Arduino setup/use:
Download and install the .pde file.  Requires TimedAction, keypad and EEPROM libraries.   Change Direction if needed (#,#,D,C).  Set Maximum travel to 9999 (#,#,A) then determine actual maximum travel going to full backfocus, then enter appropriate value.    Adjust Stepper delay (#,#,D,B).  This defines delay between step pulses (pulse width is fixed at 10 us).  "High speed" sets the number of steps per rotary encoder click when the high speed button is pushed.   These settings are stored in EEPROM so this is a one-time setup.  Backlight can be adjusted via the rotary encoder (#,#,B) (not stored).
The letter buttons (A-D) can be used for presets.   Once you achieve perfect focus with a specific eyepiece, hit one of the letters, it will ask you to confirm, that position is now stored in EPROM.  To go to that position, push  # then the letter.  This can also be used with a camera setup to store the near focus point.   
Autofocus software requirements:
Windows(XP/Vist/7),  Nebulosity and the Arduino focus unit described here(will not work w/ any other...yet)
Make sure you have a directory c:\windows\temp (necessary for installation, change on first use).  Run setup.exe.  scopefocus should show up in the Start menu.  Install the Arduino Code below(.pde). This is very 'beta' but works....updates will continue.
Autofocus software setup/use:
The autofocus software will automatically detect the arduino and connect(Connect button turns green).  If there are multiple serial devices you will have to select the port from the pull-down.
Select the directory that coincides the directory selection in Nebulosity.   Select equipment (double click to edit, these are saved).  The max focus and stepper delay are display only and must be set in the Arduino setup menu( #,#,A and #,#,D,B - respectively).  That's all that is needed for basic use. 
Utilize a star that is approximately mag 4.  With Nebulosity running in Fine Focus mode and the directories are matched, click the "Control" tab, move focus out to a position that is close to (but NOT past) the focus point.  Set step size and N to obtain a rough V-curve.  (so it goes past the focus point, going out).  Set the camera exposure time in Nebulosity so it's not saturating.  If less than 0.5 seconds, use the "Exposures" selection to use multiple exposures such that the total time for each position is at least 0.5 seconds.  Now set the Fine V to the values you'll use for a more accurate V-curve (e.g. N=40, step size 2 -- depends on stepper, gear ratio, etc...) Obtain a 'Fine V-curve' with the Calculations button OFF.  The v-curve should be centered fairly well depending on how accurate the rough V-curve was.  Repeat if not symmetric.  Next, look at the curve and select Min/Max HFR (note all HFR are times 100).  This defines the range of HFR to be used for slope calculation.  It should represent the linear portion of the  V-curve.(e.g. min 150, max 300).  Click the "Calculation On" button and obtain another V-curve.  If min/max are acceptable you can set "Fine V repeat to perform multiple repeat v-curves (10-20).  Review the data chart(botton of screen) and make sure there are no outliers.  If needed, select the # cell (only) for the row to delete and click "Delete Selected".  Click "Update" to populate the slope UP/DWN and PID fields.  Click "Goto Focus" and it will obtain 10 exposures, average the HFR's then calculate and go to the best focus position. You can use either the up or down slope, which ever seems most consistent, future update will analyze the data to help decide. 
Subsequent use for specified equipment, only need to perform a rough V-curve (additional Fine V-curve is optional) to establish near focus, click "Update" then "Goto Focus".
The "Sync" button allows for manual focus changes via keypad or rotary encoder. 
If you would like to correct for backlash(optional), click the "Backlash" button.  It will cycle in/out multiple times and determine the focus point without taking up backlash.  The difference in OUT versus IN focus point should equal the backlash.  This can be compensated for by entering the value in the Arduino setup menu (#,#,D,A).  This is not necessary since the autofocus routine goes to the focus point from one direction. 
Future --"Tempcal" performs multiple repeated Fine V curves and plots the focus position versus temp.  (Arduino not yet programmed for thermistor connection --pending).
Stepper Motor:
The stepper (Soyo SY57ST56-1206A Unipolar 6v 1.2A) is mounted from the finder scope mounts using aluminum (1/8" x 1").   The focus/motor shafts are coupled with a zero backlash flexible coupler (like this one).  This coupler was a key element in achieving smooth operation of this setup.   

Updated firmware:ArduinoFirmware_AccelStepper_rev1   requires accelstepper from here (  gradual speed changes help reduce slippage.  For stepper without gear reduction decrease stepper speed.  In arduino sketch, goto init tab, change stepper.setMaxSpeed to lower value.  Try 200 and adjust as needed.  Also set stepper.setAcceleration to around 1000.   

NEW ASCOM driver: ScopefocusArduinoASCOM_Driver6_0_0) should work with any ASCOM capable software.  unzip and install by double clicking scopefocusArdiuno setup.exe.   (readme is still pending) 

Older versions: 
New Lite Version 11/3/13 -- works with ASCOM SGL focuser 
New Version 4 5/23/12 -- Added filterwheel control and automation control fro CGEM
New Version(3) 11/24/11 - Uses slope calculation from multiple v-curves and many more improvements 
Updated 8/3/2011 -- Improved torque, uses EPROM, Setup menu (see updates page) 
Updated 7/19/2011 -- Improvements (see updates page) 
Updated 6/16/2011 -- Major improvements
Updated 6/18/2011 -- added sync button to allow for rotary encoder movements while using autofocus program.   Pushing this after manual movement will sync the software position with the Arduino current position.

Kevin Sipprell,
May 23, 2012, 3:10 PM
Kevin Sipprell,
Nov 26, 2011, 7:16 PM
Kevin Sipprell,
May 16, 2014, 3:44 PM
Kevin Sipprell,
Dec 9, 2011, 5:20 AM
Kevin Sipprell,
Nov 3, 2013, 3:42 PM
Kevin Sipprell,
May 16, 2014, 3:46 PM
Kevin Sipprell,
May 23, 2012, 3:10 PM