I have been trying to setup experiments using the spectrometer plugin, I am interested in reading GFP, (like some others)
I wanted to use the spectrometer, but instead of using its built-in white light source, I wanted to use my purple or blue LEDs, which may be brighter and will not overlap with the emission spectra. I thought the spectrometer would bypass the need for filters mentioned here: Measurements of GFP/RFP with specific read - #2 by CamDavidsonPilon
I have found that when the spectrometer takes a reading, it turns off the LEDS, so currently, that won’t work.
I’m currenlty looking into if its possilbe to initiate a reading without turning on the built in LED (i haven’t figured that out)
Simple test — Adafruit AS7341 Library 1.0 documentation (circuitpython.org)
I understand why we want to link the spectrometer readings to the OD readings, so that they don’t interfere, however I’m not sure this is the most enabling approach, and if there might be some higher level ‘light-based’ actions/readings that can be used to coordinate all LED and Sensor actions.
The point of this post is to hopefully recruit some guidance or advice:
- is this something that is physically possible (not sure I can read with the AS7341 without activating the LED) ?
- how straightforward or challenging would this be for me to implement? Would modifying the spectrometer plugin be enough, or are there challenges due to the OD reading dependence?
I’ve taken a crack at revising the plugin (with some LLM help)
spectrometer revision.zip (2.6 KB)
Is testing/debugging this as simple as overwriting these files on the raspberry pi?
Hi @DocRuzzy,
These are good questions!
I’m currenlty looking into if its possilbe to initiate a reading without turning on the built in LED (i haven’t figured that out)
In Python, anything is possible! However, since this seems like a feature that we should build in to the original plugin, so I’ve done just that.
You can download the latest spec plugin (version 0.2.9, just released this morning), and this should have configuration for keeping the Pioreactor’s LEDs on during a reading, and turning off the onboard LED:
[spectrometer_reading.config]
...
# led_current_mA recommended to be less than 30. Set to 0 to turn off completely.
led_current_mA=0
# a boolean: 0 or 1.
turn_off_leds_during_reading=0
To get the latest version, first uninstall the old version:
pio plugins uninstall spectrometer-reading-plugin
and then install again:
pio plugins install spectrometer-reading-plugin
Great, thanks!
I am still in the process of testing my revision so I hesitate to recomend it. But if you take a look at it, it should make things even better as it will not just not turn off the leds, but turn on the proper ones.
Here’s the way I debug plugins:
- Copy the Python code (usually in a
__init__.py
) to a new file in ~/.pioreactor/plugins/
. Example:nano .pioreactor/plugins/spec.py
- So long as the python has
click
code at the bottom, something like:@click.command(name="spectrometer_reading")
def click_spectrometer_reading() -> None:
...
you can run it manually with pio run spectrometer_reading
. Python code in the ~/.pioreactor/plugins
folder will overwrite any other installed plugins, so you don’t need to worry about existing plugins installed via the UI interferring.
- I like to put lots of
print
or self.logger.debug
statements my code during debugging so I can see outputs while running.
- When you’re happy, you should remove the plugin (or keep it to continue using it) with
rm ~/.pioreactor/plugins/spec.py
.
A quick look at the code you provided: looks pretty good! Try using my method above to test it locally.
Another useful tool for debugging a job like this it to watch messages hit MQTT (the realtime message queue). In another window, you can run:
pio mqtt
and watch values from the spec come in, too.
This is my first try at writing and debugging code on a remote machine and starting with someone elses github repository.
My methodology is poorly developed so this is helpful.
I typically use WinSCP to copy files, when I download the zip of the code, there is a first folder which includes setup.py and read.me and inside that is another that seems to contain the main code. Should I copy the parent or the sub folder to plugins?
(i do plan to figure out a better process, but this is what I know how to do now)
To test your code, you don’t even need to do all that. The Python code is in a single file, so you can just follow my advice here Control of light-based readings - #5 by CamDavidsonPilon, and in the spec.py
file, paste in your code from updated-spectrometer-plugin.py. Also add your new configuration to the config.ini.
Like, this might sound weird, but you can follow two paths:
- Completely ignore my repo, and use the code you wrote. For that, follow above.
- To use my code (and ignore yours), just perform the uninstall/install process here: Control of light-based readings - #3 by CamDavidsonPilon
Great that is easy. I’ll do some testing and report back
I’ve eliminated all errors and it seems to be working. I started working on some calibration intended to keep the sensors from saturating later on, but I stopped as I’m not sure what’s in your led calibration now, (maybe the as7341 can be used) but I was not yet planning to unwrap how to address both gain and LED intensity, so I have not worked on that part anymore.
Feel free to implement this code if you want.
pause/found an issue
on persistent issue, no matter what I’ve tried, is getting the proper attribute for channels on the as7341
2024-10-08T09:46:55-0400 ERROR [spectrometer_reading] Error accessing f8: ‘AS7341’ object has no attribute ‘f8’
I’m also getting some
|93.12 h|pioreactor4|spectrometer reading No valid reading for wavelength 415|
|—|—|—|—|
|93.12 h|pioreactor4|spectrometer reading All readings are None. This might indicate a sensor issue.|
so, before I move on I’m hoping to figure out the correct attribute to access the sensors on the AS7341
Spectrometer Plugin.zip (10.3 KB)