I wanted to connect several some of WS2812 LEDs to my ESP32. I use the nanoFramework as the platform. It turned out that a ready-made solution does not exist, so I had to roll up my sleeve and write it myself.
I studied the solutions of other authors, such as
They are use the RMT hardware module of ESP32 as a transmitter of commands for the LED string. So, I need to access to RMT module from C#!
Fortunately, the ESP-IDF provides API for access to this module, it remains only to write a wrapper library for access to this API code from C#.
SolutionAccording the manual Interop in.NET nanoFramework, I wrote a wrapper that allows a user to control the transmitter of RMT of ESP32.
Using this wrapper, it is possible to write a WS2812 LED control library, however it can be useful on its own, therefore it is separated from the LED control library.
Exampleusing nanoFramework.Hardware.Esp32.RMT.Tx;
...
// Register new RTM transmitter on GPIO15
// It's possible to use any available GPIO
var rmt_transmitter = Transmitter.Register(GPIO: 15);
// transmitter configuration
rmt_transmitter.CarierEnabled = false;
rmt_transmitter.isSource80MHz = true;
rmt_transmitter.ClockDivider = 4; // base period 80 MHz / 4 => 20 MHz -> 0.05 us
rmt_transmitter.IsTransmitIdleEnabled = true;
rmt_transmitter.TransmitIdleLevel = false;
// create new pulse command for to transmit
// IDLE 0.5us 1us 1.5 us 2 us 2.5 us IDLE..
// |----| |----------| |------------------|
// ---| |--------| |--------------| |------
var commandlist = new PulseCommandList();
commandlist
.AddLevel(true, 10)
.AddLevel(false, 20)
.AddLevel(true, 30)
.AddLevel(false, 40)
.AddLevel(true, 50);
rmt_transmitter.Send(commandlist);
// destroy transmitter instance and free associated RMT channel
rmt_transmitter.Dispose();
Let' see output on GPIO15:
Comments
Please log in or sign up to comment.