I have come across a few ways at work just because I work at a Uni
A reagent reacts to the compound and changes colour, ie fancy litmus paper.
Think pregnancy test method.
A PCR replicates DNA until there is enough to be detected by stokes shift florescence.
FYI, Pi's Zero's make good PCR controllers, hint - avoid Linux
As Jamesh says, it is all in the sensor, even Adafruit now sell the "right" sensor.
NMR, uses magnetic resonance of old numbered protons.
Typically the Hydrogen in water and Carbon13 in organic compounds.
You can make you own NMR, I have yet to make a Pi controlled one, no one has asked yet
Depending on the strength of the magnets, more complex molecules can be analyzed.
Higher magnetic fields determines the resonance frequency.
Earths magnetic field is a few KHz, DIY ones on YouTube
Benchtop ones at 80MHz with rare earth magnets.
Superconductive magnets in liquid Nitrogen/Helium 300 to 800MHz.
A Pi based one should be able to do 1KHz to 10MHz without getting too fancy.
Gas chromatography is used in that paper.
Yep Google say you can DIY with a Arduino
Use a bit of DVD and Pi Camera to make a spectrometer?
https://publiclab.myshopify.com/collect ... 7504787563
Multispectral sensors are getting cheaper and better all the time, they are even putting them in Smart Phones now.
Most are i2c based.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges