DmxSimple, please help test new version

PaulStoffregen

Well-known member
I've updated DmxSimple to (hopefully) work on Teensy 2.0 and Teensy 3.0. Previously it only worked on Teensy++ 2.0.

Here's the new code.

http://www.pjrc.com/teensy/arduino_libraries/DmxSimple.new.zip

I have carefully verified the waveforms on my oscilloscope, but I do not own any DMX lighting controllers. Please, if you have any DMX gear, I could really use some feedback if this truly works?

On Teensy 3.0, this depends on IntervalTimer. Use 1.14-rc1 for testing.
 
Last edited:
Paul,
I just tested the above new DmxSimple library with our new DMX/RDM Breakoutboard/Shield and the Teensy2. It works!! I will post a video to this thread in the morning showing it in action with a test RGB wash light. Here are some questions and then some observations about my journey....


Questions:
Q1) I was checking to see what pin to solder the wire to for the RS-485 transceiver TX pin... I am definitely used to picking the UART TX and RX pins, for instance TXD1=PD3=ArduinoPin8.... but in this case I notice that the choice of TX pin is software selectable. Is there any advantage (better performance) to using the true TX UART pin instead of some random software assigned pin? Note, I am soldering the following...
TXD1=PD3=ArduinoPin8 for TX
RXD1=PD2=ArduinoPin7 for RX (I know this isnt used in the DmxSimple, but I am getting ready for RDM, which is the bidirectional extension of DMX.)
EnableTX=PC6=ArduinoPin9 (this is for controlling the RS-485 transceiver half duplex direction....High is TX, low is RX...for DmxSimple we keep it high).

Q2) Stupid software question... if the Arduino Sketch calls this out "#include <DmxSimple.h>", then how and where, when you build it, does it know to use the actual "DmxSimple.cpp" file? There is no reference to the .cpp file anywhere unless it is handled behind the scenes with the "Add Library...". I am just confused as to how it knows which library to use when you have an old and a new library installed. Sorry for the newbie software question.


Observations:
1) I just updated to Arduino v1.0.5. Installing Teensyduino v1.15 on OSX, the installer offers to install the DMX simple library for me. The note says "Control DMX Lighting. Only works on Teensy++. Written by Peter Knight." I was thinking the newest DMXsimple library should be there, but maybe not yet. As a result I will watch them closely to confirm which version I am using. I will install "all" libraries for now and then sort it out after....DONE.
2) No new libraries appeared in /Users/VoltVision/Documents/Arduino/libraries, so they must have been put somewhere else (not sure where yet). They dont show up in a search.
3) I just downloaded the above DmxSimple.new.zip library. It unzips as a folder called "DmxSimple". I want it to be distinctly different from the old versions, so I am renaming all of my 3 old DmxSimple libraries to:
/Users/VoltVision/Documents/Arduino/libraries/DmxSimple1 (old one from a few years ago)
/Users/VoltVision/Documents/Arduino/libraries/DmxSimple2 (old one from a while ago).
/Users/VoltVision/Documents/Arduino/libraries/DmxSimple3 (the new one from today).
4) I then opened this example...
/Users/VoltVision/Documents/Arduino/libraries/DmxSimple3/examples/FadeUp
The software uses this line #include <DmxSimple.h>, so I get nervous whether it will use the new library or the old library, so I do Sketch->Import Library->Add Library...
Then I choose the this folder...
/Users/VoltVision/Documents/Arduino/libraries/DmxSimple3

When I build, the Good News is that I see several lines similar to this...
-I/Users/VoltVision/Documents/Arduino/libraries/DmxSimple3/utility /Users/VoltVision/Documents/Arduino/libraries/DmxSimple3/DmxSimple.cpp -o /var/folders/AK/AKPG9Ls0EOiFCs-CiIDC5E+++TI/-Tmp-/build6312543886093896398.tmp/DmxSimple3/DmxSimple.cpp.o

...this means it is using the new Library!!! (I think)...

Let me know if I did anything wrong. Next I should probably use a different ramp/color generation program to test how smooth the fades are, especially at the low levels. Also, I can test Teensy3 at some point soon.

--
Respectfully,
Steve French
800.664.7256.office

President, Volt Vision
www.voltvision.com
 
Last edited:
I will post a video to this thread in the morning showing it in action with a test RGB wash light.

Great. I always like seeing videos of real uses. :)

Q1) I was checking to see what pin to solder the wire to for the RS-485 transceiver TX pin...

For DmxSimple, the pin does not matter.


RXD1=PD2=ArduinoPin7 for RX (I know this isnt used in the DmxSimple, but I am getting ready for RDM, which is the bidirectional extension of DMX.)

I am not familiar with RDM. Is there any good (eg, quick) background info I should read?

Q2) Stupid software question... if the Arduino Sketch calls this out "#include <DmxSimple.h>", then how and where, when you build it, does it know to use the actual "DmxSimple.cpp" file?

The Arduino software searches for libraries in a few places.

The Teensyduino installer adds libraries within Arduino's own "libraries" folder. On a Windows and Linux, Arduino is just ordinary folders and files. On Mac, control-click on Arduino and use "show package contents" to see inside. The "libraries" folder is a few folders in...


the installer offers to install the DMX simple library for me. The note says "Control DMX Lighting. Only works on Teensy++. Written by Peter Knight."

Opps, that's old into. I'll update it for the 1.16 installer.

Peter's original code only worked on Teensy++ 2.0. A few months ago, I ported it to Teensy 2.0 and 3.0. A few people have confirmed it works on Teensy 2.0. I even built this little controller which worked nicely.

So far, there's been no real-world confirmation for Teensy 3.0. But I did pretty carefully look at the waveforms on my oscilloscope while porting the code.

Also, I can test Teensy3 at some point soon.

That would be nice. It's been on my to-do list for a while....

A couple people have used Teensy 3.0 for DMX, but not the DmxSimple library. You can probably find that info using this forum's search and skimming through a few older threads.

Teensy 3.0's Serial1 port has a FIFO, which makes it vastly better for fast serial data than any Arduino board. Serial2 and Serial3 on Teensy 3.0 are just normal double buffered ports, just like the serial ports on all Atmel AVR chips.
 
Also, I should mention DmxSimple uses CPU-intensive bit bashing on a pin to create the output signal.

The advantage is it works on boards like Arduino Uno that do not have any extra UARTs, and have a bad combination of bloated UART interrupt code and a slow 8 bit processor which limits the speed they could achieve with a UART anyway.

There are 2 bit disadvantages to bit basing. First, it hogs CPU time. While the CPU is busy looping to create the output waveform, nothing else can run. Of course, if you're only building a USB to DMX gateway, maybe that's not such a big deal. But if you're running any other libraries that need CPU time or low interrupt latency, DmxSimple's CPU hogging behavior can be trouble.

Second, because it ties up the CPU, DmxSimple is designed to limit how much CPU time is uses. The default it 25%. That allows your code and other libraries to do their work with the other 75% of the time. But the downside is it can only spend 25% of the time sending data. For updating all 512 channels, DMX is theoretically capable of a 44 Hz update rate. But with DmxSimple, the fastest you can update 512 channels is about 11 Hz, since 75% of the time is not transmitting anything.

A much better way to send DMX would involve using Teensy3's Serial1 port. It can easily handle 250 kbits/sec speed, or even 1 Mbit/sec speed. It also has a working Serial.flush (on most official Arduino boards this function is buggy) to wait for the data to transmit, so the RS-485 transmitter could be turned off if needed.
 
Paul,
Thanks for the responses!

I just posted a video of the above test results and put it on my blog here....
http://www.voltvision.com/teensy2-a...gether-to-test-the-updated-dmxsimple-library/

Also, to answer your questions...

Paul said: I am not familiar with RDM. Is there any good (eg, quick) background info I should read?
Frenchy says: Yes, check this out... http://en.wikipedia.org/wiki/RDM_(lighting)

Paul said: So far, there's been no real-world confirmation for Teensy 3.0. It's been on my to-do list for a while....
Frenchy says: I will do that next, then my goal is to get DMX and WS2811 pixels running @ the same time...(on the Teensy3).

Paul said: I even built this little controller which worked nicely.
Frenchy says: Nice!! My main thrust right now is to make a design which serves up pre-arranged data, sends to DMX and Pixels...and still allows interactivity (configuration of the pixel data is another topic). (prelim flower example). I think a Teensy3+rPi is my ultimate solution (for now until you release something better than the rPi/BeagleBoneBlack with native ethernet).

