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

Benchmarking the Pi 2 with Minecraft, TNT

We managed to get hold of a Raspberry Pi Mark2! It is purported to have 6x the performance of the Pi B+ but check the great blog post from Eben Upton about how those benchmarks were calculated.

Naturally we wanted to do our own key benchmarking tests, so we set out to compare the B+ and a Pi 2 together.

When we set up our 8 Raspberry Pi model Bs originally, the STEM crew followed Martin O Hanlon’s excellent Python and Minecraft tutorials and Whaleygeek’s python flashcards and started making some very cool scripts, like auto digging and cubes of bombs on demand.

One of the early challenges was to make a 64, 125 and 1000 block sized cube of TNT and detonate it.  Upon detonation of The Big One(TM), the Pi’s processor load chart would max out, and the fps would drop to about 1 frame per every couple of minutes. Eventually, the Pi would come round again, but it generated a lot of heat from the processor, so much so we thought about using heat sinks.

So – we thought it would be a great empirical benchmark for the new generation of  Pis.  We tried to set up 4 different Pis, with the most up-to date build of Raspbian (but ended updating the A+ and B for ages) , loaded the same script in all of them, and executed them in the most synchronised way we had available (pressing the execute buttons at the same time).  We timed how long it took for the processor load to drop below 50%.

It’s obvious the Pi2 has a great deal more grunt, and the extra processor speed and RAM really contribute to performance. You notice it especially when browsing or watching HTML5 YouTube: it’s a feasible computer replacement whereas the Model B was a tinkering machine or sandbox that you could use, if you were patient.

Our next experiments are to get piplay loaded on and perform some emulator benchmarks, and see if it can be built into one MAME Joystick to rule them all!

Raspberry Pi Radio.

While teaching students about how radio signals are used to send information using FM  I decided to make a raspberry pi radio transmitter using the instructions from Makezine and Instructables, so that we could explore the range of transmission, and the effects that different aerials would have on the radio signal.

http://www.instructables.com/id/Raspberry-Pi-Radio-Transmitter

http://makezine.com/projects/make-38-cameras-and-av/raspberry-pirate-radio.

The PiFM python module was created by Oliver Mattos and Oskar Weigl from the Imperial College Robotics society,  and can broadcast 16 bit mono WAV format sound files that can be played on any FM receiving radio.

Makezine made a pre-compiled install image that autoruns the transmitting software on boot, and will shuffle audio files that have been placed in the root directory.  I’ll be honest, their video was a bit Hipsterrific for my liking, but it got me interested enough to tinker.

The basis behind the generation of the signals sounds simple enough: GPIO4 is modulated via PWM fast enough to produce a signal in the FM (megahertz) range.   However, I quickly realised that it produces a lot of interference in nearby devices, and there are clear side bands of interference in neighbouring frequencies. (Just tune the radio through the frequency range and you’ll find many sidebands)  Although the power output of the device is so low, it might interfere with Emergency Service radio, and as we are located very close to a Fire Station, we decided to exercise caution!

With an FM radio right next to the Pi, it picked up the signal very clearly, but dropped off within 3-5m.  With a 15cm crocodile clip wire attachedto GPIO4  the range jumped to 20-30m radius, and was very clear.

Some builds have used Duck antennae in order to boost the signal broadcast radius, but presumably this would also boost the strength of the side bands, and would drown out commercial stations at short range.

Build Notes:

Extremely easy, and very quick to get results.

Minimal materials needed, and little expertise required for students.  Easily replicable.

Next Steps:

School radio station?

Using the piFM RDS code on github to send track information, and station Identification info.  Code:https://github.com/ChristopheJacquet/PiFmRds