Public Lab Research note

This is part of a series on community-microscope-tests.

Raspberry Pi Microscope/close up lens system

by MaggPi |

Read more:

MaggPi was awarded the Basic Barnstar by stevie for their work in this research note.

Raspberry Pi Microscope/close up lens system

This project provides a way to use a Raspberry Pi camera to take microscope/macro pictures. The design may not be as elegant as some other public lab microscope kits ( but provides an alternate approach that may be useful for a given project.

Key aspects of the design: --Lens mount convertor/adapter rings that permit a variety of lenses/microscope objectives to be used with the Raspberry Pi camera array. Modular lens approach is very useful since microscope objectives, close-up or wide field of view lenses can be easily swapped for different measurements.
--A .5 meter flex cable for the Raspberry Pi camera. The flex cable permits greater camera/computer separation distances than the 15cm cable that comes with the camera.
--Mount/stage system. A basic setup using labjacks and an LED light. Nothing fancy but easy to set up and is essential to hold lens and focus image. --Python image capture software. Software permits real time video adjustments followed by jpg image capture.

Major lens system parts list (with supplier/cost): --Lens Mount: M12 lens mount (male metric thread with 0.5 mm pitch) with mounting screws. Designed for Raspberry Pi camera v2.1 with 21mm hole spacing. Mounts lens holder to camera/array board., $8.50. -- Adapter Ring: attaches onto the M12 lens mount and enables a C Lens to be mounted,, $6.59. -- C mount to RMS adapter: This ring has both an inside and outside thread that enables most microscope objectives (RMS mount) to connect to the C mount holder. , $8.75. --Flex cable: 1 meter flex cable for the Raspberry Pi camera., $ 3.95

Attached pictures provide assembly instructions:

  1. Remove lens from Raspberry Pi camera board. Note that lens removal voids the warranty. --Option1 is to unscrew the lens. This can be done by a special 3 D printed lens removal tool or a pair of pliers and a very steady hand. –Option 2 is to ‘decap’ the lens holder (and lens) from the board. One decap method is to cut into the epoxy between the board and lens holder with end cutting pliers. The technique chews into the epoxy until the holder pops off.

  2. Align camera board holes w/M12 lens mount and screw together.
    Lens removal and lens mount

  3. –Thread the C adapter ring to the M12 lens mount --Thread the C mount to RMS adapter on the microscope objective --Thread the objective to the C adapter ring Lens mount and adapter assembly

  4. Most applications will require an adjustable height camera/objective holder. One option is to use two lab jacks with the camera resting on two rulers. This is a good option for quick tests but other designs should be considered for reliable results. Adjustable camera/lens mount holder

  5. Start taking pictures! I prefer to use a python program that provides 30 seconds to optimize the focus and then automatically records a jpg picture. Code is available at:[]10.

In order to compare different lens options, pictures of Raspberry Pi camera shipping box were taken with a standard Raspberry lens (3.04mm), M12 2.8mm lens, 10X and 20X objective. Each of the images have a different camera to object distance and show how the lens system can provide different fields of view and magnification. Images are recorded and shown with the same digital format. Lens picture comparison

webcam raspberry-pi gsoc python microscope pi-camera soc gsoc-2018 soc-2018 pi-microscope camera-comparison

barnstar:basic series:community-microscope-tests


Wow! @stevie, check it out!

@stevie awards a barnstar to MaggPi for their awesome contribution!

Hi, @maggpi -- what do you think of trying this out with one of our microscope stage prototypes? Could we send you some parts to test it out with and provide some feedback?

Is this a question? Click here to post it to the Questions page.

Mr Warren, -That would be great! Not sure if I can do anything more but take some pictures but happy to try.

Initial questions: -Please note, I only have a 20x objective. I noticed that the microscope design ( used a 40x objective. Is there a 'depth of field' design goal for the stage prototype?

-Why is the microscope stage design inverted? Is there a measurement that requires a 'looking up' objective?

Thank You

Is this a question? Click here to post it to the Questions page.

Hi! I'm not sure why it's inverted ... maybe it's more stable? A good question to ask @partsandcrafts folks.

We've been having a lot of success with a 10x, as well as a 40x, so I think 20x is great. Email us at with your mailing address and we'll send you some parts!

Is this a question? Click here to post it to the Questions page.

Hi, @maggpi! I was taking apart a webcam and wondered if this is the same lens mount?


Is this a question? Click here to post it to the Questions page.

Aha! It was! This means we could use some of your adapters on these webcams, too!


We'll send you one, to test!

Mr Warren, it looks shorter but seems to fit a M12 lens thread. You would have to measure the hole spacing (21mm) to determine if it's compatible with a PI v2 camera.

FYI, m12lenses offers mounts for most hole spacings. You may be able to match what you have against their catalog.

I assume m12 lens can be adapted to either webcam or raspberry pi camera as long as the right camera mount is selected. Mount designs seem to be based on hole spacing and being able to fit around the electronics.

link above is for CS Mounts, link below is for m12 mounts....

Wow, awesome, thanks for the help!

Also, you can just call me Jeff -- or @warren -- no Mister necessary -- thanks!

You must be logged in to comment.