iPhone Polarisation Camera

This project describes the construction of an iPhone accessory which allows pictures of polarised light to be captured. It is based on previous work by David Prutchi which should be referred to for more details.

Principles of operation

The device is based on a screen from an auto-darkening welder’s mask purchased on eBay. This is constructed from a liquid crystal panel sandwiched between two cross polarised sheets. When no voltage is applied to the liquid crystal it rotates incident light by 90 degrees and so the light passes through fairly unimpeded. When about 5V is applied the rotation drops to zero degrees and blocks the light.

Removing one of the polarised sheets produces a voltage-controlled polariser. Prutchi showed that there exists a voltage between 0 and 5V where the incident light is rotated by 45 degrees. By taking three images at 0, 45 and 90 degrees the degree and angle of polarisation can be determined for each pixel in the scene and visualised.

The precise voltage at which 45 degree rotation occurs varies over time so a way is need to calibrate the polariser. In this design a piece of polarising sheet is placed at 45 degrees and light from the iPhone’s flash-light is shone through and detected with a photo-transistor. By varying the voltage across the polariser, a minima in transmitted light occurs when the 45 degree polarisers cross. This minima can be detected and used to set the corresponding 45 degree voltage reference.

ds1054
Bottom trace – polariser voltage. Top trace – light detected by the photo-transistor. A clear minima can be seen.

The iPhone’s flash-light is also used to synchronise the change in polarisation with the image taking. The iPhone blinks the flash-light after every three images have been taken. The device uses this flash to reset the 0,45,90 sequence to a known state.

ds1054
Top trace (blue) – light pulses from photo-transistor. Bottom trace (purple) – synchronised voltage applied to the polariser.

Firmware

An Arduino is used to control the polariser. A photo-transistor located facing the iPhone’s flash-light LED is connected to both an external interrupt pin and an analog pin. Short pulses on the LED cause interrupts in the Arduino code which are used to synchronise the polariser. Long pulses on the LED cause the Arduino to enter calibration mode.

The time interval between synchronisation pulses is continuously measured and divided into three equal parts. On receiving a synchronisation pulse the voltage is set to 0V for one part, to the 45 degree voltage for one part and finally to 5V for one part.

Voltage for the polariser is supplied from an Arduino PWM output pin. To get a reasonably stable output the PWM frequency was increased to 32 kHz and smoothed with a second order RC filter.

The liquid crystal display will be damaged by a constant DC voltage so a CMOS switch is used to alternate the polarity. A 2 kHz square wave generated from a free running Arduino timer is used to drive the switching.

schematic

 

Hardware

The polariser was mounted on a cheap iPhone cover so that it covered the camera lens and the flash-light led. The photo-transistor was mounted in a strip of wood and taped to the polariser facing the iPhone flash light. For calibration a small strip of polarising film was cut at a 45 degree angle and inserted between the photo-transistor and the polariser. The circuit was made up on a scrap of strip-board. A separate battery pack was used to power the device.

IMG_6112
Assembled device
head detail
Camera head detail

iPhone App

The iPhone app is responsible for the UI and image processing. It is written in Swift.

Image frames are continuously captured from the camera. The time for three images to be captured is measured. A minimum of 60 ms per image is required and if needed intermediate frames are skipped to allow the polariser enough time to change between states. The flash-light is blinked after every 3 images to synchronise the polarisation. The blink is delayed by a variable amount to shift the alignment of frames to the changes in polarisation. A slider is provided to alter the alignmentdelay.

When three images have been received corresponding to 0, 45 and 90 degrees polarisation, they are processed to generate a representation of the scene which is displayed on the screen. Custom GL kernels are used to solve the Stokes equations and generate either an RGB or HSV visualisation of polarisation parameters. These calculations run on the phone’s GPU and so are easily able to keep up with the camera’s frame rate.

A “Calibrate” button turns on the flash-light for 2 seconds. This triggers the Arduino to run a calibration of the 45 degree voltage level, and provides the light to do so.

A selector allows a choice between RGB or HSV visualisation.

A “Shutter” button takes a picture by saving the latest processed image to the camera roll.

Full source code for the Arduino and iPhone is available here.

Example Images

IMG_6002[1]
Laptop cover illuminated at a shallow angle from rear showing horizontal polarisation (HSV)
IMG_6075
CD jewel case in front of laptop screen showing stress patterns (HSV)

 

IMG_6111
Car, RGB visualisation
IMG_6106
Car, HSV visualisation

Nixie voltmeter clock

IMG_5882

