0

I'm looking to make a necklace of "charms", each having a different shape and containing a WS2812B (an individually-addressable RGB LED using a PWM-based single line protocol in series).

One of the aspects of this is that I'd like to be able to rearrange the "charms" (which are wired in series), and be able to read the new positions of the charms by sending a signal out along a single line (like the one for controlling the LEDs).

Is there any kind of similarly-cheap component that can pulse out a signal to uniquely identify itself in series like this? In my head, this looked like a fixed-memory "cell" that would output any bits that came before it, then add a few dozen bits of its own as a unique identifier.

Marcus Müller
  • 94,373
  • 5
  • 139
  • 252

2 Answers2

0

I doubt you'll find an off-the-shelf component that does this, but it could easily be done with any of the many SOT23-6 microcontrollers that are out there.

Dave Tweed
  • 172,781
  • 17
  • 234
  • 402
0

I'm tossing and turning your idea in my head; it's a good idea. A lot of this sounds pretty much how JTAG works, and that is really some application-proven idea.

So, I think you need to think of it as shift registers. Especially, as a serial-in, serial-out shift register with a "reset" input that allows to set the register content to an ID.

   clock --->  - - - - - - - -->            
bits in! ---> | | | | | | | ---> bits out
reset values  |I|D|1|2|3|4|

At startup, all the the registers are loaded with the reset values

   clock --->  - - - - - - - ---------------->            
bits in! ---> |I|D|1|2|3|4| ---> bits out ---> next charm
reset values  |I|D|1|2|3|4|

and the first (length shift register) clock cycles simply shift out these IDs. No need for a special "readout" command – you'll reset the full charm bus anyway after the user reconfigures it :)

That way, your bracelet controller just needs to clock the bus as often as it takes until no IDs are coming anymore. No special logic needed!

Note that such shift registers cost cents if they are 8 bits long. If you need more bits for your IDs, you could put multiple registers in one charm, but that'll become costly at some point. Also, space-consuming.

So, I'd really just add that the above is exactly how SPI works: shift registers that can be read and set. Especially, in a microcontroller, you can have an SPI slave that only has a clock in, data in, and data out pin. If you do nothing on the CPU, it works just like the above shift registers. You can, however, also read out the value of the shift register once you received e.g. 32 bit, and then act upon it – by controlling an external LED controller or LEDs directly, or by modifying the SPI shift register content, so that something else will be shifted out when more clock cycles come.

I'd really say: pick the cheapest microcontroller that has SPI (and doesn't generally suck). A lot of people swear by the Attiny family, and they are dirt cheap. Currently, the SiLabs EFM8 series seems to be even cheaper, and they contain an 8051 core, so you can use a lot of compilers like the SDCC for free. With that, you could have much more flexibility (e.g. instead of having to write each value for each LED individually if you want to e.g. let them "pulse" slowly by the central bracelet controller, you can have commands like "pulse slowly", and every charm's microcontroller does what's right for itself) and features (they have ADCs – charms could detect environmental brightness or temperature, or have accelerometers or…).

Marcus Müller
  • 94,373
  • 5
  • 139
  • 252