"intelligent" LEDs ws2812 driven by Axoloti


#1

Hi,
I would like to connect some ws2812 to the axoloti. I think I need to create a new object to get this done. Question is: how do I start? As far as I understand K-rate Code runs at 3000Hz and S-Rate Code runs at 48kHz. Both seems to slow to generate 800kHz for the ws2812?

Currently I'm also not entirely sure how the PWM generation of the existing PWM OSCs work. I also don't know what the PWM timers are for.


Recomended SPI Port for external Display
#2

It's a bit complex...

I have made an example for WS2811 leds, can be found in
archive/tests/io/spi_WS2811.axh
BUT
you have to modify the firmware, and change

#define STM32_UART_USE_USART2               FALSE

into

#define STM32_UART_USE_USART2               TRUE

and

#define STM32_SERIAL_USE_USART2             TRUE

into

#define STM32_SERIAL_USE_USART2             FALSE

and recompile/flash firmware.

osc/pwm is based on a bandlimited step table
http://www.cs.cmu.edu/~eli/papers/icmc01-hardsync.pdf

the gpio/out/pwm * objects were made originally to control LED dimmers, but can be used for other purposes too. They're not for audio PWM oscillators. But the implementation of these objects is currently not very flexible.


#3

Is there any withdraw in changing these defines?


#4

The UART interface in chibios is for DMA-accelerated block transfer.
The Serial in chibios is for a stream interface.

In development, the stream interface is nice, since it allows to log messages with sprintf-style calls.
Some conditional compiles are present in firmware to log deep stuff to uart (ENABLE_SERIAL_DEBUG).

For the ws281x leds, the serial interface does not work because the serial interface uses interrupts, that does not produce the tight timing required for these leds.

Both interfaces can't be enabled for the same USART peripheral.

Using SPI is also an option but I could not get a suitable bitrate configured. This may work by feeding it an external clock, perhaps generated by a timer in pwm output mode. Only try this if you're into hardware hacking and have an oscilloscope or logic analyzer near...


#5

One solution may be to use something else to drive the WS2812's, such as an ATTiny? Get the Axoloti to talk to the tiny at it's leisure, and the tiny can do the high speed stuff on its own.


#6

Thanks for this hint smile


#7

Did the ws2812 led object gain much traction or was it left for an external mcu to do the work?


#8

Made a new patch, added into axoloti-contrib: patches/jt/led_string_ws2811.axp
"Sync Libraries" in 1.0.10 and you'll get it.
I have developed a trick to make it work with stock firmware. SPI is used to generate the data-stream, with the help of a PWM channel (from timer4) to generate the right bitrate. The SPI in master mode can not generate a suitable bitrate, so it uses SPI slave mode, with the PWM channel used to generate the right data clock.

You need to connect PB8 to PA5
WS2811 data out is on PA6

Tested with this LED Rope.

I believe the generated data stream is compatible with both WS2811 and WS2812, but R/G/B may be swapped around.

I suggest to use an independent (isolated) power supply to prevent injecting switching noises into the audio.

Feedback welcome!


4x1 RGB-LED-Ring/Rotary Encoder PCB Bulk Order
#9

Thank you for looking at this :slight_smile: Unfortunately, led_string_ws2811.axp doesn't appear to be syncing, I can't see it on github either atm.


#10

If you access github directly, you need to switch to the 1.0.10 branch https://github.com/axoloti/axoloti-contrib/tree/1.0.10/patches/jt
If you use the "sync libraries", it should appear in Your Documents/axoloti/axoloti-contrib/patches/jt


#11

Thanks, I found it :smile: That's a cool trick pwm'ing the clockrate!!

How does the patch work Johannes? Is it just doing a light show, or can the colours be manipulated by incoming data streams? atm I can see it's working for a string of 10 leds (nleds = 10), can you explain what the setv function does? Lastly, is it safe to use a 5v psu for the leds with the PA6 pin connected to the leds?


#12

I did not make an object that has RGB inlets for every LED, I think that would be hard to manage for dozens of LEDs. So yes it just shows scrolling RGB colors.
I believe in practical use cases, you want to control a few parameters of a lightshow, while the lightshow algorithm itself is better suited to coding than patching. So the script needs to be adapted to different situations...
If you want to use the two available inlets of the script2 object, you can just use in1 and in2 variables in the code, to convert them to 8bit intensity, you need to right shift them by 19 places (in1>>19).

5V powersupply is fine for the LEDs, with PA6 connected to Axoloti, and GND connected to powersupply, LEDs and Axoloti.

The setv function:
The LEDs need serial data formatted like:
for a zero bit: 1000
for a one bit : 1100

(while the "formatted" bits need to be clocked at 3.2MBit/s)
Actually the WS2811 or WS2812 datasheet don't talk about this structure, it only gives timing specifications, and this fits the requirements.
So transmitting the intensity value for a single LED/channel needs to expand for example
value (decimal)15 = (binary)00001111 into 10001000100010001100110011001100
and that's what the setv() function does.


#13

A practical use case might be lighting specific leds because a specific midi message was received or a button was pressed or a condition reached.

For instance, you could have a mode switch button, which switches banks for a 6 pot midi controller, each time it switches it could change colour to signify which bank your using. or it could tell you if a channel is clipped/clipping... or you could make your own vu meter etc.

I have zero experience with the axoloti but I have played with ws2812 leds and midi on an arduino.


#14

edit.
nevermind i'm too stupid for the internet.


#15

I'm too stupid NOT to be on the internet :joy:


#16

Great work! I want to make 33 encoders for my custom synth, so I think that I need to purchase 9 of them right? Are they available for shipping?


4x1 RGB-LED-Ring/Rotary Encoder PCB Bulk Order