How it works
The Arduino only moves film; it knows nothing about pictures. The computer drives the camera, finds the frame in each shot, and tells the Arduino how far to move.
The film transport
Section titled “The film transport”A 28BYJ-48 stepper turns a 10-tooth sprocket in the film’s perforations: 47.5 mm of film per turn, about 2038 steps. A full 35mm frame (38 mm, 8 perforations) is about 1630 steps. 120 film has no perforations: a roller with two O-rings grips its margins, each pressed against the film by a printed leaf spring.
Before every move an SG90 servo lifts the pressure frame; after it, the frame is lowered and vibrations get half a second to settle. The film is never dragged under pressure.
The Arduino speaks a tiny serial protocol (9600 baud), answering each command with OK:
| Command | Effect |
|---|---|
M<steps> |
Lift, move that many steps (negative = backwards), lower |
F<steps> |
Set how far the FRAME button advances |
+ / - |
Nudge the film about 0.5 mm |
Finding the frame
Section titled “Finding the frame”Between frames a negative is bare film base: in the backlit photo, the brightest columns and evenly bright top to bottom. Only a gap is both: a thin shadow is nearly as bright but uneven, a clear sky even but darker. For slides, gaps are the darkest columns.
detect.rs measures each column’s average brightness and variation
in the middle half of the rows, away from the sprocket holes. Columns near the brightest
level and uniform are gap columns; runs of them are gaps. Two gaps the right distance apart
frame a picture; its center minus the image center is the offset in pixels.
With one gap visible (at the start of a strip, say), the calibrated frame width places the other edge. Calibration takes that width, and a gap’s, from the format (36 mm and 2 mm for 35mm) and the pixels per millimetre, read off the film’s height: the pressure frame’s window is exactly a frame tall (24 mm for 35mm). It doesn’t measure them between two gaps: on a thin negative, any two bright bands can pass for gaps.
Thin (underexposed) negatives are hard: much of the picture is as clear and even as bare base, and a frame edge can be invisible. So:
- Two gaps must be the calibrated frame width apart, within 5%.
- A bright run wider than any real gap (15% of the frame width) is a gap merged with clear picture, or blank film. Its edge counts only when another gap sits a frame width away.
- A lone gap is believed only where dense picture borders it over most of its height: a frame’s edge. A clear band fading into the picture is not.
- When the frame’s own edge is clear but the neighbour’s is dense, the frame is placed a gap’s width from the neighbour (2 mm on 35mm film).
- A gap with dense picture on both sides wins over any other single edge.
- The frame must land within 15% of the frame width from the center, where an advance or lining up by hand leaves it. If the edges in view disagree, it says so.
When it can’t tell, the scan asks you to line the frame up instead of guessing.
“The brightest level” depends on the film: a colour negative’s orange base is less clear than a black-and-white one’s. So each film gets its own calibration, starting with the bare base: an unexposed frame, or a gap you draw a rectangle over on the live view. With neither, it is learned from the first frames found. A scan that meets film clearer than its base stops and asks before guessing.
Centering
Section titled “Centering”calibrate measures how many pixels the picture moves per
motor step. An offset of +40 px then becomes a correction of -40 / px_per_step steps.
Calibration also measures the play in the 28BYJ-48’s gearbox and between sprocket teeth and perforations:
- On turning round, the motor turns a while before the film follows (about 50 steps on the prototype). So every backwards move overshoots, then comes forwards: the loss happens once each way and cancels out. The last movement is always forwards.
- At the start of any move, a few steps move nothing (6 to 14 on the prototype). Every forwards move gets that many steps added.
The arrows in the app move the film the same way.
Learning the frame spacing
Section titled “Learning the frame spacing”Cameras don’t all space frames exactly 38 mm apart, and a 120 roller can slip. So each advance is the median of the last five spacings measured between well-centered frames. A jump more than 25% off (a slip, a frame advanced by hand) is ignored. After a few frames, most are centered on the first shot.
Shooting: why not live view?
Section titled “Shooting: why not live view?”The first version centered every frame from real shots. Now the app shows the live view, with the detector’s findings on top, and centers frames through it. Only the kept picture is a real shot.
The Fujifilm X-T5’s live view used to die after the first capture, until unplugged. In USB tether mode the camera keeps each shot in temporary memory until deleted, gphoto2’s delete of the RAW fails, and the camera refuses the live view while anything is left. The app now empties that memory after each shot (never a memory card), and the live view comes back at once.
Three more X-T5 quirks, handled by LiveCamera in camera.rs:
- About one live frame request in three fails: no new frame yet.
gphoto2 --capture-moviegives up on the first failure, so the app keeps onegphoto2 --shellrunning and asks again. That gives about 20 frames a second. - No picture can be taken while that session is open. It is closed for each shot and reopened after, so the live view freezes for about five seconds per shot.
- Every gphoto2 session locks the camera’s dials and menus, and the live view’s lasts
until the next shot. So it hands control back on opening
(
set-config prioritymode=Camera): you can set the exposure while watching.
Centering through the live view
Section titled “Centering through the live view”Once the film is still (three live frames in a row with no change), the scanner averages the next five, for less noise. It finds the frame there and nudges the film until it is centered, without a shot.
Then the real shot is taken and checked in its JPEG: more than 8 px off-center, the film is corrected and the shot retaken. The scanner learns how far shots land from where the live view showed the frame (median of the last five) and aims to cancel it, so a roll needs one retake at most. A frame you lined up by hand is never corrected.
A calibration is made the way the film will be looked at, live view or shots. When they don’t match, the app says “Calibrate again”: once, the first time the live view is used.
Not built yet: following the film while it moves, to notice a slip at once and see frame edges from many viewpoints (design).
Without a live view
Section titled “Without a live view”Without a live view, frames are centered from real shots, each JPEG scaled to 1024 px wide. A centered shot is the scan; otherwise the film is nudged, the shot retaken and the off-center one deleted. With the spacing learned, retakes become rare, and with an electronic shutter cost only a few seconds.
Safety nets
Section titled “Safety nets”- End of strip: a view with no film in it, twice in a row, ends the scan.
- Blank frame: a single empty position is skipped.
- Lost frame: if a frame can’t be found, or is still more than 16 px off after four corrections, the scan pauses and asks you to line it up with the buttons.
- No overwriting: a scan refuses to start if its output files already exist.
The tests run against a simulated scanner (src/testing/rig.rs):
a film strip, a motor with gear play, and synthetic backlit previews
(src/testing/synth.rs). Run them with cargo test.