Close
0%
0%

Raspberry Pi Spectrometer

The PySpectrometer is a Python (OpenCV and Tkinter) implementation of an optical spectrometer for the Raspberry Pi.

Similar projects worth following
The PySpectrometer is a Python (OpenCV and Tkinter) implementation of an optical spectrometer. The motivation behind this project was to build a tool that could measure the wavelength of home-made Dye Lasers and perform some fluorescence spectroscopy. Most importantly at a cost that is in reach of everyone. (Released Under Apache Licence)

The hardware is simple and widely available and so should be easily to duplicate without critical alignment or difficult construction. The hard work was developing the software.

Resolution/accuracy seems to be +/- a couple of nm or so, pretty reasonable for the price of the hardware, especially when you consider the price of commercial components such as the Hamamatsu C12880MA breakout boards which run north of 300 bucks, and has a resolution of 15nm. Of course, this build is physically much larger, but not enormous!

The Project is hosted at GiHub and all source code can be found here: https://github.com/leswright1977/PySpectrometer

The PySpectrometer is a Python (OpenCV and Tkinter) implementation of an optical spectrometer. The motivation beind this project was to build a tool that could measure the wavelength of home-made Dye Lasers and perform some fluorescence spectroscopy. Most importantly at a cost that is in reach of everyone!

The hardware is simple and widely avilable and so should be easily to duplicate without critical alignment or difficult construction. The hard work was developing the software.

Resolution/accuracy seems to be +/- a couple of nm or so, pretty reasonable for the price of the hardware, especially when you consider the price of commercial components such as the Hamamatsu C12880MA breakout boards which run north of 300 bucks, and has a resolution of 15nm. Of course, this build is physically much larger, but not enormous!

Visit my Youtube Channel at: https://www.youtube.com/leslaboratory

A video of this project specifically is available here: https://www.youtube.com/watch?v=T_goVwwxKE4

Hardware

Screenshot

The hardware consists of:

A commercial Diffraction grating Spectroscope https://www.patonhawksley.com/product-page/benchtop-spectroscope

A Raspberry Pi Camera (with an M12 Thread) https://thepihut.com/products/raspberry-pi-camera-adjustable-focus-5mp

A CCTV Lens with Zoom (M12 Thread) (Search eBay for F1.6 zoom lens)

Everything is assembled on an aluminium base (note the Camera is not cooled, the heatsink was a conveniently sized piece of aluminium.)

Screenshot

Screenshot

Installation

Developed and tested on: 2021-01-11-raspios-buster-armhf-full.img for anything else your milage may vary!

Rasberry pi 4 and PiCamera Recommended.

(Note the software uses the Linux Video Driver, not the Picam Python module. As a consequence it will work with some webcams on probably any Linux box (Tested on Debian with a random webcam))

First attach the Picam, and enable it with raspi-config

Install the dependencies:

sudo apt-get install python3-opencv

sudo apt-get install python-dev libatlas-base-dev

pip3 install scipy

pip3 install peakutils

Run the program with: python3 pyspectrometer-v1.py

To calibrate, shine 2 Lasers of known wavelength (He-Ne, Argon or DPSS recommended! (Diode Lasers can have wavelengths that can be +/- several nm!)) at a piece of card in front of the spectrometer.

Click the two peaks on the graph, and in each of the boxes enter the corresponding wavelength. Then hit 'Calibrate'. In this example I have Calibrated with 532nm (DPSS) and 633nm He-Ne. The Scale and lablels will then adjust to match your values.

For good accuracy make sure your wavelengths are quite far apart, ideally one at the red end and one at the blue end

Screenshot

Alternatively, you may use a Fluorescent tube (or any other gas discharge tube) in front of the Spectrometer, you will have to research the wavelengths of the emission lines (Mercury for Fluorescent tubes, Neon, Argon, Xenon for other types) That will be an excercise for you!

Other settings

