[Info] WS2812 (NeoPixels) C++ class for ESP32

User avatar
kolban
Posts: 421
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Info] WS2812 (NeoPixels) C++ class for ESP32

Postby kolban » Mon Nov 28, 2016 1:32 am

https://github.com/nkolban/esp32-snippets/tree/master/hardware/neopixels

Here is a sample C++ class for driving WS2812 (NeoPixels). It uses the RMT technology. To use, we create an instance of the WS2812() object specifying the RMT channel number, the GPIO pin for data out and the number of pixels. Now we can call one of the setPixel() methods to set a pixel's color and finally call the show() method to cause the pixels to light.

See also http://esp32.com/viewtopic.php?f=17&t=589 for another ESP32 WS2812 library.
Last edited by kolban on Fri Jan 20, 2017 10:28 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

uhrheber
Posts: 16
Joined: Sat Nov 12, 2016 12:07 pm

Re: WS2812 (NeoPixels) C++ class for ESP32

Postby uhrheber » Tue Nov 29, 2016 7:09 am

Kolban,

great!
Many thanks.
If only I had more time...

Uhrheber

jumjum123
Posts: 48
Joined: Mon Oct 17, 2016 3:11 pm

Re: WS2812 (NeoPixels) C++ class for ESP32

Postby jumjum123 » Tue Dec 06, 2016 3:52 pm

Is there a limit for no. of pixels ?
As far as I understand, for an array of 8 by 8 pixels, it would need 64 * 24 * size_of_rmt_item32_t
Does rmt support this amount of memory ?

User avatar
kolban
Posts: 421
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WS2812 (NeoPixels) C++ class for ESP32

Postby kolban » Tue Dec 06, 2016 4:09 pm

My understanding is that the for each RMT channel, there is a buffer that stores the data that will be pushed out by RMT interpretation. Each "item" contains the signal level and how many clock ticks that signal level is to be maintained for. There appear to be 8 buffers available to the RMT channels and lower channel numbers appear to be able to use the buffers for the channels above as long as those channels aren't used. However, as you have noted, that still puts an upper bound on the size of items that can be used ... specifically if one used channel 0 (of 8 in total) to output then it would appear that you only have 8 x sizeof(RMT buffer) number of items. However, RMT appears to have considered this notion and appears to have "threshold interrupts" that are called when the number of items in the buffer is about to be exhausted without having reached the end. My loose reading says that RMT invokes an interrupt that is responsible for replenishing the buffer form (ideally) RAM so that it continues to be fed. As such, the amount of items that can be sent by RMT appears to be unlimited as long as the interrupt service routine can move data into RMT buffers fast enough.

It is also my loose understanding that the RMT drivers "take care of this for us" ... so when we provide a buffer of items to RMT through the driver, the wrapping logic of the driver will honor whatever length of items we have supplied.

I could (as usual) be all washed up on my thinking ... but this is my best guess at the moment.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 1 guest