Hardware h1.3

= Overview =
The device consists of three separate blocks: 
# The controller unit (125x80x32 mm plastic enclosure), containing most of electronics: Arduino Uno R3, BigEasyDriver motor driver board, Nokia 5110 LCD display, 4x4 keypad, and a small breadboard with a few components (resistors, capacitors, and an RJ-45 connector);
# The motor unit: stepper motor attached to the Velbon Mag Slider macro rail with two steel brackets and a shaft-to-focusing-knob coupler, in an aluminum DIY enclosure, with a small breadboard (two relays, two diodes, two resistors, connectors: RJ-45 and 3.5mm stereo-phone socket, to connect to the camera.) The other addition is two limiting micro-switches glued to the plastic top of the macro rail - this is essential to prevent the rail hitting the two physical limits while in operation. (Once properly calibrated, the rail is programmed to never hit the switches. Re-calibration should be rarely required, and is easily accomplished by pressing a two-key command "#C".)
# The battery unit: a flat plastic enclosure for 8 AA rechargeable batteries, with a switch and a plug matching the power socket on Arduino board. This can be attached to the bottom of the controller unit using Velcro pads. The whole module was purchased on ebay; no modifications were required. The macro rail can also be powered with an external AC-DC adapter which produces ~12.0V without load and at least 1.5A.
I use a standard Ethernet (Cat 5/6) patch cable to connect the controller unit to the motor unit (this is the only cable connecting the two modules). The cable has 8 wires, and handles everything: driving the stepper motor (4 wires), driving the camera shutter and autofocus (two wires), reading the limiting switches on the rail (one wire), plus the common ground wire. Only straight 8-wire Ethernet patch cables can be used (with my design, connecting a crossover cable by accident shouldn't damage anything, but don't take any chances!). Also, since h1.3 only AWG 24 or 22 versions of Cat5 cables can be used; other kinds are too thin and will likely melt after prolonged use. One of the important advantages of Ethernet patch cables compared to many other types of cables is the fact that Cat 5/6 connectors securely lock to sockets, so the chance of disconnecting during the rail operation is minimized. This is critical, as disconnecting the stepper motor cable during its operation will likely fry the motor driver circuits. The controller unit is programmed to detect if the cable is not attached to the motor module when it is powered on, and produce a corresponding warning.
Here is the list of the essential parts I used (USD; prices include shipping):
Part 	Price ($)	Comments
Velbon Super Mag Slider 	109.93 	Likely the cheapest decent quality manual focusing rail you can find. Has both a focusing knob (this is the one which will be driven by the stepper motor in this project) and a side motion knob (remains fully functional in this project). The rail remains fully functional for its original purpose (manual focusing) after the modifications; one has to simply unscrew the motor unit and remove the two micro-switches glued to the plastic cover of the rail.
Stepper motor 	8.80 	New in h1.3. Nema 17 stepper motor with low enough resistance (2.1 Ohm per coil) and high enough amperage (1.33A per coil) to provide very decent torque when powered from 10V (8 AA batteries) or 12V AC adapter. 4 wires, 1.8 degrees steps.
Arduino Uno R3 (knockoff) 	4.39 	
Nokia 5110 display 	2.50 	LCD display. Be careful - different models have different pin numbering, so only pay attention to the names of the pins, not their numbers!
Big Easy Driver 1.2 motor driver 	4.15 	New in h1.3. Stepper motor driver with 16 microsteps/step (default) and up to 2A/coil rating. Has a tiny pot which I set to the maximum motor current my motor + AC adapter can handle (1.4A/coil), to maximize the torque. Some parts can get extremely hot (>100 C) which is normal.
8 batteries box 	2.49 	Very convenient 8-AA battery holder: flat, the size matches nicely that of the controller enclosure, has a power switch, the power plug matches exactly the power socket of the Arduino Uno board. I attach it to the bottom of the controller unit using a few Velcro pads.
4x4 keypad 	2.68 	These are real (comfortable) keys, not a cheap membrane keyboard.
Two relays SIP-1A05 	1.98 	To independently operate the camera shutter and autofocus.
Female headers 	0.99 	To make female connectors for your controller unit, to connect different boards.
Stereo headphone socket 3.5 mm 	1.99 	The price is for 5 pieces; you need only one. This is to connect your camera to the motor unit. One could also use 2.5mm stereo socket (which would match the Yongnuo shutter cable available for Canon and Nikon DSLRs), but only the 3.5mm model can be found as a screw type, which makes it more durable.
Motor brass coupler 5-7mm 	2.55 	New in h1.3. This coupler likely will not work for you. You'll have to find a coupler with the 5mm hole on one side (for the motor shaft), and a hole matching the screw you attach to the focusing knob on the other side.
Two RJ45 sockets 	1.98 	One goes inside the motor unit, the other one - inside the controller unit.
Fifty M3 x 12mm countersunk machine screws	3.00 	Great to attach boards to the plastic controller unit enclosure, and DIY aluminum motor unit enclosure, so that the bolt heads are not protruding.
Plastic enclosure, 135x80x32mm 	3.81 	Probably the smallest enclosure you can find on ebay which would fit all the controller unit boards.
Resistors 	- 	0.5W: 33R (x2); 0.25W: 330R, 10k (x4), 47k, 270k, 360k
Capacitors 	- 	0.1 μF (x2), 10μF x 10V
Diodes 	- 	1N4004 (x2)
I already had some other parts (nuts and bolts, wires, sheet metal for DIY brackets and metal enclosure, breadboards etc.). I couldn't find good micro-switches (small enough, but with fairly long levers - should have at least 2 mm travel distance) on ebay, but I managed to find good ones in a local surplus store, 1$ apiece.
The essential non-trivial tools you'll need:
* Drill press with a drill press vise. I almost ruined my Velbon Mag Slider by trying to drill the holes for the motor brackets with a hand-held drill. The Velbon is made of a special kind of hardened magnesium alloy, with the nasty property that when one uses a hand drill to make a hole, the drill bit travels a lot sideways (can be 2-3 mm), which will make it impossible to attach motor brackets properly. I ended up buying a drill press because of this. (But I always wanted to have one.) With a drill press one can do a much better job - just make sure the head doesn't move much sideways (<0.5 mm), and make the exposed part of your drill bit fairly short (so it doesn't bend much).
* Taps and dies set. You'll need these to cut a thread (M4 is about right) in the Velbon rail, for four bolts, to attach two motor brackets to the rail.
* Fret saw (or coping saw): to make rectangular holes in the plastic (controller unit) and aluminum (motor unit) enclosures - for two RJ-45 sockets, USB socket, Nokia LCD display, and 16-keys keypad.
= Motor unit =
https://farm1.staticflickr.com/624/22415906356_6bec5e1f26.jpg
https://farm6.staticflickr.com/5619/21819185734_437afa13b0.jpg
https://farm9.staticflickr.com/8619/29501421052_74a3fd3b25.jpg
https://farm9.staticflickr.com/8432/29501417292_7650c0458e.jpg
The most critical step (don't do anything else until/unless you've succeeded with this one): proper coupling between the stepper motor and the focusing knob of the Velbon rail. Unfortunately the core of the focusing knob is made of (very hard) plastic, not metal:
https://farm1.staticflickr.com/540/19024458298_c5459b24db.jpg
In addition, it has a hole in the middle (you'll see it once you remove the rubber covering of the knob), so one has to be very careful with creating the coupling to the motor:
https://farm1.staticflickr.com/321/19025886439_bd4f33db1a_n.jpg
May be I was lucky, but I happened to have some old steel furniture screws laying around, with the threaded part which fitted perfectly the hole inside the focusing knob. I just had to carefully screw the bolt into the hole keeping it parallel to the knob axis, until the wider screw part touched the end of the knob:
https://farm1.staticflickr.com/384/19215708001_20f05116d3.jpg
(To give you the scale in the above image, the full length of my screw is 45.6 mm; the inner thread diameter is 4.14 mm, the outer thread diameter is 5.90 mm; the thread length is 11 mm.) I didn't use any glue. At the end, the screw was sitting almost perfectly parallel to the knob's axis, and very tight (I couldn't turn it with my hand):
https://farm1.staticflickr.com/536/19024399990_ef614035c9.jpg
Another great feature of the screw was that the non-threaded part is a solid metal with exactly 7mm diameter. I managed to find on ebay a nice metal coupler from 7mm to 5mm (the shaft diameter of the stepper motor I used) which worked perfectly with the screw I had (I just had to cut off the head of the screw). I couldn't find identical furniture screws on ebay, but hopefully you can find something similar in a local store, or perhaps will come up with another idea on how to couple the plastic knob with the motor.
The motor shaft shaft happened to be a bit too long for my brackets, so I ended up cutting ~2-3mm from the shaft's end. Warning: the motor shaft is made of extremely hard steel, so no regular saw will do the job. I used a Dremel knockoff tool with a cutting disk, and took extreme precautions to make sure no metal particles could enter the motor - you can very easily ruin your motor if you are not careful, as it has very strong magnets inside. (I wrapped the motor in multiple layers of kitchen plastic wrap, with just a minimum hole for the shaft.) 
Warning: before doing anything to the focusing knob, you have to remove it from the Velbon rail - otherwise you will likely damage the mostly plastic bearings inside the rail. Once you attached the screw to the knob, cut off its head, and shaved off one side, you can put the knob back into the rail. Check the post #3 here for the instructions on how to remove the focusing knob from the rail.
The next critical step is to find (or make - as I did) two metal (best if steel or iron) brackets shaped like this : [ ] . They should be thick enough (probably at least 1.5 mm; I used 3mm iron) to provide a good support to the motor unit, and should be made with a high accuracy: the longer side should have the same length for the both brackets, and the shorter sides should be exactly parallel to each other, for each bracket. On one side the short ends will be attached to the Velbon rail (to the left and to the right from the focusing knob); you'll have to use a drill press to make four holes in the Velbon rail (very close to the edges of the rail - make sure the holes don't go inside the rail and potentially damage the rail's bearings), and then use taps and dies set to cut a thread inside the holes (I did M4 threading). The stepper motor will be attached to the opposite shorter sides of the brackets. (I used only two diagonally placed bolts in the motor to attach the motor to the two brackets; the remaining two bolts were left unattached).
The length of the longer side of the brackets will be determined by the length of the exposed part of the focusing knob + the length of the exposed part of the screw you put inside the focusing knob + the length of the motor shaft. You don't have to be super-accurate here, as the coupler gives you a bit of a leeway in terms of the distance between the motor and the rail. Drilling the two holes for the motor in the short sides of the brackets should be the last operation here: you want to find such locations for the holes that the motor shaft is almost exactly on the same axis as the focusing knob, or else the motor will not have enough of torque to move the rail. I accomplished this step by securing the coupler to the motor shaft (tightening a bolt), inserting the screw put inside the focusing knob inside the coupler (don't secure it with a bolt), and then finding the positions for the two holes on the short sides of the brackets for the two motor bolts. 
This is how it looks like assembled:
https://farm9.staticflickr.com/8333/29501413812_c1a1b375cd.jpg
The remaining steps are much less critical. One can put a metal (better aluminum) enclosure around the brackets, which has multiple purposes:
* It simplifies attaching the small bread board to the motor unit.
* It makes the motor attachment to the rail more tight and secure.
* It hides all the wiring inside.
* It prevents you from turning the focusing knob by hand - this is bad because it breaks the rail calibration, and it can also burn your motor driver (by induced voltage) if the controller is attached to the motor unit.
* It looks nicer and more professional.
Warning: when designing the brackets and the enclosure, make sure that the bottom part of the assembly doesn't protrude below the bottom of the rail (specifically the top part of the rail, with the focusing knob), otherwise you won't be able to use the detachable bottom part of the rail, with the manual knob to move your camera sideways:
https://farm1.staticflickr.com/573/22253937830_101fbc541b.jpg
This is not absolutely essential, but it would be a pity if the bottom part of the rail was wasted, and the sideway motion knob does simplify the job of macro-photography.
Then you should make a small breadboard and solder there the two relays, two diodes, two resistors, two external connectors (RJ-45 and 3.5 mm phone) and ideally a couple of internal connectors (for the motor and the limiting micro-switches; this will make it easier to disassemble the motor unit).
Finally, you need to attach the two limiting micro-switches to the rail, in a way that one of them would be triggered before the rail hits one of the physical limits. When a switch is triggered, there still should be enough of travel distance - 2 mm or more - left for the rail to properly decelerate and stop. The only way I could attach my micro-switches to the rail was by gluing them with a super-glue to the plastic cover of the rail, at a slight angle (to ensure there is the required 3mm gap when the switch is triggered). This worked pretty well:
https://farm1.staticflickr.com/706/21820750243_d77af9eae3.jpg
Then you have to solder the switches sequentially, in a way that normally (when switches are not engaged) the two wires going to the controller unit would be shorted, and only if one of the switches is triggered the connection would be broken. This is used by Arduino to calibrate the rail (to make sure that the rail will never trigger the switches during its normal operation.) With time the calibration will be lost, so a re-calibration would be required once in a while. Calibration is triggered automatically if during its normal work the moving rail will trigger one of the switches, or one can request a re-calibration manually.
= Controller unit =
https://farm1.staticflickr.com/713/21820758783_77c80d3e58.jpg
https://farm6.staticflickr.com/5741/22415911926_bff7952648.jpg
https://farm1.staticflickr.com/640/21819190094_af419cdb30.jpg
I managed to fit all other components (except for the batteries module) inside a small (125x80x32 mm) plastic enclosure from ebay:
https://farm9.staticflickr.com/8234/29320768930_654dcd8b47.jpg
https://farm9.staticflickr.com/8475/29500856012_ee4084f2bb.jpg
Only one cable (Cat 5/6) is connecting the controller unit to the motor unit, and one cable is connecting it to the power source (the battery module, or 10-12 V AC power adapter.) There are three boards inside, all attached to the bottom of the enclosure via ~5 mm long plastic spacers:
* Arduino Uno R3 knockoff board. The size of the enclosure is perfect in the sense that the Arduino board fits it nicely in the landscape orientation, with the USB and power sockets accessible from the outside (once you cut the corresponding holes in the side of the enclosure - use fret/coping saw for the rectangular hole).
* BigEasyDriver v1.2 motor driver board. This board is extremely small, and a bit of a challenge to attach to the enclosure: I ended up shaving the sides of two M3 nuts to prevent them from shorting circuits on the board. There is a tiny pot on board (motor current regulator). I set it to the largest motor current (1.4A) my motor + AC adapter can handle, to maximize the motor's torque. I set the required amperage by setting the voltage on TP1 to 1.23V. (See Question 3 at the bottom of this page: http://www.schmalzhaus.com/BigEasyDriver/ .)
* Breadboard with some other components soldered in: RJ-45 socket, a few voltage limiting resistors to connect the 5 V Arduino to the 3.3 V Nokia LCD display, 10μF polarized capacitor to smooth out PWM signal for the LCD's backlighting, and a female header for the 4-wire cable to go to the LCD display. This board is attached at the top of the enclosure.
Two more components are attached to the top part of the enclosure (you'll have to make corresponding rectangular holes for them, with fret/coping saw):
* Nokia 5110 LCD module.
* 4x4 keys keypad.
https://farm9.staticflickr.com/8338/28985365434_5010cce54b.jpg
The most time consuming part here is soldering all the required connections between these five components.
The power for the motor driver is taken directly from the Arduino's power plug. You'll have to solder the two wires, for - and +, directly to the Arduino plug, on the bottom of the board.
You have to check and recheck multiple times all the connections before attempting to power it on for the first time. It is especially critical for the camera shutter connectors: make it absolutely sure you are not sending high voltage inside your DSLR by mistake. Test this with any new Cat5/6 cable you plan to use with the rail.
Warning: never let anyone to attach your rail to a networking device (computer, laptop, router) via Cat5/6 cable! I use RJ-45 sockets and Cat5/6 cables here for convenience; they have nothing to do with Ethernet. If somebody does attach the rail to another device, this will most likely burn the networking board on that device, and might also burn the motor driver in the controller unit. It wouldn't hurt to put a red label on your controller unit next to the RJ-45 socket with such a warning.
=Schematic =
The schematic was drawn using the online software SchemeIt.
https://farm9.staticflickr.com/8387/29609756585_afcce3db9e.jpg
New in h1.3: The changes compared to h1.2 are:
* BigEasyDriver instead of EasyDriver (same wiring)
* Pins A3-A5 were swapped with pins 0-2. (It is better for motor driver not to use the serial interface pins; also, this would allow controlling the Arduino from a computer in the future.)
* Pin 6 swapped with A2. (This is only needed in the telescope focuser mode, where we need an analogue pin to measure the temperature).
* Polarized capacitor 10uF x 10V added to the controller's breadboard, to fix the LCD instability caused by backlighting PSW pulsations.
== RJ-45 sockets ==
RJ-45 socket (view from the bottom of the breadboard):
https://c2.staticflickr.com/6/5690/22314781196_4be86083ca_o_d.png
This is the wiring I did for the RJ-45 socket I got on ebay. The one you have might have a different layout.
You can only use a straight (not crossover) Cat5/6 patch cable!. Test first any cable you plan to use with the rail.
Here is the RJ-45 pin assignment:
* 1 (white-orange): camera shutter
* 2 (orange): common ground
* 3 (white-green): camera autofocus
* 6 (green): micro switches
* 4,5 (blues) : motor A
* 7,8 (browns): motor B
The pin assignment was done to minimize the risk of damaging anything if you by accident connect a wrong (crossover) patch cable. In a crossover patch cable, the following pins are swapped: 1<->3, 2<->6. As you can see, using a crossover cable will render the macro rail non operational, but will not send the high voltage / high current motor signals to a wrong destination. Still, better be safe than sorry, so always test any Cat5/6 cable you plan to use (to make sure it is a 8-wire straight cable) before using it in your rail!
== Nokia 5110 ==
Different Nokia 5110 boards have different pin numbering, so be careful! 
In h1.2, LCD's SCE pin is permanently soldered to the ground via a 10k pull-down resistor R9, and RST pin is powered via RC delay circuit (R10=47k, C2=0.1uF -> delay 3.3 ms; my LCD works fine with R10=30k...680k; it is best to choose a lower value for R10 from this range, with a bit of leeway to account for environmental changes) from +3.3V (VCC). You might need to adjust the values of R10 and/or C2 if your Nokia 5110 board requires a substantially different delay to work properly. I soldered most of these components directly to the Nokia board. 
Original Nokia 5110 wiring reference: https://learn.sparkfun.com/tutorials/graphic-lcd-hookup-guide
== BigEasyDriver ==
For the motor driver (BigEasyDriver v1.2), solder M+ pin directly to the "+" pin of the Arduino board power plug, and GND pin - directly to the "-" pin of the Arduino board power plug.
BigEasyDriver reference: http://www.schmalzhaus.com/BigEasyDriver/ .
== Battery sensor ==
Battery sensor consists of a passive voltage divider (resistors R3, R4) with high enough total (R3+R4) impedance to make energy losses negligible, and with the ratio R4/(R3+R4) chosen to make the largest expected power voltage (~13V) fit within the allowed range for the input pin voltage for Arduino (0...5V), after the divider. I also added C1=0.1 uF parallel to R4 to reduce the measurement noise. I soldered all these components directly to the Arduino board.
Original reference: http://electronics.stackexchange.com/questions/154371/lower-voltage-with-a-zener-diode
= Battery unit =
https://farm6.staticflickr.com/5645/21819188204_f15cb4d645.jpg
Nothing to do here - just buy and use one of those 8-AA battery flat enclosures with a switch and a cable with a plug. Double check that the polarity of the plug matches that of the Arduino power socket.
= Electronic shutter adapter = 
Starting from s1.14, my rail supports Full Resolution Silent Picture mode of Magic Lantern (alternative firmware for Canon cameras), which is basically electronic shutter (great for extending the lifespan of your camera when doing focus stacking). Very importantly, I figured out and implemented a way to use the electronic shutter with an external flash, which is a must for focus stacking. This required a new software feature - mirror_lock=2 mode, and soldering a simple adapter consisting of one 3.5mm stereo jack, one 3.5mm stereo socket, and a hot shoe for flash (I use it to connect it to my RF flash controller, YN-RF603, which wirelessly triggers my flash, YN-560III). The purpose of the adapter is to let the shutter relay inside my rail to operate an external flash. (Under FRSP, photos are taken by using the AF switch, not the shutter switch.)
Here is the schematics for the adapter:
https://farm2.staticflickr.com/1510/25251015024_b33d2d1041.jpg
= Telescope focuser hardware =
My Arduino can now also control a totally different device - motorized telescope focuser. All stuff related to that functionality resides on a separate wiki page, Telescope Focuser.