An autofocus module for a board camera moves its lens less than a millimetre, yet that stroke covers roughly 4-5 cm to infinity with the short lenses these cameras use. It is driven as an I2C slave, so focus is a bus write rather than a thumb-and-forefinger fight with a tiny barrel, and it works with no display attached. That is exactly what a headless host needs: an embedded controller, a robot cell box, a board you reach only over SSH. The sections below cover how the actuator works, how much travel your focal length actually needs, how the focus value reaches the driver chip without a GUI, where a 1 mm stroke stops being enough, and how to choose between autofocus, liquid lens and fixed focus.
What moves inside an I2C autofocus module
A voice-coil motor (VCM) module is a small solenoid acting on the lens itself. The lens sits in a carrier suspended on leaf springs between permanent magnets; current through the coil creates a magnetic field that pulls the carrier against the spring. Because the spring is nearly linear, coil current maps to lens position. A driver IC beside the actuator regulates that current and holds the commanded position, and closed-loop parts measure the current to correct for spring settling and tilt. The whole assembly is a few millimetres across, and the stroke is about 1 mm.
The driver IC is an I2C slave on the camera's control bus, and a register holds the focus code. Two consequences follow. Focus can be set from anything that reaches the bus: a kernel driver, i2c-tools, your own code. And with zero current the spring pulls the carrier back to its rest position, so the focus value must be rewritten after every power cycle.
The module replaces the fixed S-mount (M12) lens on a board camera, so it pairs naturally with compact M12-mount hosts:
- Sensor format
- 1/2.9"
- Lens mount
- M12
- Sensor format
- 1/2.7"
- Lens mount
- M12
- Sensor format
- 1/2"
- Lens mount
- M12
For a headless GigE build, the MV-CB016-10GM-M-W combines a 1/2.9" global-shutter sensor with an M12 mount. For two synchronized views, choose the LS-BCM-0043. That binocular 1.3 MP USB3 module carries two M12 mounts and runs 1280 x 1024 at 123 fps.
The travel the optics actually need
Focusing means moving the lens along the axis by the extension e that satisfies the thin-lens equation, with S the working distance, s' the lens-to-sensor distance and f the focal length:
At S = ∞ the extension is zero: the lens sits at its nominal flange position. Every finite distance asks for a little more, and for short focal lengths the ask is tiny. Take a 3.6 mm lens, the common board-camera wide, at f/2.8:
| Working distance S | Extension e = 12.96/(S − 3.6) mm |
|---|---|
| 1,000 mm | 0.013 |
| 250 mm | 0.053 |
| 100 mm | 0.134 |
| 50 mm | 0.279 |
Pulling focus from infinity down to 50 mm costs 0.279 mm of travel. Typical smartphone-class modules quote about 1 mm of stroke and a 4-5 cm close-focus limit, and the arithmetic shows the limit is not travel: a full 1 mm would carry a 3.6 mm lens to about 17 mm. The 4-5 cm rating comes from aberrations and the mechanical stop instead. Treat the table as a thin-lens estimate, good to a few percent — close enough to plan with. The same extension arithmetic explains close-focus limits on CS-mount lenses at fixed flange distance.
When 1 mm of stroke stops being enough
The demand scales with f², so travel binds quickly as focal length grows. With maximum stroke e, the closest object distance follows from 1/S = 1/f − 1/(f + e), which rearranges to S = f(f + e)/e. For a 1 mm stroke that is simply f² + f:
| Focal length f | Closest S with 1 mm stroke |
|---|---|
| 3.6 mm | 16.6 mm — optics limits first |
| 8 mm | 72 mm — travel is the wall |
An 8 mm lens shows where the wall sits in between: at 100 mm working distance the extension needed is 64/(100 − 8) = 0.696 mm, comfortably inside the stroke; at 50 mm it is 64/(50 − 8) = 1.524 mm, beyond it. An 8 mm lens on a 1 mm module therefore cannot focus closer than 72 mm, whatever focus code you write.
The decision: on 2.8-4 mm lenses, trust the module's rated 4-5 cm close limit, because travel is not the constraint. On 8 mm lenses and longer, compute f² + f with your actual stroke before promising a close-focus number. If the application needs closer than that, change the optics — a shorter focal length or a mechanically focused mount — not the focus code.
Setting focus headlessly over I2C
If the kernel has support for the actuator, focus appears on the video device as the standard absolute-focus control, V4L2_CID_FOCUS_ABSOLUTE. The range is driver-defined — 0-1023 steps is typical — and any control tool sets it from an SSH session. Read the real minimum and maximum from the control's own menu, sweep the range, and park the code that peaks sharpness. No vendor GUI and no display are involved at any point.
Without kernel support, the actuator is a slave address plus a register map from its documentation. Linux exposes the bus as /dev/i2c-N and i2c-tools does the rest:
i2cdetect -y 1 # scan /dev/i2c-1 for slave addresses (illustrative bus number)
i2cset -y 1 0x0c 0x00 0x0200 w # word-write a focus code (illustrative address, register and value)
i2cget -y 1 0x0c 0x00 w # read the register back to confirm the write took
The bus number, slave address, register index and value above are placeholders showing the shape of the exchange. The actuator's documentation defines all four; never guess a register.
Whichever path you take, write the focus code during start-up, before the first inspection frame. The unpowered carrier sits at its rest position, so yesterday's value dies at the next power cycle.
How forgiving the focus code is: depth of field
A focus code is forgiving because depth of field spreads a window around the focused distance. With circle of confusion c (one pixel is a sensible choice), f-number N and working distance S, the near and far sharp limits are approximately:
Worked example: f = 3.6 mm, N = 2.8, c = 3 μm, S = 100 mm. N·c = 2.8 × 0.003 = 0.0084 mm, and N·c·(S − f) = 0.0084 × 96.4 = 0.810 mm². Near = (100 × 12.96)/(12.96 + 0.810) = 94.1 mm; far = 1296/(12.96 − 0.810) = 106.7 mm. The window is about 13 mm around a 100 mm working distance, roughly −6/+7 mm.
Two readings follow. The actuator's hysteresis — a few code counts when the lens approaches from a different direction — moves the focal plane by a fraction of a millimetre, far inside that window. And focused at infinity, everything beyond the hyperfocal distance H = f²/(N·c) + f = 12.96/0.0084 + 3.6 = 1,546 mm ≈ 1.55 m is within one pixel of best focus, so distant scenes barely need refocusing. Smaller pixels tighten the window in proportion: at c = 1.6 μm the same setup spans roughly 97-103 mm, about 7 mm in total.
Run your own focal length, aperture and pixel size through the calculator before locking a focus policy:
VCM module, liquid lens or fixed focus
A focus actuator is one of three ways to hold a board camera sharp, and the right pick is per station:
| Actuator | Range | Close focus | Control | Pick it when |
|---|---|---|---|---|
| VCM autofocus module | about 1 mm lens stroke | 4-5 cm on short lenses | I2C code, rewritten at boot | distance changes between runs; headless host |
| Liquid lens | electrical tuning, no moving mass | model-specific | I2C or analog drive | frequent refocus cycles; vibration |
| Fixed S-mount lens | barrel thread only | set once by lens height | hand adjust and lock screw | static working distance |
Per case: a station where the part always lands in the same place wants the fixed lens — simplest, no actuator hysteresis, nothing to rewrite at boot. A cell where parts arrive at varying heights wants the VCM module as the low-cost default, or the liquid lens autofocus approach when refocus cycles are frequent or vibration is high. On moving carriers the question changes again; the autofocus versus fixed-focus comparison on mobile robots settles that case.
Mounting and verification
Two mechanical details decide whether the electronic range covers your scene. First, nominal height: the actuator strokes about its rest position, so the S-mount holder must set that rest position near the right flange distance, or the whole electronic range shifts away from your working distance. The S-mount holder set-up guide covers the measurement, and a short M12 thread can cap physical travel on top of that, as the thread-travel analysis explains.
Second, verify without a display. Script a sweep of the focus code, capture a frame at each step over the network, score sharpness per frame — the sum of gradient magnitudes is enough — and park the peak. Then confirm the working window on a depth-of-field ruler such as the LS-LXR-0029, whose 0.5 mm dots on a 76 x 76 mm grid let you read off which distances fall inside the window you computed.
- Type
- Calibration targets
If you stay fixed-focus, the tool is a focusing ring: the LS-LXR-0087 adjusts an M12 lens across a length of 24-45 mm.
When the usual advice is wrong
- Blur means autofocus. On a static station, blur is almost always flange height or a dirty window, not focus range. Fix the mount first, using the blurry-image diagnosis for global-shutter cameras.
- A bigger code focuses closer. Past the stroke floor computed above, extra codes do nothing. The focus-range diagnosis tells you whether you are travel-bound or optics-bound.
- Under 4-5 cm is a software problem. The class floor is the class floor: macro work at a few centimetres needs optics designed for it, not a larger focus code.
- Just add it to the existing bus. Sensor and actuator share one I2C bus happily when their addresses differ; when they collide, the duplicate-address bus options apply.
- Standardize on the module after one bench test. Fold it into the board-camera evaluation checklist first: address stability across boots, rest position after power cycles, hysteresis between approach directions.
Where this leaves you: pick the actuator for your focal length — the arithmetic above takes ten minutes — then treat focus as a boot-time bus value rather than a knob on the barrel. Assemble the station from the board-level cameras and lens accessories ranges, filter by mount, shutter and interface in the camera finder, or start at the camera configurator. The other lens guides cover the mechanical half of the same problem.
Questions
How long does the lens take to settle after a focus write?
The move itself takes tens of milliseconds for a full travel sweep; small corrections settle faster. Budget 100 ms between the write and the first captured frame, and keep that order in the acquisition sequence: write, wait, grab. If frames at a new code look soft only on the first exposure, you are capturing before the spring has stopped ringing — increase the wait, not the exposure.
Does a voice-coil module hold focus through vibration?
While powered, yes: the driver regulates coil current against the spring continuously, so the commanded position holds even as the camera shakes. Watch two things instead. Approach the final focus code from the same direction every run, because the mechanism has a few counts of hysteresis, and rewrite the code after every power cycle, because an unpowered carrier sits at its rest position. Where vibration is severe, a liquid lens with no moving mass is the sturdier actuator.
How do I find the autofocus actuator's I2C address?
Scan the camera's control bus with i2cdetect and match the result to the address in the module's documentation. An address already claimed by a loaded kernel driver reports as UU rather than a number, which tells you the driver bound successfully. The image sensor keeps its own documented address on the same bus; actuator and sensor sit at different fixed addresses on typical modules, so no rewiring is needed.
Can I replace the lens inside an autofocus module?
In practice, no. Lens, carrier and spring are aligned as one factory assembly, and the module class offers no serviceable adjustment for a different focal length; opening it loses the centring and the focus calibration. If you need another field of view, choose a module built for that lens, or go fixed-focus with a height-adjusted S-mount lens, which changes focal length freely within the mount's thread range.
Does a 1 mm autofocus module work with long focal lengths or telecentric lenses?
For focal lengths of 8 mm and up, the stroke becomes the close-focus limit: applying the f² + f rule to a 1 mm stroke, a 12 mm lens cannot focus closer than 156 mm. Telecentric lenses do not focus by axial extension at all, so a voice-coil module is the wrong tool there. The module class suits the short, wide lenses board cameras normally carry, where optics bind before travel does.