"Label Peak width" and "Label threshold" set the width of a peak to label, and the level to consider it a peak respectively. The Defaults are fine, but if you find the graph too cluttered, you can play with these values.

Snapshot, takes a snapshot of the graph section like this: Screenshot

Example Spectra

Here is an example of the spectrum of a fluorescent bulb. The peaks at 405,435,545,650 are Mercury, Europium (one of the lamp phosphors) is visible at ~610nm.

Screenshot

Measuring the wavelength of a cheap red laser pointer (661nm)

Screenshot

Measuring the wavelength of a cheap violet Laser pointer, note the strong fluorescence from the paper! Paper is optically brightened with a fluorescent dyes, most likely Coumarin.

Screenshot

The spectrum of Daylight (pointed out of the window at a blue sky)

Screenshot

The spectrum of of a Helium-Neon Discharge.

Screenshot

Minimum smoothing...

Read more »

Zip Archive - 2.42 MB - 08/09/2021 at 20:30

Download

View all 8 project logs

  • 1
    See Details!

    Please see the details above!

    The physical build is simple. The heavy lifting is all done in Software, which is Open Source!

View all instructions

Enjoy this project?

Share

Discussions

j wrote 09/01/2021 at 13:38 point

Nice Project! 

Do you have any identification routine with backend database, if not is it planed? Keep up the great work!

  Are you sure? yes | no

LesWright wrote 09/01/2021 at 20:51 point

Do you mean a database of known emission spectra against which to compare the spectra being viewed?

I suppose it could be done, though I suspect it would be a lot more complex than you might expect. It depends what you want to measure.

If you wanted to measure emission spectra for example, say from gas discharge tubes and the like, it could probably be done in quite a straightforward fashion, as they produce light in discrete lines.

The same should hold true for Fraunhofer lines. Being discrete bands, it should be possible to root out and identify those as well.

Curves on the other hand (absorption and emission), well that is going to be a real challenge! A quick google, leads me to believe there are Python libs that might well be suitable to compare curves...

I can certainly look into it (time permitting). As described above discrete lines would be the place to start

  Are you sure? yes | no

j wrote 09/01/2021 at 21:38 point

Yea, that's what i mean. 

Finding those maxias and compare them of all known discharge spectra sound like a good start. I see the complications with reflective measurements. 

I'm working on a cost effective reference sample for a baseline for proper comparable reflection coefficients measurements, made with barium sulfate and white paint - if it's done properly its as white as spectralon, witch it's quite high in price. 

How many Channels did you acquire with this setup? It looks like >500 with a FWHM of about 1 nm, as you mentioned.

Just for the kicks: Do you see chances to see the hyperfine D-lines of discharging sodium ? Would a full HD cam or 4k and maybe a tiny slit in front of the tube help to see those lines? The D-lines of sodium are at 589.59 and 588.99 nm, so the resolution for that should be <0.6 nm.

sorry for getting nerdy here (:

  Are you sure? yes | no

Comedicles wrote 08/31/2021 at 21:51 point

I gotta ask, why use Tkinter on a Pi? You can easily use PyQt and get a more versatile and better looking GUI.

  Are you sure? yes | no

LesWright wrote 09/01/2021 at 12:01 point

It's already included in Python, so one less thing to worry about and I have coded with it before. You are right though, Tk does have its limitations, though it was good enough to get the job done. I am sure there are better looking packages.

  Are you sure? yes | no

Lightning Phil wrote 08/22/2021 at 17:57 point

Just received a diffraction spectroscope.  Nice instrument!  Hope to find time to make a spectrometer.  In the mean time, looking at things through it is fun.

  Are you sure? yes | no

LesWright wrote 08/22/2021 at 18:23 point

Awesome! It's beautiful right. Nice spectra to be had, even around the home!

  Are you sure? yes | no

LesWright wrote 08/14/2021 at 20:34 point

You are welcome!

  Are you sure? yes | no

Kev wrote 08/14/2021 at 15:07 point

This is very cool, I like this. Thank you for sharing.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates