Coder Social home page Coder Social logo

ssilverman / teensydmx Goto Github PK

View Code? Open in Web Editor NEW
95.0 14.0 6.0 887 KB

A full-featured DMX library for Teensy 3, Teensy LC, and Teensy 4. "Programmable DMX and arbitrary USB serial device emulation."

License: BSD 3-Clause Clear License

C++ 100.00%
teensy dmx dmx512 rdm rdm-responder teensy3 teensy-lc teensy32 teensy35 teensy36

teensydmx's People

Contributors

ssilverman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

teensydmx's Issues

TeensyDMX.h:20:19: fatal error: cstdint: No such file or directory

Hello,

this library sounds awesome, i've been thinkin about doing some DMX projects on my Arduinos for Months.
Unfortunately, trying to compile a Sketch using the lib yields the following error:

libraries\TeensyDMX\src/TeensyDMX.h:20:19: fatal error: cstdint: No such file or directory

Full Sketch:

`
#include <TeensyDMX.h>

namespace dmx = ::quindesign::teensydmx;

// send / Drivers
#define DE 2
// receive
#define RE 3

dmx:Sender sender{Serial};

void setup() {
// put your setup code here, to run once:

}
void loop() {
// put your main code here, to run repeatedly:
}
`

Library Version: 3.0.0-beta installed from Arduino Library Manager
Arduino Version: 1.8.7

Use of connection();

Hi,

I try to detect whether my DMXreceiver receives a dmx signal. I wanted to use the connected() function. However, I don't seem to get it working. I think the docs are not written for an Intermediate level programmer so I'm a bit stuck.

I would like to keep looping a function when no DMX signal is detected.
The example code in the docs gives an error. I try to put something together myself but also had no luck so far.
What would be the correct implementation of connection detection for my use case?

Docs example:

dmxRx.onConnectChange([](Receiver *r) {
  digitalWriteFast(LED_BUILTIN, r.connected() ? HIGH : LOW);
});

My try:

  while (dmxRx.connected() == false)
  {
  Serial.println("No DMX signal");
  markColor(100, 255, 0, 0); //NUM_LEDS 
  }

Full code

#include <TeensyDMX.h>
namespace teensydmx = ::qindesign::teensydmx;
teensydmx::Receiver dmxRx{Serial1};
uint8_t packetBuf[5] {0};
uint8_t dsrgb[5] {0}; //Dimmer, RGB, strobe


// BasicTest example to demonstrate how to use FastLED with OctoWS2811
#include <OctoWS2811.h>
#define USE_OCTOWS2811
#include <FastLED.h>
#define NUM_LEDS  190 //3040

CRGB leds[NUM_LEDS];

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // Wait for initialization to complete or a time limit
  }

  while (dmxRx.connected() == false)
  {
  Serial.println("No DMX signal");
  markColor(100, 255, 0, 0); //all leds red
  }


  LEDS.addLeds<OCTOWS2811, RGB>(leds, NUM_LEDS / 8);
  Serial.print("Let there be light!");
  markColor(100, 255, 0, 0);
  delay(2000);
  Serial.println("Done");
  Serial.println("Start DMX read");
  dmxRx.begin();
}

void loop() {
  dmxRx.readPacket(dsrgb, 1, 5); // first 5 channels

  //Dimmer + color
  if (dsrgb[4] < 10) {
    markColor(dsrgb[0], dsrgb[1], dsrgb[2], dsrgb[3]);
  }

  //STROBE + color
  if (dsrgb[4] > 10) {
    Strobe(map(dsrgb[4], 10, 255, 10, 150)); //argument: strobe time in MS
  }

}



void Strobe(uint8_t strobeIntervalMs) {
  if ((millis() / strobeIntervalMs) % 2) {
    markColor(0, 0, 0, 0);
  } else {
    markColor(dsrgb[0], dsrgb[1], dsrgb[2], dsrgb[3]);
  }
}

void markColor(uint8_t dmxDimmer, uint8_t dmxRed, uint8_t dmxGreen, uint8_t dmxBlue) {
  uint8_t dimmerRed = map(dmxRed, 0, 255, 0, dmxDimmer);
  uint8_t dimmerGreen = map(dmxGreen, 0, 255, 0, dmxDimmer);
  uint8_t dimmerBlue = map(dmxBlue, 0, 255, 0, dmxDimmer);

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i].setRGB(dimmerRed, dimmerGreen, dimmerBlue);
  }

  FastLED.show();
}