Paul said: Teensy 3.0's Serial1 port has a FIFO, which makes it vastly better for fast serial data than any Arduino board.
Frenchy says: At DMX speed of 250kbaud...would you consider that fast? Does the FIFO still provide advantage here over the "normal double buffered ports"?

Paul said: ...with DmxSimple, the fastest you can update 512 channels is about 11 Hz...
Frenchy says: 11Hz, thats about 91ms between updates. I bet that was a big factor in the perceived "digital stepping" when the ramp preset was going through the low brightness ranges that I commented on in the video.

Thanks for explaining to me that the Libraries are installed "inside of" the Arduino.app and I did see them using "Show Package Contents"....although the one thing that still confuses me is how does it know to use the new library instead of the old library when building? The code "#include <DmxSimple.h>" doesnt clarify if its supposed to use the old library (installed as part of Arduino.app) or a new library, which is located somewhere else.

Thanks for everything Paul you truly are awesome.
respect,
frenchy
 
Last edited:
I personally tested DmxSimple on Teensy 3.1 a couple months ago. It worked fine.

10475970_664204850335088_5705209095609599146_o.jpg
(click for full size)

Teensy 3.1's hardware serial is also plenty fast enough to send DMX as ordinary serial.

Here's a little program which sends DMX using Serial1. I tested both DmxSimple and this program on the hardware you see in the photo.... which them went on to make a sound-reactive art car for Burning Man this year! :)

Code:
uint8_t buffer[513];

void xmit() {
  digitalWriteFast(12, HIGH);
  Serial1.begin(83333, SERIAL_8N1);
  Serial1.write(0);
  Serial1.flush();
  Serial1.begin(250000, SERIAL_8N2);
  digitalWriteFast(12, LOW);
  // first byte of buffer must be zero
  // to comply with DMX protocol
  Serial1.write(buffer, sizeof(buffer));
  Serial1.flush();
}

#define RED    0xFF0000
#define GREEN  0x00FF00
#define BLUE   0x0000FF
#define YELLOW 0xFFFF00
#define PINK   0xFF1088
#define ORANGE 0xE05800
#define WHITE  0xFFFFFF

void setup() {
  Serial1.begin(250000);
  pinMode(12, OUTPUT);
}

void loop() {
  colorWipe(RED);
  colorWipe(GREEN);
  colorWipe(BLUE);
  colorWipe(YELLOW);
  colorWipe(PINK);
  colorWipe(ORANGE);
  colorWipe(WHITE);
}

void colorWipe(int color)
{
  for (int i=0; i < 48; i++) {
    buffer[0] = 0;
    buffer[i*3 + 1] = color >> 16;
    buffer[i*3 + 2] = color >> 8;
    buffer[i*3 + 3] = color >> 0;
    buffer[i*3 + 1 + 144] = color >> 16;
    buffer[i*3 + 2 + 144] = color >> 8;
    buffer[i*3 + 3 + 144] = color >> 0;
    buffer[i*3 + 1 + 288] = color >> 16;
    buffer[i*3 + 2 + 288] = color >> 8;
    buffer[i*3 + 3 + 288] = color >> 0;
    buffer[25] = 0x5A;
    xmit();
    buffer[25] = 0xA5;
    xmit();
  }
}
 
Thank you Paul,
After switching to using the serial ports directly like this i am having no problems.
thanks again,
Dave
 
DMX as ordinary serial on Teensy-LC and Teensy3.0 also?

Paul,
Below you mentioned "Teensy 3.1's hardware serial is also plenty fast enough to send DMX as ordinary serial."...does the same thing apply to Teensy-LC? ...and Teensy3.0? I assume yes since they are all 32 bit Kinetis, but thought I should confirm. Thanks! I am building up a bunch of exhibits for a show now and was hoping to use some Teensy-LCs for some simple DMX output interactive exhibits. Talk soon.
-frenchy (Steve French)
www.voltvision.com


I personally tested DmxSimple on Teensy 3.1 a couple months ago. It worked fine.

View attachment 2807
(click for full size)

Teensy 3.1's hardware serial is also plenty fast enough to send DMX as ordinary serial.

