Modifying Optics Module to Accommodate Different Lenses

Hey folks,

We’re looking at making a bunch of OpenFlexure microscopes for our microscopy students to take home with them so they can do lab activities during Covid-19. We found an amazing deal on 13mm diameter x 49mm focal length achromatic lenses and we’d like to incorporate these into the design instead of the 12.7mm dia x 50mm fl lenses specified in the assembly instructions for the optics module for the high resolution microscope version. I mentioned the source of these lenses in the “sourcing non-printed parts” thread.

In this thread, I’d like to open up a discussion about how to modify the optics module to accommodate different lenses. Maybe the 1mm difference in focal length in our example will not degrade image quality significantly enough to warrant a modification, but maybe it will. How can one determine how big of a modification to make in the physical positions of the components in the optics module?

When I put this question in the chat, @j.stirling made this comment: “It would be best to modify the lens optics module slightly but it wouldn’t just be a 1mm move. However there is in the OpenSCAD code a module called “optics_module_rms”. This takes in the lens radius, lens nominal focal distance, and lens front focal distance and uses them to make the correct optics module. Assuming a high quality achromatic lens you will notice very little change in imaging performance, and a very slight change in field of view. As the move is sub-mm you could probably get away with not adjusting the optics module with only limited performance reduction, but here I am less sure.”

Does anyone have more thoughts on this? How about @r.w.bowman ? Can we put together instructions for modifying the optics module in OpenSCAD?


With an infinity a corrected microscope objective, the change in position would just be the change in focal length of the tube lens. However most of the microscope designs have a back focal distance of 150mm (‘tube’ length 160mm) and we are modifying that with the tube lens to make the image the correct size to fit the camera. This gives a distance which does not simply change by the change in lens focal length.
As @j.stirling says, it should all be calculated automatically in the optics_module_rms module in the optics.scad design. This is on gitlab for the microscope. STL builds are made for the common optics, but you should be able to download the code and change the lens parameters in OpenSCAD and @r.w.bowman 's marvellous code will generate the required part. The lens position calculation is commented in the scad file.

I have extensive CAD experience with Solidworks, but I had never heard of OpenSCAD until you mentioned it in your post. To be frank, the learning curve on this software seems steep and it doesn’t seem to play well with other programs (no option to export as .stp, for example). I tried to figure it out per your explanation, but I don’t think I did it right. Maybe you can help. Here’s what I did:

I installed OpenSCAD, downloaded all the model files, opened optics.scad, made the following changes to the lens parameters:

I also made sure the pi camera v2, RMS finite 160 tl objective lens and beamsplitter options were activated in the microscope_parameters.scad file.

I rendered the file and exported as a .stl.

However, when I import the “optics_picamera_2_rms_f50d13_beamsplitter.stl” file from the standard build and the new .stl file I created in OpenSCAD into Solidworks and compare them, there is no difference in any of the critical dimensions which locate the optical components. I must have done something wrong. Any ideas?


I don’t think you expect to be able to see any difference. The lens holder should be 0.3mm bigger and the difference in position of the lens holder is about 0.6mm (if I applied the calculation correctly).
That is hard to see in the STL. May not even make a difference physically. The slightly bigger lens would probably push in the normal hole, and the focus word probably work and the image would be OK. But as you can change the SCAD to the correct dimensions it is nicer to have it right.

This is one of the good things about OpenSCAD. If you keep everything parametric you can change the sizes of some parts and everything will automatically adjust. As you say, understanding it can be hard.

If you want to check that something is actually changing, put in a diameter of 6mm and focal length 30 or 40mm. Then the differences should be big enough to see.

Just a note. I see you are looking at the reflective version of the microscope. The transmission illumination is much easier to set up if you are looking for students to do it. Of course it depends on having relevant things for them to look at that are transmissive.

I think it’s possible you are getting caught out by the non-standard way I tend to build things, for which I can only apologise. It would be very good to pull this post into the documentation somewhere…

The optics module is built, as you have correctly figured out, by optics.scad. However, this file does a bunch of different things depending on the settings in microscope_parameters.scad. That’s deliberate - because when the project is automatically built, we override those settings to make the different versions (all the STL files that start with optics_ are built from the same SCAD source).

The parameters you changed, at the top of that screenshot, are the default parameters for the optics_module_rms module. To build the optics module with default parameters, you would use a line that looked like


However, the parameters of the module are intended to be changed when it is called. If you scroll down to the bottom of the file, there’s a big if statement that controls what gets built, depending on the value of the optics parameter (defined in microscope_parameters.scad, or by the build script). That means the command that actually builds the optics module, on line 403 is:

            tube_length=(optics=="rms_f50d13" ? 150 : 99999) //use 150 for standard finite-conjugate objectives (cheap ones) or 9999 for infinity-corrected lenses (usually more expensive).

If you change the parameters there instead, it should have the intended effect.

I hope that makes at least some sense!

Thanks @WilliamW ! I should be clear: I am building a reflected light version for my own metallographical needs. (I am a college instructor in a machine technology department.) I am interested in figuring out a way to get darkfield and maybe DIC (or something similar) to work. The limitation for DIC is the Nomarski prism, but I’ve always dreamed of one day making some DIY prisms out of calcite. Maybe now is the time to follow my dreams :slight_smile:

As for students, there will likely be two groups building scopes: 1) middle school or high school students who will likely be building simple transmitted light versions, and 2) college students in the microscopy program who will likely be building epifluorescence versions.

Thanks @r.w.bowman ! Your instructions were very helpful! When I modified the parameters in line 403, I was able to correctly export a customized .stl file. I verified the critical dimensions in Solidworks (with which I am much more comfortable) and I got these values:

Distance from lens mount face to objective shoulder
11.56mm for default 50mm fl lens
11.65mm for custom 49mm fl lens

Distance from lens mount face to Pi camera mounting surface
35.94mm for default 50mm fl lens
35.85mm for custom 49mm fl lens

If I did this correctly and these really are the changes (a little further from the objective and a little closer to the Pi camera by about .1mm), then I think these are indeed insignificant enough that modification to the .stl file is unnecessary if one wishes to use the bargain 13mm dia X 49mm fl achromatic doublets sourced from That’s good news for folks who are looking for the easiest + cheapest way to build the scope.

But I will build two optics modules - one with each set of dimensions - and compare them just to be sure there is no discernible difference. Fun fun!