Serial2-6 for recieve on Teensy 3.6

Seems like Serial3 and Serial4 (so far as I tested) are not working for recieve on my Teensy 3.6. If I connected a DMX Singal to Serial1 (Pin0) or Serial2 (pin9) everything works fine. Connecting it to Serial3 or Serial4, I cant recieve any values. I'm using the Flasher.ino provided in your examples.

Would be nice if you can fix that :)
Or is this just a problem on my side?

Any plans for a DMX USB Pro Widget implementation?

Hi Shawn,

Thanks for your great work on this library, it's awesome to have a functional interface for working with DMX on the Teensies.

I saw you briefly mentioned that the library should be in a state where the widget API could be implemented on top and was wondering if you have a reference implementation or plans to integrate such functionality into TeensyDMX. Being able to do so would make it perfect for use in headless setups with DMX recorders etc. and without having to user ArtNet and additional expensive Ethernet breakout.

I understand the DMX over USB widget API is essentially a serial signaling spec but I'm not entirely sure where to begin in implementing it against software like MadMapper / TouchDesigner or ay other PC client.

Any help / pointers / reference code would be appreciated!

Teensy Locks Up after several Connects / Disconnects of DMX from certain sources.

It seems to be possible to to cause the Teensy (Teensy 3.2 (96Mhz (Overclocked)) to lock up when receiving DMX from certain lighting desks and physically connecting / disconnecting the dmx cable.

The timings of the Offending DMX source are as follows:
Refresh: 20Hz
Break Length: 238 to 280uS (**)
MAB: 23uS
Channels Rx: 512

When the lock up occurs, only a power cycle fixes it .

USBWidgetPro Example Correction

Hi,

First of all, thank you for this great library!

I've been using this for a couple of projects of mine, and it works very well. One of the projects is to upgrade the Velleman VM116/K8062 USB Controller DMX Interface by removing the original PIC and replacing it with a TeensyLC running TeensyDMX in send mode. I essentially used the USBWidgetPro example pretty much as is, and it works well with FreeStyler and the fixtures I tested it on.

However, when I tried to use it controlling another one of my projects, I was getting quite a lot of glitches coming through. To cut a long story short, it turned out that the problem was that the TeensyLC was pausing briefly to process data received from the USB port.

The issue is this block of code in handleMessage (line 508):

if (len != dmxTx.packetSize()) {
   __disable_irq();
   dmxTx.setPacketSize(len);
   dmxTx.set(0, msg.data, len);
   __enable_irq();
   } else {
     dmxTx.set(0, msg.data, len);
}

The data can be set whilst a transmission is taking place, causing a brief delay in the DMX data stream and glitching the receiver. I propose changing this block to:

if (len != dmxTx.packetSize()) {
  dmxTx.pause();
  while(dmxTx.isTransmitting()) { yield(); }
  dmxTx.setPacketSize(len);
  dmxTx.set(0, msg.data, len);
  dmxTx.resume();
} else {
  dmxTx.pause();
  while(dmxTx.isTransmitting()) { yield(); }
  dmxTx.set(0, msg.data, len);
  dmxTx.resume();
}

After this change, the glitches disappeared and it all works perfectly!

I hope it helps!

Finish Teensy 4 support

This is written but I still have to test on some hardware. I have some Teensy 4s but haven’t tested yet.

Example pinout?

Novice here, is their any examples for using this library with a 3pin XLR DMX light?

Also is an RS485 needed or could a Teensy LC be used standalone with the light

Teensy 3.6 Serial6 doesn’t work in conjunction with other ports

From an email:

I am trying to use Serial6 for a teensyDMX Sender running on a Teensy 3.6 and can’t seem to get it to work.
The other 5 serial outputs work well and I can use those 5 and create a Sender with Serial6.
It’s when I call begin on the Serial6 Sender that things break down. I’m not sure what is happening but none of the other serial outputs work after that call.
Searching on the Teensy forum I found a message from 2019 where you mention an LPUART issue, could I be running into that?
If you haven’t had a chance to test Serial6 on a Teensy 3.6 in the mean time, and are still interested in it, I can run tests and check the outputs on a scope.

More details:

  1. Serial6 works by itself.
  2. Just Serial6 and Serial1 doesn’t work.

USBProWidget - usb type

If I am to understand correctly this example makes the Teensy function like one of the well-known brands DMX Pro interface for use with apps like QLC? How stable is is considered?

I tried to flash, but it's not detected correctly in QLC+ (my other real devices are). Permissions error or am I selecting the wrong USB Type opinion in the IDE? The file doesn't state the correct mode to use

Freeze when using Audio Shield and DMX transmit on Serial3

Original discussion is here:
https://forum.pjrc.com/threads/71964-Using-Serial3-when-using-audio-library

In summary, it appeared that the Audio Shield was causing some freeze when transmitting DMX on Serial 3. Upon further digging, it was discovered that it was some interaction with TeensyDMX, plus the Audio Shield capacitor on pin 15 (RX3).

Test code:

#include <TeensyDMX.h>
// #include <Audio.h>

namespace teensydmx = ::qindesign::teensydmx;
teensydmx::Sender dmxTx{Serial3};

// AudioOutputI2S           audioOutput;

void setup() {
  Serial.begin(115200);
  delay(1500);
  if (CrashReport) {
    Serial.println(CrashReport);
    CrashReport.clear();
  } else {
    Serial.println("No CrashReport");
  }
  Serial.println("setup begin");

  dmxTx.begin();

  for (int i=0; i<25; i++) {
    Serial.println(i);
    delayMicroseconds(250);
  }
  Serial.println("setup end");
}

void loop() {
  static elapsedMillis timer;
  static uint32_t counter = 0;
  if (timer >= 1000) {
    Serial.println(counter++);
    timer = 0;
  }
}

The cause is a capacitor connecting the RX line to voltage, eventually triggering RX and causing continuous TX. i.e. When RX reaches a threshold. The best scope trace that shows this is in post # 15:
https://forum.pjrc.com/threads/71964-Using-Serial3-when-using-audio-library?p=319218&viewfull=1#post319218
file

The blue trace shows that the TX interrupt seems to be continuously triggering after RX reaches some threshold. Code to generate this (on Serial1):

void lpuart6_tx_isr() {
digitalWriteFast(32, HIGH); // Blue trace on scope
  Sender *s = txInstances[0];
  if (s != nullptr) {
    s->sendHandler_->irqHandler();
  }
digitalWriteFast(32, LOW);
}

(Credit to @PaulStoffregen for the trace.)

Teensy 4.1 - No Serial8

Using the BasicSend.ino example works on the 4.1 with Serial1-Serial7, but not on Serial8. It will not fail to compile or during runtime, but there is no output. I tried to dig through and did notice the switch for Serial8 references the wrong IC when checking defines (IMXRT1052 instead of IMXRT1062 on the 4.0 and 4.1, and I believe the 4.1 is the only model with Serial8 available)
I tried changing that but resulted in a slew of errors. If you do not have a 4.1 available to test, I can try any updates you make to confirm. I'm just not sure where to start to try to find the issue myself.

On another note, I'm also using NativeEthernet on this board and teensyDMX seems to kill the linkStatus functionality due to link_callback not being received, yet works fine without this lib initialized.. don't expect a definitive answer but if you have ANY idea what in here may conflict with that so I could dig a bit I would love to hear.. been fighting that one for a while..

Receiver is unable to parse RB-DMX1

I'm seeing framing errors and other issues when trying to receive data from a Pioneer RB-DMX1.

My setup is as follows:

  • Teensy 4.1
  • TeensyDMX was pulled from git, from master branch not more than a few days ago
  • Sketch is DMX receiver-only, via Serial1. Based on the example sketch.
  • I'm using pin 3 as an RX watch pin, via dmxRx.setRXWatchPin(RX_WATCH_PIN)
  • I'm using the serial console to debug packet stats and error information to the serial monitor.

The RB-DMX1 works fine when I hook it up directly to my lights. I've got roughly 19 DMX devices and about 157 used channels.

The Teensy 4.1 and your TeensyDMX library work fine if I receive DMX data from an Enttec Open DMX, with the same amount of fixtures.

When the RB-DMX1 is sending data to TeensyDMX, I will get framing errors and long packet counts. Depending on what the DMX box is outputting, it will sometimes not give any errors at all, but in other situations, it will give me nothing but errors, with no data at all output. This box is proprietary in that it only works with Rekordbox DJ software. what's weird is that it seems to wig out the most when it's sending certain colors, like red. Other colors/modes, it won't error out at all. Which is really weird.

I started adding debug code in to figure out where the framing errors are coming from. There are about 11 places in the code where receiveBadBreak() will increment framingErrorCount.
I see framing error counts increase in the following source locations:

The DMX output looks decent on an oscilloscope but my scope kinda sucks. I think I might modify the library to pulse a spare IO pin when the MAB transitions. that would be helpful. But anyway, here are the measurements I can come up with from the scope:

  • Space-for-break time: 180.0 uS
  • MAB time: ~20 uS
  • Data bit length: 4 uS
  • Break-to-break time: ~28.8 ms

The times look really consistent, there's not really any jitter to speak of.

I've spent a few days on this and I'm not sure what to do from here. I'm pretty certain that the DMX device is within spec, or close to it, especially since it works with my lights. I think this might a legitimate bug with the library. Could you help me with this?

Returning all Zeroes, Packet time negative (-44)

Hi

I'm using your library, but I'm having problems reading the data.

Using teensydmx::Receiver::readPacket i'm trying to read 2 channels, sporadically both are setted to 0 even if the function has return value 2 (channel readed) , when this happen Receiver::PacketStats::packetTime (obtained passing it as forth function parameter) has value -44

This behavior is the same with both and without teensydmx::Receiver::setRXWatchPin configured

I'm also running 2 analogWrite, both using FTM1 as timer

I'm running on a teensy3.2, TeensyDMX4.0.0, compiled on Platformio (Teensyduino 1.53)

Any ideas? Thanks

using teensy 4.1 for 8 DMX universes

Does any one have any experience with using the teensy 4.0 or 4.1 as a multi universe DMX interface?
I wonder if it could be used as a replacement for the ENTTEC Storm 8

I know the Storm 8 is an Art-Net device. So either try to use https://github.com/natcl/Artnet or expand the USBProWidget example to handle multiple universes.

I would also need to explore how to expand the ofxDMX openframeworks c++ addon i am currently using so it sends out more than 2 universes.

I am happy to hear if others have done something like this before.

Teensy4.1 multi DMX Sender.

How many serial ports can be used at the same time?
I want to use all 8 serial ports on Teensy4.1 to send out DMX signals.
By modifying the sample code and adding the number of serial ports one by one, there is no problem at around 3, but beyond that, the processor dies.

Test Code..

#include <TeensyDMX.h>

namespace teensydmx = ::qindesign::teensydmx;

constexpr uint8_t kTXPin = 17;

teensydmx::Sender dmxTx{Serial1};
teensydmx::Sender dmxTx2{Serial2};
teensydmx::Sender dmxTx3{Serial3};
teensydmx::Sender dmxTx4{Serial4};
teensydmx::Sender dmxTx5{Serial5};
teensydmx::Sender dmxTx6{Serial6};
teensydmx::Sender dmxTx7{Serial7};
teensydmx::Sender dmxTx8{Serial8};

// Data for 3 channels.
uint8_t data[3]{0x44, 0x88, 0xcc};

void setup() {
Serial.begin(128000);
while (!Serial && millis() < 4000) {
}
// Turn on the LED, for indicating activity
pinMode(LED_BUILTIN, OUTPUT);
digitalWriteFast(LED_BUILTIN, HIGH);

// Set the pin that enables the transmitter; may not be needed
pinMode(kTXPin, OUTPUT);
digitalWriteFast(kTXPin, HIGH);

dmxTx.set(1, 128);
'
dmxTx.set(10, data, 3);

dmxTx.begin();
dmxTx2.begin();
dmxTx3.begin();
// dmxTx4.begin();
// dmxTx5.begin();
// dmxTx6.begin();
// dmxTx7.begin();
// dmxTx8.begin();
}

void loop() {
Serial.print( dmxTx.packetSize());
Serial.print(" ");
Serial.print( dmxTx2.packetSize());
Serial.print(" ");
Serial.print( dmxTx3.packetSize());
Serial.print(" ");
Serial.print( dmxTx4.packetSize());
Serial.print(" ");
Serial.print( dmxTx5.packetSize());
Serial.print(" ");
Serial.print( dmxTx6.packetSize());
Serial.print(" ");
Serial.print( dmxTx7.packetSize());
Serial.print(" ");
Serial.println( dmxTx8.packetSize());
//Serial.println( dmxTx.refreshRate());
dmxTx.set(10,data,3);
dmxTx2.set(10,data,3);
dmxTx.setPacketSize(data[0]);
dmxTx2.setPacketSize(data[0]+10);
dmxTx3.setPacketSize(data[0]+20);
// dmxTx4.setPacketSize(data[0]+30);
// dmxTx5.setPacketSize(data[0]+40);
// dmxTx6.setPacketSize(data[0]+50);
// dmxTx7.setPacketSize(data[0]+60);
// dmxTx8.setPacketSize(data[0]+70);
data[0]++;

delay(100);
}

Not receiveng DMX on teensy 4 with RX monitor on a specific dmx transmitter

Hi There!

I've been playing with the code for a long time now and I just encountered a problem that I can not figure a solution yet.
The problem is that I'm unable to receive valid DMX data from one of my DMX transmitters with the teensyDMX library.
I've tried with a hardware node and there I can receive correctly the DMX information coming from the same transmiter.
Clarify that the same code is sucsessfully receiving data coming from a second dmx transmiter from a different brand. So the problem seems to be the format of the DMX data.

I've enabled DMX monitor on pin 6 of the teensy 4,0 but without any luck. Also enabled setKeepShortPackets.

here is my code:

`/*

  • A basic toy receive example, demonstrating single- and
  • multi-byte reads.
  • This example is part of the TeensyDMX library.
  • (c) 2019-2020 Shawn Silverman
    */

#include

#include <TeensyDMX.h>

namespace teensydmx = ::qindesign::teensydmx;
elapsedMillis ledTimer;

// Create the DMX receiver on Serial2.
teensydmx::Receiver dmxRx{Serial2};

///////////////////////////////////////////////////////////////////////
// The last value on the channel, for knowing when to print a change
// (Example 1).
uint8_t lastValue = 0;

// Buffer in which to store packet data (Example 2).
uint8_t packetBuf[3]{0};

// The last values received on channels 10-12, initialized to zero.
uint8_t rgb[3]{0};
///////////////////////////////////////////////////////////////////////

void setup() {

// Turn on the LED, for indicating activity
pinMode(LED_BUILTIN, OUTPUT);
digitalWriteFast(LED_BUILTIN, HIGH);

// initate XBEE serial com
Serial1.begin (9600);

// Serial initialization, for printing things
Serial.begin(115200);
while (!Serial && millis() < 4000) {
// Wait for initialization to complete or a time limit
}
Serial.println("Starting BasicReceive + send XBEE");

// Start the receiver
dmxRx.begin();
int DMXwachPIN = 6;
pinMode (DMXwachPIN, INPUT);
dmxRx.setRXWatchPin (DMXwachPIN);
dmxRx.setKeepShortPackets(true);

// Print the first values
lastValue = dmxRx.get(1);
// Serial.printf("Channel 1: %d\n", lastValue);

delay (1000);
}

void loop() {
// The following two examples print values when they change

// Example 1. Get the current value of channel 1.
// This will return zero for no data (and also for data that's zero)
uint8_t v = dmxRx.get(1);
if (v != lastValue) {
lastValue = v;
Serial1.write (v); // Send to xbee
// Serial.printf("Channel 1: %d\n", v);
setLedAnalog(v);
}

if (ledTimer>300) {
setLedAnalog(0);
}

// print any received info from xbee
if (Serial1.available() > 0) {
int data = Serial1.read();
Serial.println (data,HEX);
}
}

void setLed(bool stateLed) {
digitalWriteFast(LED_BUILTIN, stateLed);
ledTimer = 0;
}

void setLedAnalog(uint8_t stateLed) {
analogWrite(LED_BUILTIN, stateLed);
ledTimer = 0;
}`

And the scope pictures of the different DMX signals starts (working and not working):

Working signal
WORKING SIGNAL

Not working signal
NOT WORKING SIGNAL

Any idea of what could be going wrong? Is there anything else I could try that comes to mind?
Thanks for this wonderfull library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.