Page 1 of 5 1 2 3 ... LastLast
Results 1 to 10 of 44

Thread: Motorized macro rail on the cheap

  1. #1
    Senior Member
    Join Date
    Mar 2010
    Location
    Croatia
    Posts
    101

    Default Motorized macro rail on the cheap

    Note to the Picaxe forum members: I link here from a few other (non-electronics) forums so I explain some things you already know. Just skip that bits.

    I love macro photography and as anyone who has ever tried it will know, extremely thin depth of field (here we are often talking about 0.1mm and below) can be a real problem as the object we are photographing is usually significantly larger. The higher the magnification you use the less of the photo ends up in sharp focus. This problem is typically solved by taking multiple photos with a slightly different focus point and later combining them to produce the final image where everything of importance is in focus. One such software is the excellent Zerene stacker that will do all the work for you. You still need to take a bunch of photos of the same object that differ only in the focus point - and by 'bunch' I mean sometimes more than 50!

    For that reason I went to design an automatic macro rail that can very precisely move a small object back and forward a few centimeters. The macro rail had to be able to:
    - move in user selectable steps from 0.01mm to about 1mm
    - continuously slide (fast) for the initial focusing
    - memorise the start and the end positions for the focus stack
    - compensate for the 'slack' in sprockets when changing the direction
    - control my Canon dSLR and automatically take the photos once everything has been set
    - remember some settings between the runs (step size)
    - I had to build it from easily available 'junk' as I wasn't prepared to pay more than $20
    - simple and quick to build - no heavy machinery required
    - controlled by a smallest and cheapest micro-controller I head - the Picaxe 08m
    - remote controlled to minimize the possibility of accidentally moving the camera or the subject

    I actually managed to do this utilising only the parts I already had in the house (so it didn't cost me a penny while similar rails can be bought for close to $500!). All I needed was an old, broken DVD-ROM drive (for a very nice rail it contains), a unipolar stepper motor (from an ancient 5.25" floppy drive - remember those?), the Picaxe 08m, and a few standard electronic components.

    Here is the result:

    First, watch the video!


    (a bigger version).
    IMPORTANT NOTE: I have made a mistake when drawing the diagram. The wire that connects the input pin 2 of the ULN2003A to the output pin 6 (veroboard strip 12 to 16) should be connected to ULN pin 1 (strip 11), not 2!

    Ok, now forget my ugly scribble and download the excellent multi-layered Photoshop drawing that SteveD has made:
    http://www.stevedargie.pwp.blueyonde...ds/circuit.psd

    Putting together the mechanical part of the project couldn't have been simpler. Apart from dissembling the CD-ROM all I had to do was superglue a plastic bottle cap to the first sprocket (that would normally be rotated by a small motor which I have actually left in place and simply not use) and add a unipolar stepper motor. These two are connected by a rubber band, and that's it! :) If you use a bipolar stepper you'll have to use a larger Picaxe and also rewrite the code so I don't recommend it.

    The electronics are also quite simple and should provide little challenge to someone who knows how to solder. Buy a veroboard (stripboard), cut to size and just follow the circuit diagram.
    Where there is an 'X' in the diagram cut the copper strip.
    The IR receiver (that thing to the right/below the 08m) used is the TSOP1138. Wiring the stepper is a bit tricky as you have to guess the correct order of the wires. This is how you can do it:
    1. Use a multimeter to measure the resistance between different pairs of wires. Two numbers should keep appearing - one resistance will be twice smaller than the other. If you have a 5 wire motor then there will be one wire that will give this 'half-resistance' to any other wire. Mark this wire. If you have a 6 wire stepper you will find two such wires with the difference that not all the wire pairs will be internally connected (there will be two sets of wires that are connected). Mark both these wires.
    2. Glue a long paper 'pointer' to the stepper (so you can easily see in which direction it turns). Connect the previously marked wire(s) to the battery + side (4AA battery pack should work fine). Experiment connecting the 4 wires that are left to the battery - side, one at the time. The goal is to find the right sequence (1,2,3,4,1,2,3,4....) that will make the motor turn. Mark the wires 1,2,3 and 4.
    3. When connecting the stepper to the board connect in order (from left to right): 1,3,2,4
    Hopefully the sequence will be correct.

    After you have put all of it together, it's time to program the micro-controller. How to do this is better explained in the Picaxe manual (free download from their site). Basically all you need is a serial (or USB to serial) cable and a diagram from the manual describing which wire to connect where (you need to connect three wires to the bottom left of the board, marked -, RX and TX). You also need to connect a 5V power supply (4 AA NiMH batteries work great). If you want you can also connect a small switch on the '+' wire from the battery.

    Once everything is set, here is the code you need to send to your board:
    Code:
    ' Macro focus rail driver
    ' Unipolar stepper (12V 1.8deg) connected to ULN2003A:
    '    green, white, red, brown -> Out1-Out4
    '    08m 2 -> ULN In2
    '    08m 1 -> ULN In3
    ' Out4 -> optocoupler for shutter triggering (tip+, sleave-)
    ' IR detector codes:
    '    CH+      back focus
    '    CH-      front focus
    '    NN       steps in one slide (in 0.01mm)
    '    AV/TV    the next slide will be continuous (any key to interrupt)
    '    Vol-     mark focus (front) and start moving focus back; mark focus end by any key
    '		slide to the front of the stack
    '    Power    start shooting
    
    symbol slack = 5          ' how many micro steps to add when changing direction 
    symbol steppause = 1   ' larger number will make it go slower 
    '                                  - useful if you have a stepper with very few steps per revolution
    
    symbol stepc     = b0
    symbol s 	= b1
    symbol i 	= b2
    symbol direction = b3
    symbol nsteps    = b4
    symbol nframes   = b5
    symbol nslide    = b6
    symbol j	 = b7
    symbol irflag    = b8
    symbol olddir    = b9
    symbol contflag  = b10
    
    high 1
    high 2
    low 4
    
    '           (nsteps)
    eeprom 0, (20)
    
    read 0, nsteps
    
    contflag=0
    
    main:
    	infrain2
    	if infra<10 then
    		infra=infra+1
    		infra=infra//10
    		nsteps=infra*10
    		pause 500
    		infrain2
    		infra=infra+1
    		infra=infra//10
    		nsteps=nsteps+infra
    		write 0, nsteps
    	elseif infra=37 then
    		contflag=1
    		pause 500
    		infrain2
    		pause 500
    	endif
    	select infra
    	case 17 ' front focus
    		direction=2
    		gosub slide
    	case 16 ' back focus
    		direction=0
    		gosub slide
    	case 19 ' Vol-  - mark focus start
    		nslide=0
    		irflag=0
    		pause 200
    		do
    			pause 200
    			direction=0
    			gosub slide
    			nslide=nslide+1
    			'pause 200
    		loop while irflag=0
    		pause 2000
    		for j=1 to nslide
    			direction=2
    			gosub slide
    		next j
    		gosub slide
    		direction=0
    		gosub slide
    	case 21 ' Power - start shooting run
    		gosub shoot
    		for j=1 to nslide
    			direction=0
    			gosub slide
    			gosub shoot
    		next j
    	endselect
    	'debug
    	pause 500
    	goto main
    
    shoot:
    	pause 5000    
    	high 4	' shoot
    	pause 400
    	low 4
    	pause 3000    ' wait before the next slide (exposure time)
    	return
    
    	
    slide:
    	if direction<>olddir then	' remove sprocket slack
    		for i=1 to slack
    			gosub onestep
    		next i 
    	endif
    	irflag=0
    lup:
    	for i=1 to nsteps
    		gosub onestep
    		pause steppause
    	next i
    	if irflag=0 AND contflag=1 then goto lup
    	contflag=0
    	olddir=direction
    	return
    
    onestep:
    '	s=direction*2
    	stepc=stepc+direction-1
    	let stepc=stepc // 4
    	lookup stepc, (%00000110, %00000100, %00000000, %00000010), s
    	let pins=s
    	if pin3=0 then
    		irflag=1
    	endif
    	'pause 1
    	return
    The rail is completely controlled through an IR remote (any universal remote that can be programmed to use Sony TV codes). You simply type in a two digit number to change the size of one slide (as it happens, almost exactly in 0.01mm units in my case). CH+/- will make one forward/backward slide. If you press the AV/TV key before the CH then the slide is continuous in that direction until any key is pressed. Once you have moved your object to a starting position of a focus stack you press the Vol-. That starts the gradual slide which you are supposed to interrupt (any key press) when the end point of the focus stack is reached. The rail will then reset to the starting position remembering the number of steps needed. The Power button starts the take-the-shot, move, take-the-shot... loop.

    Once all the photos have been taken you use a Zerene stacker (or similar software) to make the focus stack. These programs are usually designed to be used even with hand-held photos so giving them such a perfect series usually results in a perfect stack even on 'full automatic'.

    There you have it :) A useful project for macro photographers with an extremely easy to put together mechanics (old CD/DVD-ROMS or writers are easily obtainable) and a few cheap electronic parts. Once you have all the parts the whole thing can be put together over the weekend.

    Here is just one example of a small 4mm speck of soil from a potted plant. This is how one frame looks like:


    Notice the extremely thin 'slice' that is in focus (about 0.12mm wide)! And here is a result from a stack of 35 photos taken 0.09mm apart:

    I believe the difference is obvious :)

    As an added bonus the exactly same setup can be used to automatically build a 360deg product rotation animations! :)
    Last edited by dsvilko; 27-01-2013 at 08:45.

  2. #2
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    854

    Default

    That's really slick!

    I'm assuming you clip the 'subject' there in the center. How do you handle the background for the macro shot?

    It is hard to tell from your photo what exactly is moving.

    How about some of the resulting photos?

  3. #3
    Senior Member
    Join Date
    Mar 2010
    Location
    Croatia
    Posts
    101

    Default

    Quote Originally Posted by Texasclodhopper View Post
    That's really slick!

    I'm assuming you clip the 'subject' there in the center. How do you handle the background for the macro shot?
    With the depth of field (how much is 'sharp' on the photo) measured in 1/10mm, all I can say is 'what background?' :) Everything more distant than 1cm behind the subject is completely destroyed by the background blur. You can only decide which colour background you want and put something (anything) of that colour there.

    As for mounting the subject, you are right. For now there is a simple clip that can either hold the subject or as L profile to rest the subject on.
    Last edited by dsvilko; 05-01-2011 at 16:54.

  4. #4

    Default

    This is an amazing project. I've been wanting to do something like it for ages. Bravo.

    Are you using the CD motor or did you install a different motor?

    I will be taking apart a bad cd drive as soon as I get home. I burn a lot of DVD backups and regularly have to replace the drives. I think the mechanical parts are fine, since they can read the media, the issue is in the writing...glad I did not toss them out.

  5. #5
    Senior Member
    Join Date
    Mar 2010
    Location
    Croatia
    Posts
    101

    Default

    Quote Originally Posted by julianE View Post
    This is an amazing project. I've been wanting to do something like it for ages. Bravo.

    Are you using the CD motor or did you install a different motor?

    I will be taking apart a bad cd drive as soon as I get home. I burn a lot of DVD backups and regularly have to replace the drives. I think the mechanical parts are fine, since they can read the media, the issue is in the writing...glad I did not toss them out.
    The mechanics are almost certainly fine. I have decided not to use the original solar motor because it's much harder to precisely control than the unipolar stepper I am using. I didn't even bother removing the original motor. All I did was glue a plastic bottle cap onto the large sprocket the motor is connected to and screw the stepper to the board using one of the existing holes (it's held by just one screw but it's completely solid). Add a rubber band and you are done :) Couldn't be simpler. It your DVD is anything like mine you can finish the mechanical part in 10 minutes.

    Old CD/DVD drives are a simply amazing source of mechanical parts (motors, rails, sprocket assemblies...). The same drive that 'donated' it's rail assembly previously gave me enough parts to build a 1-D automatic panorama head:
    http://www.youtube.com/watch?v=UFjerJWB5Hs (from the early stage of development)

  6. #6
    Moderator
    Join Date
    Jan 1970
    Location
    Middle England
    Posts
    5,921
    Blog Entries
    1

    Default

    Excellent and congratulations.

    A non-Picaxe question:
    What software did you use for
    the combination shot in post #3?


    e

  7. #7
    Senior Member
    Join Date
    Mar 2010
    Location
    Croatia
    Posts
    101

    Default

    Quote Originally Posted by eclectic View Post
    Excellent and congratulations.

    A non-Picaxe question:
    What software did you use for
    the combination shot in post #3?
    Thanks!
    I have used a evaluation copy of the Zerene stacker. As this is my first stack with this software I am sure there is a lot of room for improvement.

  8. #8
    Moderator
    Join Date
    Jan 1970
    Location
    Middle England
    Posts
    5,921
    Blog Entries
    1

    Default

    Quote Originally Posted by dsvilko View Post
    Thanks!
    I have used a evaluation copy of the Zerene stacker. As this is my first stack with this software I am sure there is a lot of room for improvement.
    But it's still an excellent first attempt. :-)

    Thanks for the info,
    and congratulations again.

    e

  9. #9

    Default

    That is impressive , well done.

  10. #10
    Senior Member
    Join Date
    Mar 2010
    Location
    Croatia
    Posts
    101

    Default

    Quote Originally Posted by eclectic View Post
    But it's still an excellent first attempt. :-)

    Thanks for the info,
    and congratulations again.

    e
    Well, it the software could dream, the Zerene stacker would dream of stacking such a perfect series of photos, already precisely aligned and equally spaced in focus points :) It's no wonder that even without fiddling with advanced settings I got a decent result.
    My next task is finding a subject with enough detail to look interesting on that scale. Typically nothing man-made comes close and in a dead of winter the 'natural stuff' is not readily available. :(

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •