# Ethernet Controlled Graduated ND Filter

## Problem:

So, after the excitement of fixing the shutter jitter mentioned in the ‘Reverse Engineering the D750 Shutter for Remote Control’ project, I was able to take a nice looking SSPC signal from 3 samples but I noticed something interesting. Ideally, the SSPC signal below should only show slope increases when the incident energy is enough to excite trapped charge into the conduction band or out of the valence band but it seemed that the signal could be perturbed by some of the peaks in my 350W mercury source. In order to publish the data this needs to be fixed so that I’m not trying to make conclusions based on faulty data.

## Solution:

As always, I checked for an existing solution that may be within financial reach but once again found they were much too expensive. The only thing I needed to do was control how much light was able to pass into the end of a fiber optic and quickly found that Newport and ThorLabs sold a circular and rectangular graduated ND filter. If possible I would have liked to use the circular one since attaching it to the end of a stepper motor would have been very easy but they were VERY expensive (>$1K) compared to the rectangular ones (~$114). Since the optics had been selected I only needed to figure out how to slide it in front of the light path. Having read a lot about 3D printers and how open source they have become, I decided to invest in a cheap (\$75) stepper controlled linear actuator which I could mount the rectangular ND filter on and then slide in front of the optical path. Below is the linear actuator with the ND filter mounted.

Once I had the ND filter mounted it was time to setup the hardware so that it could easily be controlled by a LabVIEW program I had running on our main characterization computer. To control the stepper motor I first tried to use a generic L298N board I bought from eBay but quickly learned that an H-bridge wasn’t the most efficient way to control a stepper mainly because there was no circuitry to limit the current through each of the stepper coils. This resulted in saturating the coils with a 12V supply when the motor wasn’t moving. After a little research the DRV8825 Polulu clone from Amazon would be the best solution as far as price and usability. An Arduino seemed like the most sensible choice for quick prototyping but I wasn’t comfortable running a long (>30ft) serial cable across the lab so I decided to acquire a generic ENC28J60 board for Ethernet communication. Below is the circuit I used to interface all three boards boards along with the stepper motor. NOTE: The ENC28J60 is 5V tolerant but requires its own 3.3V power supply. I used two Buck converters to transform the 12V/2A wall wart to 3.3V and 5V.

The Arduino was programmed to act like a TCP server (using the UIPethernet library) which could be connected to by a LabVIEW running a TCP client program. The client connects and sends a short string which the Arduino server would interpret and either move or return requested data (Arduino program attached at the end). The next step was to check the range of attenuation I could achieve with my new apparatus. I set the wavelength to 435nm (one of the larger peaks in an Hg lamp spectrum) and moved the ND filter while taking optical intensity measurements. The intensity vs. motor step is shown below.

Finally, I created the algorithm to calculate the motor steps away from the limit switch which would give the correct attenuation value and once again measured the spectrum of the Hg lamp. As you can see below the photon flux at each wavelength is much more consistent but a lot of light power is lost.

# Arduino Code

The Arduino code is long but pretty simple. I decided that the speed of moving the ND filter did not matter as much as the resolution so I chose to micro-step at 1/32. The first piece of code I wrote was to reset the stage to a known location. To accomplish this I quickly stepped the motor until I hit the limit switch at which point I SLOWLY micro-stepped off of it until it was no longer depressed and set the current location to ZERO. Next, I manually moved the stage to a few steps prior to hitting the far side and then I would run the ResetMotor() function to check how many steps it would take and found that 138,000 steps was the maximum I could go before hitting the other side. When testing for backlash and motor slippage I found that if I moved the motor <500 steps at full speed it would miss a few so I wrote a check in the MoveSteps() function that would move the motor a little slower for small motor movements. As for the Ethernet code, I basically used the UIPEthernet TCPserver example to setup the ENC28J60 to receive TCP packets and parse the data portion into a String. From there I just setup a few command strings to be recognized (GT, CS, RS, and EN) and then parsed accordingly (ex. GT120000(CR) would go to step 120,000). NOTE: The only way I could get LabVIEW to connect to the ENC28J60 was if I gave it an IP address VERY close to the computer.