I recently acquired a vintage nixie tube multi-meter on eBay, with the not so original idea of converting it into a clock.

However, rather than hack around with the internal circuitry, I decide to see if I could keep the meter intact and use the existing voltmeter functionality to display time.  The basic idea is to send the meter a voltage corresponding to the time, so e.g. 12:45 becomes 12.45V. The meter has a 20V range which displays a fixed 2 decimal places which suits my purpose just fine. Unfortunately there is a hard limit to 20V on this range so a full 24 hour clock is not possible, but a 12 hour clock and maybe a 20 hour clock are.

The high level schematic is:

RTC -> Arduino -> DAC ->Multi-meter

IMG_5880

 

Each minute on the display corresponds to 10mV so the DAC must be at least this resolution. I used an AD5501 which has 12bit resolution and can work at up to 60V. For my needs I used the 30V range which works out at 7.3mV per bit, just enough. This DAC also has an integrated voltage reference which reduces the component count. It comes in a TSSOP package so was soldered onto a breakout board for easier prototyping.

For the RTC I used a DS3231 module. This is accurate to about 1 min/year and has a battery backup. It can be controlled from the arduino over an I²C bus.

The Arduino runs a simple program which at every new minute gets the current time, calculates the required voltage for the time, offsets it by a calibration factor and sends it to the DAC. The program also accepts a few commands over the serial port to calibrate the display and set the current time.

Here is everything running on a breadboard:

Breadboard layout

For power, rather than tap into the internal multi-meter power buses I hooked up a simple 240VAC/5VDC module with a cheap Chinese boost converter to give 15V for the analogue power.

The meter has space inside for a battery so there was no need to miniaturise the component layout and I just wired the modules together on a bit of strip-board, fixed it to an insulating base and popped it into the meter.

 

Capture

Connecting various lab instruments to ethernet

I have an assortment of lab instruments that I’d like to control from a PC. They have a range of connection options: RS232, USB, GPIB, Ethernet and support the SCPI protocol. Decided to standardise on Ethernet.

The three Rigol devices all have Ethernet connectivity so I assigned them all fixed IP addresses via the front panels, plugged into the LAN, and then connected via telnet (putty) to port 5555.

Rigol DP832

Responded to *IDN? query OK

Rigol DS1054Z

Responded to *IDN? query OK

Rigol DSA815

No reply to *IDN? query. I suspected the DSA815 did not like the CRLF line termination from putty and sure enough, sending just a LF terminator (0x0a) from a simple test program worked OK.

The other two older machines did not have an Ethernet port, so I connected via two Ethernet/RS232 adapters. I used the USR-TCP232-2 module from eBay. This doesn’t provide any hardware flow control so will need to bear that in mind for the PC control software.

The instructions were not the clearest but in the end configuration was straightforward. Plug the device into the LAN and run the USR-TCP232-T24V5.1.0.1.exe setup program. Click “Search in LAN” and you should see your device in the list. Select “TCP Server” mode, give it a new IP address and set the subnet mask and default gateway for your router. Set the module port to 5555 to match that used by the Rigols. Configure the RS232 port as needed. Then click “Set selected item via LAN”.

Keithley 2015 THD

Set RS232 comms to 19200,N,1,1 from the front panel. The 2015has a female RS232 connector and needs a M/M serial cable (crossover 2<>3, 3<>2, 5<>5). Set to no flow control for now. It also has the option of XON/XOFF flow control which might come in handy.

HP 33120A

Set RS232 comms to 9600,N,1 from the front panel. This unit requires 2 stop bits. It also requires pin 6 (DSR) to be held high when hardware flow control is not used. The unit has a male RS232 connector and needs a M/F null modem cable (2<>2, 3<>3, 5<>5, 6<>6). On the USR-TCP232-2 module I soldered a jumper lead from the +5V power pin to pin 6. Does the job.

IMG_5852

HP 34401A

Same as HP 33120A above.

MolPad released to Windows App Store

Description

MolPad is a chemical structure drawing app specifically designed for tablets. It allows you to draw chemical structures freehand with a finger, stylus or mouse, just as you would with pencil and paper. The raw ink is converted on the fly to an underlying connection table. Both chemical bonds and handwritten atomic symbols are recognised, cleaned and incorporated into the structure.
screenshot_11222014_123756

Features

  • Intuitive to use
  • Designed specifically for tablets
  • Chemically intelligent
  • Recognises bonds and basic atomic symbols
  • Gesture support for drawing rings
  • Supports industry-standard Molfile format

Find MolPad here.

Feedback and suggestions for improvement welcome!