Monday 26 January 2015

Eyepiece - Back to the camera.

This afternoon I reached the point of being able to test the Raspberry Pi camera module against one of the eyepieces from the microscope.

In order to do this, I kludged together an illuminator (using four white LEDs) and a printed image that sits in the graticule tray - an object that is in focus at the same time as the image from the microscope objective.

By holding the objective to the camera, I was able to estimate the separation between camera lens and eyepiece required for the best possible image - as well as to determine whether any intermediate lenses would be required.

The test was unexpectedly an immediate success. With the camera sat against the built in eye-cup on the eyepiece (a Vickers x10 Complan), the (circular) test image almost filled the height of the rectangular image - meaning that with a little tweaking and with the creation of a suitable adaptor, the camera is essentially able to be used as-is.

The graticule image - this was scaled down to a 19.5mm diameter.
In the graticule image above, the edge of the graticule mount covers the edge of the image - the fine, black line representing the expected limit of the vignette.

First Test - captured image through the eyepiece
As you can see, the test image is rather grainy - this is because the image is of a tiny picture printed out using an ink jet printer. There is also some distortion, but this is mainly due to the graticule being somewhat misshapen.

A blurred artifact (from the 3 o'clock to the 6 o'clock position) is the visual effect of some de-lamination in this eyepiece's optics.

The image is not properly centred because the test system was simply being held together in my hand. The pale mark in the lower left of the image is a reflection off of the inside of the eye-cup.

Conclusion:
This test was more successful than anticipated, and will warrant a proper adaptor being made in the near future.

Next steps:
A paper and card prototype adaptor will be used to perform more sophisticated testing and adjustment of the optical system. An acrylic design will follow, which will be capable of supporting the camera and associated computer while attached to the eyepiece.

Thursday 15 January 2015

Eyepiece - absolute position sensing using optical detectors.

There are several ways of locating the relative positions of two mechanical components:

  • Having a datum position (micro-switch, optical interrupter etc.) and calculating the position by measuring the number of pulses (opto-interrupter, motor steps etc.) taken to get somewhere.
  • Using an ultrasonic measuring device (sonar)
  • Using a laser measuring device (laser rangefinder)
  • Using laser interferometry
  • Using an optical scale and a series of sensors.
The first method is simple for the fine focus mechanism on the M55 microscope as this doesn't drift at all.

For the macro focus mechanism, using a datum and calculation doesn't really allow for the possibility of disturbing the set up, either while changing optics, swapping samples or drift due to the heavy sample stage that has to be braked.

Sonar and laser rangefinders are both relatively inaccurate and are both expensive and challenging to implement satisfactorily.

Laser interferometry is an excellent solution for extremely precise positioning, but is unnecessarily complex for this project. Interpolation between the 1mm marks of the scale will be done by counting stepper motor steps.

An optical scale can easily be designed and sensors may be recovered from such devices as old computer mice. This is the route I have settled upon.

Being something of a pack rat, I had half a dozen defunct mice of various types - most of which contained one or more optical interrupters (quadrature encoders for mouse ball position etc). These interrupters comprise an Infra Red LED and a dual Infra Red sensing Phototransistor - as two discrete components.

Unsoldering these is a simple task, yielding about 20 detector pairs.

How does an optical scale work?

Firstly, there are two geometries available - reflective and transmission.

The reflective detector shines a light (usually Infra Red) on a scale and the light level between white (reflective) and black (absorptive) represents a binary one or zero.

The transmissive system simply shines the light through a sheet of paper or plastic. Where the material is opaque, the light is interrupted and where transparent, the light is transmitted - representing the binary value as before.

By printing a grid pattern of black and white representing binary values from, for example, |000000| to |111111| (six bits), a position scale of zero to sixty three positions may be measured. 8 bits give a range of zero to 255. The rectangles on the scale (left) are 0.8mm high on a 1mm pitch, while the ladder on the far left has rectangles 0.25mm high at 1mm intervals - this represents the millimetre datum, and should ensure that the position detection is accurate to ±0.25mm.

