Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: New TeensyDMX library for Teensy 3

  1. #1
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54

    New TeensyDMX library for Teensy 3

    I created a new DMX library for Teensy 3: https://github.com/ssilverman/TeensyDMX

    I wrote it partly as an exercise to learn how to do this kind of thing on the Teensy. Comments are welcome.

    Some features:
    1. Teensy's default serial buffer isn't used; the data goes directly to/from the DMX buffers from/to the ISR's.
    2. Simple API: After setup, there's only one read call (`readPacket`) and two forms of one write call (`set` for single and multiple channels).
    3. The library properly handles DMX packets containing less than 513 slots.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,500
    Great. I've added a link to this thread from the DmxSimple page. Hopefully that will help people interested in DMX find this one too.

    Can you tell me which Teensy boards this library has been used with so far?

  3. #3
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    I've tested this with a Teensy 3.2. Thanks for posting it!
    (Side note: I think the link to DmxSimple needs to be corrected; it currently points to this thread.)
    (The link: https://www.pjrc.com/teensy/td_libs_DmxSimple.html)
    Last edited by shawn; 03-28-2017 at 08:40 PM. Reason: Adding a link to DmxSimple

  4. #4
    Hey Shawn,

    Just wanted to say thank you. I'm testing a new board, my first that will be transmitting and receiving at the same time (different ports, don't worry). I tried switching to Chris's (et al)'s library but couldn't get it to work. Ward's version worked fine. Switched to yours and I'm receiving again. Next up, trying to add simultaneous transmit. Shouldn't be too hard.

    Only thing I noticed is that while testing I often plug and unplug the DMX cable to test my receive indicator. Depending on where I am in the packet when I unplug, sometimes my next read shows all zeros. It's not a problem for me, but wanted to mention it.

    I'm curious about RDM. I was going to experiment with it had I gotten Chris's library working. I still might try eventually. If you end up doing any work on that front I'd love to have a look and mess with it.

    Thanks again!

  5. #5
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    Hey, jkoffman. Really glad you're finding it useful, and thank you for the feedback. RDM is planned but when I have a chance to get to it.

    Can you tell me more about what happens when you unplug the DMX and you get all zeros? Curious, are you checking the length returned by readPacket()?

  6. #6
    Hi Shawn,

    Keep me posted, I'd be happy to help test RDM if that's useful.

    Here's a snippet of code I'm running in my main loop:

    Code:
      int read = dmxRx.readPacket(DMXRX_Buff, 1, 512);
      if (read > 0) 
      {
        LED_DMXRX_State = 4;
        digitalWrite(LED_DMXRX, HIGH);
        Serial.print(DMXRX_Buff[0]);
        Serial.print(", ");
        Serial.print(DMXRX_Buff[1]);
        Serial.print(", ");
        Serial.print(DMXRX_Buff[2]);
        Serial.print(",,, ");    
        Serial.println(DMXRX_Buff[511]);
      }
    Basically I'm storing the whole packet, then printing the first three, then the last value. This was so I could double check I was receiving the correct values where I thought they should be. No issues there.

    Attached (hopefully) is a screenshot of my serial monitor. The two anomalous areas you see are where I unplugged the XLR, then replugged, then unplugged again.

    Like I said, I think it's based on when in the packet I happened to unplug. It isn't a huge deal for my purposes at the moment. In the future I'll probably put in a timeout that zeros the buffer if it detects a drop in DMX.

    Let me know if the image didn't work, I will try to attach again.

    Josh
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2017-04-05 at 5.56.41 PM.png 
Views:	73 
Size:	37.1 KB 
ID:	10221  

  7. #7
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    jkoffman: Curious what the 'read' value is when receiving a packet. It will return the number of bytes actually read, up to and including the given length. Maybe the received packet, in the case of a disconnected cable in the middle of one, is actually much smaller?

  8. #8
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    @jkoffman: I believe I have a fix for the all-zeros issue. Let me know if you have some time to test a new branch.

  9. #9
    Member dimitre's Avatar
    Join Date
    Aug 2016
    Location
    São Paulo
    Posts
    58
    A quick question: with this library I can handle more "universes" like having 4 DMX Outputs in one Teensy board?
    Thank you @shawn

  10. #10
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,988
    You might have as many outputs as the Teensy has h/w UARTs. Thus, on a Teensy 3.6, you can have 6 DMX outputs.

  11. #11
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    I just released v2.3.0 that contains better handling of packet boundaries and timeouts. I *think* this may solve @jkoffman's "unplugging problem".

  12. #12
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    @dimitre, were you able to get multiple DMX outputs working?

  13. #13
    Junior Member
    Join Date
    Oct 2017
    Location
    Derbyshire UK
    Posts
    3
    Gents I wonder if you would help. I have failed to get DmxSimple to work on my Teensy 3.2 even using the basic built in examples and looking at the code it seems to be the exact opposite of Simple with hard coded timings etc. Shawn's library seems to me to be a much better option using the hardware properly but I have failed to find the way to use libraries that are not already compiled and provided via the IDE. Is there a How To or similar somewhere to help people like me get going. Thanks

  14. #14
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,988
    What you are asking for, is a common standard procedure in the Arduino IDE...

    First, you go on the GitHub page of the library which you want to install. There is a green button "Clone or download". When you click on it, a sub-menu opens and you click on "Download ZIP".

    In a next step, you need to install that downloaded library in the Arduino IDE: In the "Sketch" menu, select "Include a library" => "Add a .zip File" (or similar, my menus are in French language and I translate freely...). Navigate to the just downloaded zip file (most probably in your Downloads folder), and click on the select button. Now, go again to the "Sketch" menu, select "Include a library" and browse the sub menu down to "Contributed Libraries" where you will find and click the freshly installed TeensyDMX library.

  15. #15
    Junior Member
    Join Date
    Oct 2017
    Location
    Derbyshire UK
    Posts
    3
    Thank you that worked perfectly. I tried following the Arduino - LibraryTurorial under hacking and that failed for reasons that I do not understand - maybe it's out of date.

    I will let you know how I fair in a few days time.

  16. #16
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    Or, a better option sometimes, if you didn’t want the “in progress code”, go to the “Releases” section and download the latest zip version from there.

  17. #17
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    @FreekyFrank I added the TeensyDMX library to the main Arduino library list, so it should just be findable using the "Library Manager" in the Arduino IDE.

  18. #18
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    54
    RDM works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •