Microscopy – with added Pi

tl:dr :  I hacked open an intel QX3 toy microscope, replaced the crummy sensor with a Picamera, installed RPI_cam_web_interface on it and now have a wireless electronic microscope that you can control using a web interface.  It’s a great little teaching tool, and the camera can live with the microscope permanently, the Pi can be detached and used for other projects.

An intel QX3 microscope with a Raspberry Pi camera inside.  The Model B is mounted on top temporarily whilst I work on fitting an A+ inside the microscope body.
An intel QX3 microscope with a Raspberry Pi camera inside. The Model B is mounted on top temporarily whilst I work on fitting an A+ inside the microscope body.

Background: When the education pyramid for my county was collapsed into two tiers (Primary and Secondary only-  Middle schools were closed down), some of the science equipment was redistributed to other schools.  We got a bunch of the Intel Qx3 Mattel microscopes, which were ‘legacy equipment’, and hadn’t been used in years (sneeze alert).    I saw these sad microscopes and thought they could be revitalised with some ‘Pi inside'(TM) Back when they were released, they boasted fairly good specifications, including 10, 60 and 200x optical magnigfication, USB connectivity, CCD sensor capable of native res of 320×240, and incandescent illuminators above and below the stage.  They are great toy microscopes, and work well for the price, although the drivers haven’t been updated for Windows in years, and the software really only works reliably with XP.  This also means that if you do get an old XP box/laptop you have to use the heinous digital blue software bundled with the camera, which stinks of bloat, and wacky menus.  Getting it functioning: Mac OS X has a working solution with macam, but doesn’t allow direct control of the illuminators, and my school doesn’t have any OS X machines to hand. There is a solution for Linux machines that works as described in this excellent blog post here.  Since it works on a linux distro, and video4linux  identifies the camera as a gspca (CPiA) webcam, it should work on a Pi, since V4L is baked into the kernel of Debian. There is a great blog post here detailed how to get it working with Camorama. Naturally, I plugged it straight into a Pi via usb and managed to get it working in X using camorama using the following commands.

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install v4l2 camorama mplayer ffmpeg

On running camorama, It worked, but it was really disappointing.  The res was low, the framerate from the webcam was sucky, the sensor had a huge amount of noise present and it crashed after about 2 minutes every time. I persevered with getting it to work, but my coding skills weren’t up to the challenge of getting V4L2 to play more nicely with the camera (although I did manage to get the illuminator to turn on and off using:

v4l2-ctl -c illuminator_1=0

At this stage, I was ready to say that the cams were working again – We had a solution that allowed kids to get images from them, and use them in education, but it was clunky, and didn’t offer that good a solution. Option 2: Void that Warranty So, I removed the sensor board, and stuck a Pi camera inside, set up streaming webcam with controls and it’s awesome.  I haven’t added GPIO controlled LED lights yet, but it’s a huge improvement over the previous res with the camorama option.   The step were as follows:

  • Detach Microscope from stand
  • Unscrew the back by undoing the six screws on the back of the microscope.
  • Disassemble microscope.  Carefully take apart the 4 main pieces of the webcam (back plate, front plate, base, microscope body) I was really careful to avoid getting dust inside the optical assembly, which seemed fairly well sealed.
  • Unclip cables: Usb and illumination ribbon cables from control board. (might need a screwdriver here, they are glued)
  • Drill out the Usb cable from the back plate of the microscope (I couldn’t loosen the glue, so had to resort to persuasion)
Drllling out the usb cable holder at the back of the microscope.  It was held with adhesive far stronger than the surrounding plastic, and I risked shattering the microscope casing.
Drllling out the usb cable holder at the back of the microscope. It was held with adhesive far stronger than the surrounding plastic, and I risked shattering the microscope casing.
  • Unscrew the control board.  There are 3 screws with maddening Red Plastic glue over them to prevent fiddling.  I cut this gunk up with a razor blade first, then unscrewed them fully. It’s well worth tampering with them.
  • Modify Pi camera by unscrewing the lens completely (use tweezers and use a craft knife to break the glue seal). This allows more light into the sensor, and is far better for microscopy and telescope use. You can reverse this, and set the lens focus back to inifinity afterwards, but if you are not careful, you could risk damaging your PiCamera module.   There’s a nice tutorial here on how to do it.
I replaced the CCD sensor module by unscrewing the glued screws and mounting  the camera module in exactly the same place.  I used a servo horn to hold the camera in place and prevent  dust entering the sensor.
I replaced the CCD sensor module by unscrewing the glued screws and mounting the camera module in exactly the same place. I used a servo horn to hold the camera in place and prevent dust entering the sensor.
      • align pi-camera over old sensor hole. You can see this in the photo above.
      • live test using raspistill to get position of the camera module where the old CMOS sensor was and test focal length, focus etc.  You might need to adjust the picamera further away from the lens assembly to make sure that the stage can focus when you adjust the stage height with the knobs.
        raspistill -o image.jpg

        This command will generate a preview screen if you are in X.  You should see the red light come on, and then if you look in your home directory, you can look at the file, and make adjustments.

    • affix pi camera in place.  I used a medium servo horn (it just had the correct spacing for the screw holes) or other piece of plastic/wood.  Metal is a bad choice, it will short the connections on the back of the camera module, likely resetting the Pi. It’s possible to 3D print or laser cut a bracket to the correct size, but I didn’t have access to those at home)
    • Feed ribbon cable out through the usb cable hole.   In time I’ll probably Sugru it in place when I’ve found the sweet spot of replacement flex cable length and where I want the Pi.  Longer = more flexibility (no pun intended)
You can see the Picamera mounted inside the microscope casing, and the flex cable is routed out of the original USB cable hole.
You can see the Picamera mounted inside the microscope casing, and the flex cable is routed out of the original USB cable hole.  The  Model B is mounted on top, caseless, for the moment.
  • Reassamble the Microscope by putting all of the bits back together (Make sure the camera module is aligned so that it has a light path straight to the stage – Initially I put it in back to front, and couldn’t see anything, and went through a painstaking process of checking camera connections, rebooting, before I realised that it was a basic physics fail).
  • Install the amazing RPI_Cam_Web_Interface on the Pi. ( There is excellent documentation on the elinux site, with installation instructions).  This gets an MJPEG feed from the picamera and streams it to a web server with the Pi’s address.  The web interface has awesome customisation options and allows you capture stills, video and time-lapses through a browser.
  • Add a usb wi-fi dongle to Pi and power it up via battery or mains power.
  • Browse to the IP address of your Pi on another computer.  (you can do this by typing ifconfig into the terminal, or by watching the messages that appear during startup.

At this stage, it works, it can be used by anyone who knows how to point a browser to an IP address, providing you have a wireless connection.  You can probably plug in a monitor, keyboard and browse to localhost on the Pi itself to control it, although I haven’t tried, but a wireless microscope is SO much cooler! Next steps- Use a Pi A+ and see whether I can secrete the workings into the base so it is an invisible mod apart from the camera ribbon cable. -Replace the bulbs with LEDs, and control them via GPIO, and add buttons to the RPI_cam script. -Remove the reboot and shutdown buttons from the script, or at least password protect them. -Write a proper instructable for people who like to void their warranty with style. Naturally, not having access to school wifi makes it a bit more tricky, but you can still plug in a keyboard and monitor via HDMI, and you will be able to access the web cam interface at

 http://localhost/

in a browser on the Pi.

Here’s a sample of 3 zoomed images downloaded from the Camera browser interface.

L
Ladybird at 10x magnification. I found it inside the window casings in my lab. 😦
60x magnification of ladybird showing detail of the compound eye.
60x magnification of ladybird showing detail of the compound eye.
This is a focus-stacked jpg made in photoshop.  I had to correct a red cast on the photos, and focus stacked 5 images , hence the ganky edges around the frame.
This is a focus-stacked jpg made in photoshop. I had to correct a red cast on the photos, and focus stacked 5 images , hence the ganky edges around the frame.
Advertisements

13 thoughts on “Microscopy – with added Pi

  1. Hi Dave – Good job! I’d been meaning to do something like this for a while, and your post has inspired me to make a start.

    The A+ is quite a nice fit – attach 25mm long x 6mm diameter standoffs to each of the four mounting holes & it will sit nicely on top of the ‘scope, legs straddling the sides perfectly. Adding bit of heatshrink tubing increases the diameter a tad & gives better friction than plastic (or metal) on plastic. I suppose the B+ & 2B will sit just as well, but the A+ at £15 is perfect to “embed” in the scope.

    I found I needed to mount the camera a little lower than either the standoffs or black plastic shroud would allow. I took a dremmel to the sides of the camera module adjacent to the mid-side mounting holes to allow it to fit inside the standoffs. In retrospect it might’ve been better to trim the standoffs, but it’s done now!

    The black plastic light shroud was taken out & sanded to remove a mm or so of height, being careful to ensure it was still parallel to the bottom. To that end, I put the shroud in the chuck of a pedestal drill & spun it slowly by hand whilst abrading against sandpaper on the drill table. I then carefully trimmed a little more along one side & corner to allow clearance for the Sunny connector & a couple of smd components.

    I cut a piece of veroboard to fit inside the housing, with three drill-holes to mount using the original screws. A small piece of neoprene foam is placed on the cameras module such that when the veroboard is screwed down, the camera is held in place. I’ll mount mosfets on the circuit board in due course to give gpio control of the lights.

    I have the camera cable exiting through the opposite hole to you – the switch button was easy to remove, and I’m still wondering whether to retain the original blue cable as the power source for a wifi-only microscope.

    Liked by 1 person

  2. Wow

    David – your build sounds much more reproducible than mine, or the kind of thing that should definitely be made into an instructable for the benefit of others. There must be hundreds of these microscopes sitting around in schools getting no love!
    I made mine at home over the course of an evening, so I didn’t have any machining capabilities, I made do with a dremel and a drill. Also, I should have made more build photos, it’s something I need to be better at!

    (1) It’s interesting what you said about changing the standoff height for the sensor – I actually removed the standoff completely and used a dremel to take the height of the mounting screws down, but on my first try I went too far, and I couldn’t focus the image correctly (focal point behind the image sensor). so I re-added the pedestal. If I do it again, I might see if I can 3D print a solution which allows the camera to be returned to stock (but I know it won’t be!)

    The other thing I’ve been working on this week is to replace the incandescant bulb with a bright white LED, and to wire up the loom to the GPIO, but I’m having issues with that right now! I can switch them on and off externally, but ideally I think it would be nice to control the LED brightness with PWM, so you can dim. I’m not sure what the effect of mounting the diffuse LED underneath the stage will do to the PiCamera. I know that LEDs give off very intense light that can bleach out shots when aimed at the camera

    Must find the time to finalise my build – I was actually thinking of making a more general microscopy build that could be added to any optical microscope in the classroom.

    Great to hear about your build! Please link to it when finished!

    Like

    • No, not as of yet. I was going to investigate what the current/voltage combination was for the lamp, and how to trigger GPIO events from the web interface. I’ve been busy preparing my many students for the exam period. I will be tinkering again in June, and I will post any progress that I make.

      Like

    • I have now sorted this so that it is controlled over the GPIO. You can connect LEDs into the bulb holders relatively easily, just check polarity. Wire a resistor in, and then make sure that they have a common ground, and use the two 3V lines on the GPIO. You can then control this in python, using the rpi.gpio or gpiozero libraries. The gpiozero library allows you to fade or pwm control the brightness of the LEDs, but it may cause flickering.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s