Developing a closed-loop feedback system via DotStar LEDs

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Developing a closed-loop feedback system via DotStar LEDs

Post by sgbaird »

This is for a low-cost self-driving lab demo that combines autonomous experimentation (inputs + outputs) with an optimization algorithm. The lowest-cost-while-still-being-interesting example I've been able to think of so far (open to other suggestions) is having a dimmable array of LED lights (Blinkt!), and a spectrometer (i.e. 10-channel light sensor). The Blinkt! array would be the tunable input parameters, and the spectrometer would generate the output signal. In a simple case, the optimization task would be to find an optimal set of RGB+brightness settings for the 8 DotStar-s (8*4=32 numerical parameters) that most closely matches a desired output spectrum (arbitrary, predefined). Optimization algorithms are my research specialty, so the help I need is mainly in the hardware and interfacing the hardware with an algorithm of my choosing (e.g. SAASBO).

BOM
I've been putting together a bill of materials: My Background
I've had some basic experience setting up a Raspberry Pi 4B using a headless connection (IIRC), getting it connected to WiFi, etc. but I no longer have access to it (hence the Pi 400 above). I'm well-versed in Python and have a basic working knowledge of hardware connections. I like the idea of being able to install Ubuntu onto a Pi 4B and the large available RAM (up to 8 GB), such that running memory-intensive ML algorithms isn't an issue. I'm open to suggestions for other microcontrollers/processors.

Hardware Setup
Here's what I'm thinking for the hardware connections:
  • connect the CYBERDECK Bonnet to the Pi 400
  • connect the spectrometer to the Stemma-QT cable to the Bonnet Stemma-QT port
  • Connect the Blinkt! to the Ribbon Cable to the Bonnet GPIO pinouts
  • Attach the spectrometer to a 90 degree angle bracket to a flat surface using adhesives
  • Position the Blinkt! to be perpendicular to and some distance away from the spectrometer using adhesives and a spacer (mounting block)
Software Questions