Here's a little program which sends DMX using Serial1. I tested both DmxSimple and this program on the hardware you see in the photo.... which them went on to make a sound-reactive art car for Burning Man this year! :)

Code:
uint8_t buffer[513];

void xmit() {
  digitalWriteFast(12, HIGH);
  Serial1.begin(83333, SERIAL_8N1);
  Serial1.write(0);
  Serial1.flush();
  Serial1.begin(250000, SERIAL_8N2);
  digitalWriteFast(12, LOW);
  // first byte of buffer must be zero
  // to comply with DMX protocol
  Serial1.write(buffer, sizeof(buffer));
  Serial1.flush();
}

#define RED    0xFF0000
#define GREEN  0x00FF00
#define BLUE   0x0000FF
#define YELLOW 0xFFFF00
#define PINK   0xFF1088
#define ORANGE 0xE05800
#define WHITE  0xFFFFFF

void setup() {
  Serial1.begin(250000);
  pinMode(12, OUTPUT);
}

void loop() {
  colorWipe(RED);
  colorWipe(GREEN);
  colorWipe(BLUE);
  colorWipe(YELLOW);
  colorWipe(PINK);
  colorWipe(ORANGE);
  colorWipe(WHITE);
}

void colorWipe(int color)
{
  for (int i=0; i < 48; i++) {
    buffer[0] = 0;
    buffer[i*3 + 1] = color >> 16;
    buffer[i*3 + 2] = color >> 8;
    buffer[i*3 + 3] = color >> 0;
    buffer[i*3 + 1 + 144] = color >> 16;
    buffer[i*3 + 2 + 144] = color >> 8;
    buffer[i*3 + 3 + 144] = color >> 0;
    buffer[i*3 + 1 + 288] = color >> 16;
    buffer[i*3 + 2 + 288] = color >> 8;
    buffer[i*3 + 3 + 288] = color >> 0;
    buffer[25] = 0x5A;
    xmit();
    buffer[25] = 0xA5;
    xmit();
  }
}
 
does the same thing apply to Teensy-LC? ...and Teensy3.0?

Teensy 3.0, yes, definitely.

Teensy LC, maybe, sorta. There's no FIFO, so 4 times as many interrupts will be generated and the CPU isn't nearly as fast. I believe it will still work, but sending at 250000 baud will tax Teensy LC somewhat.
 
I'm running that sketch on a Teensy-LC right now. Here's the serial output waveform. Looks good.

file.png

Of course this doesn't measure how much extra CPU time Teensy-LC has to do other work.
 
To investigate this just a little more, I added a digitalWriteFast() at the beginning and end of the Serial1 ISR. This only measures the CPU time consumed by the ISR code, but not the main program code which puts data into the buffer, nor the CPU's overhead to respond to the interrupt or return. Still, it's hopefully a reasonable measure. I'd assume this is 50% of the actual CPU overhead.

Here's Teensy-LC sending DMX:

file2.png

So CPU overhead isn't nearly as much as I'd guessed it might be!
 
This should work on LC, but keep an eye on usage of the limited RAM. Maybe decrease the array size if you don't need all 512 channels.
 
This should work on LC, but keep an eye on usage of the limited RAM. Maybe decrease the array size if you don't need all 512 channels.

Hi Paul,

I tried the example code (the colorwipe with the xmit() function) On the TeensyLC it doesn't seem to work at all and it works fine on a Teensy 3.2, any ideas what could be wrong, Serial1 is pin 1 on the LC right ?
 
Update: I got it working by using Serial2 (pin 10) but pin 1 wouldn't do anything, strange...

I don't seem to have ram problems but if I try to send all 512 channels the framerate seems to drop quite a lot... I also tested it on a Teensy 3.2 with the same results. Would there be a way to optimize speeds when sending all channels ?
 
Sending more channels does take more time.

Maybe you're seeing some additional timing problem? Or maybe it's simply the amount of data? You have to post a complete program (the "Forum Rule") for this sort of help. Without a way to reproduce the problem, I can only guess.
 
Hello Guys........
"I'm eager to test the most recent DmxSimple version! Wishing for better features and better performance. I'm appreciative of the continued progress and dedication to DMX control quality. Now let's illuminate the future!"
 
Last edited:
Back
Top