Arranging for reliable reflective detection of these small panels is beyond most domestic electronics workshops. On the other hand, transmissive detection is as simple as positioning LEDs and detectors on opposite sides of a piece of paper and getting everything properly aligned. In theory, it should be possible, with the salvaged detectors, to measure down to 0.25mm, though this is rather more precise than the application actually calls for.

Precision - I may test out using a thinner mm scale ladder, or even go to 0.5mm resolution



The Electronics:

Testing the concept (as well as the individual devices) requires a simple circuit to be built. Because the sensitivity may need to be tweaked, I built this using breadboard with a suitable 5V power supply.

Optical position test circuit
The two phototransistors in the package are connected in parallel, giving a degree of redundancy.

The IR LED (D1) illuminates the phototransistors (PH1.1 & PH1.2).

When illuminated, they begin to conduct through R2, pulling the input of U1.n low. U1 is a hex inverter with Schmitt inputs (74LS14), which removes the uncertainty of when the device switches between .true. and .false.

The LED (D2) provides visual confirmation of the output state of U1.n.

The value of R2 alters the sensitivity of the input - values between 82kΩ ind 180kΩ will adjust between insensitivity and extreme sensitivity respectively. 82kΩ is about right for the test IR LED that I was using.

Bit(n) represents the output to the computer.

Choice of material:
Printing the scale using an ink jet printer resulted in a much finer line, but an almost unusable scale due to the relatively low opacity of the ink. Doing the same using a laser printer resulted in an excellent dark/light sensitivity. Both scales were printed on standard photocopier paper.

Colour Scheme:

The scale is actually designed as a white panel = binary zero. This is because a generally dark scale produces less glare (crosstalk) between channels. Because of the way the detector and Schmitt input operate, this translates correctly, resulting in the output being a binary number of millimetres from the datum (maximum elevation of the microscope stage).

Mechanical support:

A paper scale, while easy to produce, is rather too flimsy for this application, thus I will, in the near future, try the transmissive detector using a scale that has been put through a laminator, otherwise, supporting it with a clear acrylic panel will be necessary.

Computer Input:

I have a Quick2Wire interface that will connect to the Raspberry Pi, and, using the port expander, will allow a number of additional interfaces to be connected while providing some protection for the GPIO pins of the Pi.



Friday 9 January 2015

Eyepiece - more on the Vickers M55 microscope

I spent time yesterday building a chassis for the stepper mechanism. Because the microscope has been modified to accept a bracket for a video camera (one of the big, old, heavy ones - which I do not have), I was able to use the mounting for this to attach the base plate. This plate is 2.5mm aluminium salvaged from an old piece of equipment. It will need a coat of the appropriate colour paint before it is finished.

The fine focus knob
 - with the old video-camera mounting base attached

The stepper chassis attached with mounted stepper motor and drive belt.




Some drilling and fiddling, and I have a removable base plate with a stepper mounted on it. Since I'm still waiting for the electronic parts to arrive, that is as far as I can go.

Once the chassis was built, I turned my thoughts to the macro lenses. Swapping the micro optics for macro optics is a five-minute exercise. I tried the incident illumination, and found that it is useless for looking at rocks (no surprises there), so I got out the oblique illumination attachment (a mirror on a simple swivel mount).

This is the first time I have attempted to use oblique illumination using the macro lenses, and discovered that the adjustment screw was sheared off.

An hour later, I had removed the broken piece of screw and had to find a 6BA screw to replace it with. Luckily, I have a big pile of old clock-repair parts, including a selection of BA size screws.

(The pictures show the oblique illumination mirror with the new part - which needs a coat of paint)

Some work with a countersink and emery-paper on an old bronze motor bush produced a respectable head of the correct size to turn a long countersunk screw into a short screw with a smooth knob for a head.A spot of steel epoxy permanently fixed the screw in the knob (with an exposed slot head to enable release with a screwdriver, if necessary).





