Open Focus - Autofocus DIY Style
Written by Dave Grennan   
Sunday, 05 July 2009 21:10

Are you spending too long of those precious clear nights trying to attain that perfect focus?  If so 'Open Focus' may well be the answer. 'Open Focus' is an open source set of plans schematics and drivers for an autofocus unit which can be coupled to many common focusers and can be built at home for a small fraction of the cost of a commercially available unit.  Interested?  Click the read more link below for details.



Update: 5th November 2008 Version 1.5 driver published.  This driver removes the need for two dll files.  Also implements the 'Last Position' option in the driver which causes the focuser to remember the last position it was set to.  This negates to a degree the need for the contact switch which can be dispensed with.  The new driver and source are contained in the repository at the end of this article. To use the new driver you need to ensure that all copies of the old one are removed from your system by using regsvr32 -u <dll filename> at the command prompt.  Do not install the new driver until the old one has been removed.

Having automated almost all parts of my astronomical observatory.  Two outstanding items remained.  One is motorising the sliding roof and the second was automating my focuser.  The former is a project for a later stage, the later is now one I have dealt with to my satisfaction.  On inspecting the market and looking at the offerings available, it continued to strike me that with a bit of thought and an investment in time it should be possible to ‘home brew’ a unit to carry out this function.

And so was born the concept of ‘Open Focus’.  From the outset I decided that there would be two important facets to my project.  Firstly it would be open source.  I planned to release all of the schematics, drawings and code to the astronomical community for further development and for the benefit of my fellow astronomers.  Secondly I would design the software around ASCOM.  ASCOM is now a generally accepted standard for the production of software drivers to allow much of today’s excellent astronomy software to interact with devices in a common way.

I looked at many designs for the electronics portion of the project.  The choice of a stepper motor for the project was a ‘no-brainer’.  Stepper motors allow very precise positioning of the motor shaft in a way which is very easy to implement.  The next problem was to design a circuit that would allow various brands of motors to be used and would also allow some sort of control to limit the amount of current the motor can draw.  After a few tests I finally settled on a design which utilised the L297 stepper motor controller available as a ‘black box’ IC.  The L297 provides current limiting ability in the form of an inbuilt ‘chopper’ circuit.  Basically this works by cutting off the current to the motor when that current reaches a certain level.  This is applied in such a way that the overall current the motor draws can never exceed a predefined limit.

Fig.1 In a ‘chopper’ controlled circuit the current rises until it reaches a set limit (red line) at which point the current to the motor is switched off.

Absolute Positioning

In order to provide reliable autofocus the unit must be able to allow a reference position to be set.  I considered a couple of options.  Asking the user to set this position by returning the focuser to a predefined position (focus of a high powered eyepiece for example).  However in my final design I provided for a reference position to be set by providing a ‘contact’ which the focuser could only make in one specific position.  In most cases that would be the fully ‘racked in’ position of the focuser, but as you will see, this does not have to be the case.

Fig 2. A contact is made from a standard sewing pin which only contacts the main body of the focuser when the drawtube is fully ‘racked in’.  This allows the software to automatically set the ‘zero’ position of the focuser upon connect.

Connecting to an Existing Focuser

Connecting the stepper to the focuser would be the next problem to overcome.  Clearly with so many brands of focuser and telescope available there was to be no standard way of doing this.  Following an initial test, I found that without any gearing a stepper motor cannot provide enough torque to turn the main focus shaft without some assistance.  This ‘assistance’ had to be provided by a  reduction gear drive system.  I used some simple plastic gears to provide a rather ‘Heath-Robinson’ approach and admit freely that a commercial gearbox will provide a superior solution.  Further down the road I discovered that my existing focuser was prone to slippage and not really up to the job anyhow.  I decided to purchase a Moonlite CR1 focuser which is far more appropriate for the task of reliable, repeatable autofocusing.  The moonlite unit comes with an option of a built in stepper motor and 75:1 gearbox.  Since the price difference was not much more than the cost of a motor and a gearbox bought from a surplus store I decided to go with that.  The moonlite stepper motor is wired to the ‘Robofocus’ standard wiring and as such I arranged my own wiring to match.


Fig 3: A 3:1 gear reduction system is provided by two simple plastic gear wheels.  This provides enough torque to allow the stepper motor turn the 1:10 microfocus shaft on my focuser.  Since this is geared 10:1, I expect that in order to turn the main (non geared) focus shaft a reduction of 30:1 or more will be required.  Once you go past a gearing ratio of over 80:1 you may find the focuser moves too slow and too fine resolution for your needs

SCT users face a different problem.  Most SCT’s have a vast range of travel of the main focus wheel.  Most SCT focusers don’t stop suddenly when they are fully racked in or out.  Therefore the SCT user will need to manually set a reference point.  SCT users may well prefer a drive system utilising a drive belt type arrangement.

Main Circuitry

The Main circuitry consists of two parts;

1:  The Main Control Circuitry and Housing: This is the ‘brains’ of the operation.  It provides the stepper motor control circuitry and also the electronics to allow the unit communicate with a standard RS-232 port.  In my tests there was no problem using a standard RS-232 (Serial) to USB convertor which thus allows the unit to operate via a common USB port.


The full resolution schematics are given in the zip file accompanying this article.

The main control circuit is built from commonly available parts

4 x 100n Ceramic capacitor
5 x 1uF Ceramic capacitor
2 x 22pF Ceramic capacitor
1 x 1nF Ceramic capacitor
1 x 220uF 50v Electro. Capacitor.

1 x 4 MHz (4Mhz Crystal)

8 x 3A Fast (FR301 or UF5401) Diodes

3 x 1N4148
1 x 1N4001

1 x L298 (L298 Full Bridge Driver)
1 x L297 (L297 Stepper Driver)
1 x PIC16F628 (PIC16F628) Programmed
1 x MAX232CPE

2 x 0.5R (2W (or equivilent parallel arrangement)
1 x 3.9k
3 x 15k
1 x 4.7k
1 x 22k
1 x 39k

1 x 10K (10K Var Resistor)

1 x LM7812ACV (12v VReg, 1 amp)
1 x LM7805ACV (5v Vreg,  1 amp)


1 x 4 way PCB header and plug
1 x 3 way PCB header and plug

2 x Push To Make type switches
1 x Rocker switch (Power)
1 x Power connector (for 12v DC)

3 x male 'Sub D' 9 way connectors
3 x female 'Sub D' 9 way connectors

Suitable stepper motor (4 phase) and appropriate gearbox reducer.

The circuit is fairly straighforward to build.  I recommend using sockets for the various IC's.  You can cut up a standard DIL IC socket to make a seating for the L298 zig zag pattern.  You will need to connect the Sub D sockets to the board via signal wire.  In general you can choose to route the wires through whatever pins you choose.  However you should route the four stepper motor wires as per the 'Robofocus' arrangement. (See connecting the stepper motor) later in this article.

Once the main board is complete you should connect the various wires for input and output.  These are;

The connection points are numbered showing where to connect the various wires to the board.  The full resolution PCXB artwork and connection diagram are given in the zip file accompanying this article.

1 +12-20vDC (Power supply)
2 Ground (Power supply)
3 Hand Conroller IN
4 Hand Controller OUT
5 Hand Controller +5v
6 Minimum position contact switch.  The other side of the switch should go to any of the 5v outputs.  E.g #5
7 Stepper motor A
8 Stepper Motor A1
9 Stepper Motor B
10 Stepper Motor B1
11 Serial Port RX
12 Serial Port TX
13 Serial Port Ground

You may choose to layout the circuit above in any way you choose.  However my recommendation is to use a printed circuit board (PCB).  If you have never produced a PCB before you might be baulking right now but fear not.  A year ago I had never produced one.  A beginner should consider the ‘Toner Transfer’ method of marking the copper clad board.  A search on Google will provide many tutorials on this straightforward method.  More experienced developers will know that the ‘UV exposure’ method of transferring the pattern onto a board is superior.  See links at the end of this article for an easy to build UV exposure unit based on UV LED’s.

You may of course decide to lay out the circuit on strip-board using point to point wiring.  You should be careful however to ensure that resistors marked R1 and R2 should be kept as close to the L297 as possible and have the same length of connector to ensure no variations in the very small resistance across them.

You will need to provide connectors for the RS232 Input/Output, Hand Controller, zero point contact wires, input power, and of course the stepper motor itself.  I used standard ‘Sub D’ 9-way connector for the Hand Control, Stepper motor and RS-232.  A standard power jack was used for the power input and a ‘rocker’ switch was connected across the positive input power wire to turn the unit on and off.

Connecting the Stepper Motor

The stepper motor can be connected to the 4 outputs on the board by any means you choose.  I do however, highly recommend using the same pinout as the ‘Robofocus’ standard.  You should implement this by using a standard ‘Sub D’ 9 way connector.  Using the following pinout,

Pin 1 Coil 1+ (7 on board)
Pin 2 Coil 1- (8 on board)
Pin 3 Coil 2+ (9 on board)
Pin 4 Coil 2- (10 on board)
Pin 5 – 9 Not Connected

On some motors you may need to reverse the middle two wires (On Pins 2 and 3).  Only do this if the motor doesn’t turn when connected as shown above.  If you do not know which wires are which on your motor.  I suggest first searching on google with the motor manufacturer and exact model to see if you can find the datasheet.  Failing this you cant do too much harm by experimenting.  Usually the common leads on a unipolar motor are black and white, but this is not always so.  Once you 100% identify the common leads either cut them off  or tie them off so you don’t confuse them with the phase leads.

Connecting the RS-232 (Serial) Wires.

Standard RS232 ports use a DB9 or DB25 connector. The standard RS232 pinout is shown below.  You only need to connect the pins in boldface.

DB9 DB25 Function
1 8 Data carrier detect
2 3 Receive data
3 2 Transmit data
4 20 Data terminal ready
5 7 Signal ground
6 6 Data set ready
7 4 Request to send
8 5 Clear to send
9 22 Ring indicator

A couple of notes on the component layout.

Note the notch position of the L297 (notch to bottom)

The 2 sense resistors (R1 and R2) should be 0.5ohm.  The datasheet states that they should be 2W.  The best way to achieve this is to take 8 x 0.5watt 2ohm resistors (commonly available) and connect them in groups of 4 units connected in parallel.  This will equate to 0.5ohm at 2watts

The following diagram illustrates;

The two wires to the hand controller are reversible depending on which button (in or out) you want on top.  In the connection diagram number 4 is step out and number 3 is step in.  All points marked L(X) on the layout diagram are for linker wire.  Link each pair of L(X) points e.g. L1 – L1, L2 – L2, ….. and so on.

The ASCOM Driver.

Of course the whole point of developing this application is to enable it to work with existing autofocusing software.  In my tests I have successfully interfaced Open Focus with Maxim DL, and FocusMax.  The development of an ASCOM driver means that Open Focus will work with any ASCOM compliant software.  To read more about ASCOM and download the latest version of the ASCOM platform (which you will need) go to

This is what the setup screen should look like once the driver is installed. Select the COMM port to which the focuser is attacted and click 'Test Connect'.  If all is well you should get a message back to say that the connection tested successfully.  If you do not you need to look at all the connections and the circuit. (Check the serial; wires are going to the right pins).

The current version of the ascom driver is still a beta version so use it at your own risk.   Currently known issues are;

Only 'Home Position' connection option is currently implemented.
'Set Max' position button not yet implemented.

Upon connection, the focuser will slew inward until the connection wires are closed.  This represents the home position of the focuser.  Once this happens the focuser should show connected and be available for use.

A full installer and source code (Visual Basic) for the driver is included in the zip file accompanying this article

Installation Hints;Here are some photos showing how I attached the stepper motors to various scopes/focusers. Also included are some photos of my prototype Open Focus.

The prototype 'Open Focus' cracked open.  Note the use of headers and plugs on the board.  Also note the use of a heatsink on the 5v regulatro.  This is probably not necessary but as it gets a bit hot and I had one spare, I used it.  The blue and silver switch seen is not necessary it was used for me to test the current draw of the circuit.  My unit draws 0.35amps. The front face of my unit.  9 Way 'Sub D' connectors are widely used.  The two wires for the reference position contact switch are routed through the HC connector.  The rocker switch is connected across the positive power line.
My Moonlite CR1 focuser is shown here.  Of note is how I implemented the reference position contact switch.  This is seen as the nut and bolt arrangement.  One wire of the contact switch is connected to the nut/bolt arrangement which is in turn clamped (using the bolts) to the lip of the draw tube.  The other wire is connected to one of the mounting nuts.  When the focuser slews in the nut contacts the bearing nut (just to its right in the photo)  When this happens the circuit is made and the focuser stops slewing.  The nice thing is this is acheived without invading (drilling) the focuser.  The lenght of the bolt can be adjusted to preciselt set the reference position. A bipolar stepper motor and gearbox (salvaged from an old mount) is seen attached to my Celestron 80ED 'Onyx' refractor.  The coupling is known as an 'Oldham coupling' and the bracket was made from some scrap aluminium.  REMEMBER you must use a gear reduction system to provide enough torque to turn the focus knob.  In the motor shown above a 40:1 gearbox is already built in.

Conclusion, Repository Zip File and License Agreement

Please note that as of this time I am not in a position to supply assembled boards or complete units. I simply do not have the time for this. If there is sufficient interest in this project I may be able to acquire a run of PCB's at a reasonable cost. Please let me know if this is something you are interested in. I provide here a zip file containing all of the files you will need to get this project up and running.

If I have ommitted anything important or if you have any questions, please feel free to contact me by clicking here

This project is a true open source project. I provide all of the source code, drivers, schematics etc which I have invested a lot of time in. What I would like to see is the community taking this further and adding to the project. If you have made a useful improvement to any part of this project please send it to me and I will include it giving you the full credit you deserve. However to ensure the spirit of open source is maintained, I require that all persons downloading the zip file repository read and accept the following license agreement. Should the spirit of this agreement be breached I can and will pursue to the fullest extent of the law.  This particularly applies to anyone trying to make money out of this project.

License Agreement

This license agreement is governed by the laws of the Republic of Ireland. The author of 'Open Focus' is David Grennan.

A licence is granted free of charge to use the software, source code, schematics and documents contained in the zip file linked below.

The user may use this at his/her own risk. The author accepts no liability for any losses howsoever caused resulting from the use of these files.

The user may modify these files in any way subject to the condition that he/she sends a copy of any modified files along with relevent documentation to the author. The author can be contacted by clicking here.

These files may not be redistributed on any other website by any persons other than the author and those persons who have made a recognised contribution to this project by supplying improvements modifications to the author.

None of the work presented here may be used in any commercial product, in any shape or form without the express and written permission of the author.

Persons under 18 years of age are not permitted to enter such an agreement in certain countries.  If you are under 18, you must get a parent or guardian to agree to the license agreement on your behalf.

By clicking on the link given below and downloading the files you hereby agree in total to the terms of the agreement given above.

I agree to the terms and conditions above.


Latest Images

CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error CF-Error