C
C#7d ago
ELBotLike

DMX over UART bus on Raspberry Pi

Hey everyone, I'm currently trying to get an app running on my Raspberry Pi 5 that sends out DMX. DMX is a standard for communicating with lights: https://en.wikipedia.org/wiki/DMX512 I'm using this head for it: https://bitwizard.nl/shop/DMX-interface-for-Raspberry-pi I'm using this library for it: https://github.com/BrunoDPO/DMXSimples I have it halfway working. Individuals packets are fine and valid, but it only sends packets at around 3.5Hz instead of the desired 40Hz, which I measured with an oscilloscope. It just leaves big gaps between the packets. The interesting part of the library I'm using is the SendBytes() function https://github.com/BrunoDPO/DMXSimples/blob/16d4f402a71713cdb808601d3563ea66eb7aaf27/DMXSimples/DMXCommunicator.cs#L154
DMX512
DMX512 is a standard for digital communication networks that are commonly used to control lighting and effects. It was originally intended as a standardized method for controlling stage lighting dimmers, which, prior to DMX512, had employed various incompatible proprietary protocols. It quickly became the primary method for linking controllers (...
DMX interface for Raspberry pi
Addon board for the raspberry pi that allows you to interface with DMX networks. Designed and developed in cooperation with Arjan van Vught. Works with Raspberry Pi, Raspberry Pi 2, Raspberry Pi 3 & Raspberry Pi Zero. This normally allows you to
GitHub
GitHub - BrunoDPO/DMXSimples: C# implementation of the DMX-512 prot...
C# implementation of the DMX-512 protocol (with a simple GUI) - BrunoDPO/DMXSimples
GitHub
DMXSimples/DMXSimples/DMXCommunicator.cs at 16d4f402a71713cdb808601...
C# implementation of the DMX-512 protocol (with a simple GUI) - BrunoDPO/DMXSimples
15 Replies
ELBotLike
ELBotLikeOP7d ago
I've tried this optimisation with no luck
private void SendBytes()
{

while (isActive)
{
packetTimer?.Restart();

serialPort.BreakState = true;
Thread.SpinWait(500);
serialPort.BreakState = false;

// Send all the byte parameters
serialPort.BaseStream.WriteAsync(buffer, 0, buffer.Length);

while (packetTimer?.ElapsedMilliseconds < 24)
Thread.SpinWait(10);

packetTimer?.Reset();
}
}
private void SendBytes()
{

while (isActive)
{
packetTimer?.Restart();

serialPort.BreakState = true;
Thread.SpinWait(500);
serialPort.BreakState = false;

// Send all the byte parameters
serialPort.BaseStream.WriteAsync(buffer, 0, buffer.Length);

while (packetTimer?.ElapsedMilliseconds < 24)
Thread.SpinWait(10);

packetTimer?.Reset();
}
}
I hoped that Thread.Sleep() would be the problem. ChatGPT suggested to use .WriteAsync as well, but I gumbled up a lot of garbage and I'm not versed enough to know if this is actually a better idea. I've also tried setting senderThread.Priority = ThreadPriority.Highest; I've also tried starting my process with nice -n 100 ... to give it a higher priority, no luck From my understanding these changes should cause the Thread to never really halt and to always block one CPU core, as I'm using .SpinWait() instead of .Wait(), but if I look at htop while my program is running, all cores are mostly chilling, which I find odd, so there might be a little twist or caveat that I don't know off. Hopefully someone can help me out
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
Yes, that's how I understood it and that's why I thought I would see one core being 100% all the time, which I dont Which would be fine as the Pi5 has 4 cores
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
Okay, the original had a .Wait(1) which is an accuracy never to be reached
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
And .SpinWait() isn't implemented the same on all platforms, so I can't depend on these either
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
Correct
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
The specifications of DMX require the breakState to be high for at least 100us and a packet to arrive every ~24ms
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
Thanks for the hint, will look into it
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
ELBotLike
ELBotLikeOP7d ago
Thanks for the help, much appreciated!

Did you find this page helpful?