Sunday, December 23, 2018

Home-brew Spectrometer

Due to a quality control problem at a local marijuana dispensary, we found the high-CBD plants we thought we had actually were unknowns.  This became apparent when the plants got big enough to exhibit their typical growth habit and odor (smell can vary widely among different clone types).  To make it clear:  we want high CBD for pain management.  Not interested in getting high.

Via online searching I found a chemical test for CBD and it showed that just one of the 3 clones contained much CBD -- but, unfortunately, the test is not very quantitative.  It relies on the development of a purple color when the plant material is added to a 5% solution of sodium hydroxide dissolved in alcohol.   The darker the color, the more CBD is present.  But eyeballing is not very accurate.  I started thinking that a spectrometer might improve the accuracy of the test.  In addition to the alcohol-hydroxide test, there is a very sensitive test that will stain THC and CBD slightly different colors.  It is a dye called Fast Blue B, dissolved in water, and is used to develop thin layer chromatography (TLC) plates.  So it MIGHT be possible to determine the ratio of THC and CBD by using Fast Blue B and a spectrometer to resolve the different colors.

But commercial spectrometers are expensive.  Sure, it is possible to find them for less money on Ebay:  but often they need software and a computer, and if the package is complete the price goes up.  The other aspect of this work is to hopefully make it possible for others to do the same measurements on their own material, so a one-off purchase from ebay won't cut it.   As an alternative I found an open-source spectrometer here.  Cost is around $50.  For that you get a web cam, an optical slit, a CD-R disk (to turn into a diffraction grating), a black cardboard box and materials to assemble it all.  I put the thing together and found it wasn't mechanically stable enough to generate repeatable absorption spectrograms.  So I used the essential parts -- the camera and slit -- and built my own spectrometer.  The photos below show the spectrometer I put together.

Exterior showing the slit and lid.  The "hinge" is a length of adhesive-backed aluminum (which is opaque to light).


This is a photo showing the "optical holder" design.  It is a block of oak with a flat-bottomed hole just large and deep enough to glue in a super magnet.  The bottom of the spectrometer is a steel plate, so the blocks stay put -- but are easy to move around to optimize the optical path.

And here is a photo of the interior.  The diffraction grating is glued to one of the optical blocks.  I sawed a slit in the block to provide a robust mounting point for the grating.  The web cam is attached to an optical block using heavy-duty double-sticky tape.  The corners of the enclosure are reinforced with wood blocks that were glued in place.  The top, sides, and ends of the box are made using foam-core poster board.  Black, of course.  I also put a length of the poster board on the bottom, to reduce reflections that would degrade contrast of the spectrum.  I had some black silicone caulk so I ran a bead along the front corners and along the bottom edges as well, to reduce light leaks.

And here is the spectrum of a CFL lamp, obtained using my spectrometer:

Unfortunately, I found the web camera is not compatible with the Public Labs spectrometer software.  At least, not on my linux laptop.  So I found it necessary to write my own program(s) to do the job.  I found a starting point here but it has a fairly serious memory management problem -- it acquires a bunch of frames, and only then performes averaging.  I modified the code to acquire one video frame, then extract ONE line of interest for processing.  This way I can average over any number of frames without running out of memory.  I also wrote a version to get the calibration factors needed to convert pixel positions to wavelengths.  The end result is a system that easily resolves the two green emission lines around 540 nanometers, and has a low noise level in the data.

Now I can move on to testing my THC/CBD measurement idea....