Now, the way the micro-focus mechanism operates is by moving the objective lens up and down - which has a coarse focus knob and a fine focus knob (which now has a stepper motor attached.

The macro mechanism, on the other hand, moves the specimen stage up and down, using a large knob and a friction brake. This is also the knob that is used to move the stage out of the way in order to swap the optics.

This knob is big and rather stiff (it operates a physically heavy piece of equipment, after all), and if I want to do image stacking using the macro system, it means another stepper to operate this knob. I also need to be able to lock the position as the stage is heavy enough that the mechanism drifts downward quite rapidly when released with the locking knob released.

The range of motion is enormous (15mm between micro examination and x5 macro) - and this means that I will need to be able to adjust and lock the stage elevation automatically. Since I am planning on using the macro optics a lot, then this is a change critical to the project.

I have managed to find a higher torque stepper in my parts bin (I may have something even heavier duty knocking around - somewhere), and so I will try that for size.

Sunday 4 January 2015

Eyepiece - on stepper drivers and motion sensors

I have spent the past couple of days designing the electronics by which to control the stepper motor that will be used to operate the fine focus of the microscope for image stacking.

The mechanism has an extremely free operation and the end stops cause the knobs to continue to rotate through use of a fairy stiff friction clutch.

The output torque of a stepper motor is roughly proportional to the current through the windings, and thus to the voltage of the electrical supply.

The motor that I have has 40Ω windings, and is designed for use at somewhere around 20V - therefore, it would be possible to drive the stepper at a lower voltage, set so that the motor stalls at the end of the focus mechanism's travel.
Preliminary circuit design - stepper controller


Stalling a stepper motor (difficult to do when fully powered) doesn't damage the motor or the drive circuitry (one of the reasons for my choice of stepper rather than a DC servo motor).

I am still refining the design and features of the board which will be used to drive the stepper motor.


_______________________________


While on the subject of the focus mechanism, I wanted to be able to detect when the motor stalled. One way would be to use an optical encoder, either attached to the motor or to the focus knob, but the problem remains that if the knob bounces as the motor state changes, that small motion could well be registered as continued movement.

To prevent this, a quadrature encoder would be required - and thus calling for its own additional circuitry to determine whether the motor was stalled or not.

The alternative would be to use dome form of optical device to detect the net motion of the knurling on the knob.

Now, what device do we all use to detect relative motion?

A clue, most of them are attached to our computers and located alongside the keyboard.

A cheap mouse will do the job, and ten minutes effort with Google provided sufficient information to be able to, theoretically, access a USB mouse directly from software.

Edit:

I have now tested this idea - and, not only does it work, but it detects the three microswitches, too!

Because of the way Plug 'n' Play works, multiple mouse devices are separately enumerated, and their names placed in the appropriate directory
 /dev/input/by-id/ 

The python program that is used as a proof of concept is:

#!/usr/bin/python

# Core logic courtesy of PeterO on the Raspberry Pi forum.
#  http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=80987

import struct
import binhex

# You'll need to find the name of your particular mouse to put in here...
file = open("/dev/input/by-id/usb-192f_USB_Optical_Mouse-event-mouse","rb")


while True:


    byte = file.read(16)
#    h = ":".join("{:02x}".format(ord(c)) for c in byte)
#    print "byte=",h

    (type,code,value) =  struct.unpack_from('hhi', byte, offset=8)

    if type == 1 and value == 1:
        if code == 272:
            print "LEFT PRESS",
        if code == 273:
            print "RIGHT PRESS",
        if code == 274:
            print "CENTRE PRESS",
        print code

    if type == 2:
        if code == 0:
            print "MOVE L/R",value
        if code == 1:
            print "MOVE U/D",value

    if type == 0:
        print "Clear Event", type, code, value

    if (type <> 0) and (type <> 1) and (type <> 2) :
        print "other event", type, code, value


_______________________________


While I like to build my electronics on custom printed circuit boards and, indeed, have the software to do so, it tends to be somewhat expensive - especially should any error be made in the board design.

Since it is unlikely that this electronic design will ever be anything but a one-off, I have decided that I will be building using either proto-board or strip-board.
That is, to say, AFTER testing the design out using breadboard!