I'd like to avoid receiving the first order and realizing I'm missing something critical for getting initial tests set up. Related to that, I have three questions:
  • Does the hardware seem sufficient to the task?
  • Are there any software incompatibilities/difficulties that stand out? (aside from the ML algorithm, I'm mostly concerned about being able to send commands to the LEDs and read the spectrometer values)
  • Any other general feedback or noticed "gotcha"-s?
Happy to answer any questions if something isn't clear or if I missed something.

https://github.com/sgbaird

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Developing a closed-loop feedback system via DotStar LED

Post by adafruit_support_mike »

sgbaird wrote:Does the hardware seem sufficient to the task?
Without knowing the amount of RAM your system will need, I'll guess a Pi400 can handle it.

All 'nixes use virtual memory, with the option to save chunks that haven't been used recently to disk (a 'swap' partition). In theory that means you can have as much effective RAM as pluggable drive space, but in practice the system spends more time moving chunks of data between RAM and the disk than doing anything useful (called 'thrashing') when the swap gets more than about double the size of the physical RAM.

RasPis don't use a swap partition by default because SD cards are incredibly slow, but you can enable swap and assign it to an external drive or SSD module.
sgbaird wrote:Are there any software incompatibilities/difficulties that stand out? (aside from the ML algorithm, I'm mostly concerned about being able to send commands to the LEDs and read the spectrometer values)
Talking to the LEDs and the sensor should be easy. Those already have library support to handle the low-level details so you can focus on programming at a higher level.
sgbaird wrote:Any other general feedback or noticed "gotcha"-s?
Gotchas are almost inevitable for any new hardware, and run the gamut of 'the unexpected'. I don't think you'll get caught by anything more complex than wiring and connections though.

On that subject, take some time to get familiar with the LEDs and the color sensor individually before trying to hook them up to your optimizer. Take a couple of hours to run through the tutorials and get comfortable working with them, then do a few passes of setting the LEDs and reading the color sensor by hand. Having seen a process work is immesurably helpful when you start trying to build a more complex system.

User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Re: Developing a closed-loop feedback system via DotStar LED

Post by sgbaird »

Thanks for the reply! The notes about memory and the advice about gradually working up to the full system are great. Will post back as I continue developing this out.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Developing a closed-loop feedback system via DotStar LED

Post by adafruit_support_mike »

Another point: iterate from success to success, making small changes as you go.

System complexity icreases geometrically with the number of parts, and trying to debug an unknown system with three simultaneous problems is a nightmare. Even when you do exactly the right thing in one place, the feedback is distorted by the other problems in other places. It's nearly impossible to learn enough to make progress.

Working from success to success in a series of small changes limits the number of unknowns enough that you can actually learn something from the results.

User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Re: Developing a closed-loop feedback system via DotStar LED

Post by sgbaird »

Great point about unit testing of the components.

A related question, the Blinkt! array is great, but in the end, I'm only really getting 3 distinct wavelengths, maybe with some slight manufacturing variability across the different diodes. I've been looking around and have had trouble finding an addressable strip of progressively increasing wavelength LEDs. I've also looked into monochromators, but these are probably too expensive. Any suggestions on getting ~10+ wavelengths in the visible range where I can adjust the power to each (and have all 10 "shining" simultaneously)?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Developing a closed-loop feedback system via DotStar LED

Post by adafruit_support_bill »

Most individual LEDs have a fairly narrow bandwidth output. (The exception would be 'white' LEDs which use phosphors to create a broader spectrum output). An RGB led has just 3 narrow bands of output as you can see on page 7 of the SK9822/Dotstar datasheet: https://cdn-shop.adafruit.com/product-f ... _SHIJI.pdf

There are discrete LEDs available across many points of the visible spectrum. Unfortunately, they are not as convenient to control as the 'smart pixels'. You would need something like one of these:

https://www.adafruit.com/product/1429
https://www.adafruit.com/product/1455

User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Re: Developing a closed-loop feedback system via DotStar LED

Post by sgbaird »

Thanks for the note about the drivers! After more thought, I might just stick with Blinkt! for the first iteration for ease of use even if it might be a bit less interesting from a scientific complexity perspective. If eventually, I go with a custom LED array later, the drivers you mentioned seem like a great option.

I've also put together a BOM for a demo that uses RPi Zero: http://www.adafruit.com/wishlists/551817.

Thanks to both of you for the feedback! Planning to post back with the progress, and also made a hackaday.io project for it (https://hackaday.io/project/186289-self ... ptics-demo).

User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Re: Developing a closed-loop feedback system via DotStar LED

Post by sgbaird »

I've made some progress on this, and one of the outstanding challenges for me is mounting. I need to mount the sensor perpendicular to and some short distance away from the LEDs (e.g. 2-4 inches). Right now I have strips of aluminum foil wrapped around the Stemma-QT cable as a makeshift "gorillapod" that mostly stays in place when flexed into a different position. While it's working for prototyping, not so great for a final design. Any suggestions?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Developing a closed-loop feedback system via DotStar LED

Post by adafruit_support_bill »

Do you need things to be fixed in place, or adjustable?

For small-scale mounting brackets, 3D printing is an option. For larger stuff I'll usually CNC from aluminum or hardwood ply.

For quick and flexible yet precise setups, I have a collection of "Arca" standard QR rails mounting plates & brackets.
https://sunwayfoto-store.com/collection ... and-clamps

User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Re: Developing a closed-loop feedback system via DotStar LEDs

Post by sgbaird »

Thanks for these suggestions! Fixed in place is probably better. In the short term I might just go with some thick sculpting wire wrapped around or attached to the Stemma-QT cable. Some rods that go through the RPi mounting holes and have a plate (e.g. 3D printed) at the end might make more sense in the long-term. Thanks also for the link to your collection!

Maybe I'll stop by a local hardware store.

User avatar
sgbaird
 
Posts: 8
Joined: Thu Jun 30, 2022 4:51 pm

Re: Developing a closed-loop feedback system via DotStar LEDs

Post by sgbaird »


Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”