Cannot Use Multiple Serial Instances Concurrently for TeensyDMX [Teensy 4.0]

chaps

New member
I am currently at my wits end trying to make this work, I suppose my understanding of how Teensy handles HardwareSerial may be an issue with the code I am trying to write.

The original idea for this mini-project (a first step in a much larger endeavor), was to set my Teensy to a Raw HID mode, allow communication from a connected computer, and use the TeensyDMX library to talk to a simple DMX controlled light I am using to test my code. With the XLR ground connected to ground, Data+ connected to pin 1, and Data- connected to pin 2, I am successful at getting my light to turn red, or any other color I choose to initialize with.

However, any call to delay() is simply ignored by the program, and seems to halt. This is understandable, as the Serial libraries that TeensyDMX is built upon probably uses interrupts (I could be wrong here too, I make a lot of assumptions about the things I am working with), which can interfere destructively with a delay() call. I had some success using IntervalTimers to control the output of some of the channels, and that's as far as I got. I switched back from Raw HID to plain serial communication under the assumption that the library might be out of date, but I cannot seem to be able to communicate with my computer in any meaningful way with Serial as well. As soon as the connection with the light is established, no data can be sent to my computer using Serial.println(), Serial.write() or anything else. Is it the case that the Serial ports used by TeensyDMX "hog" up the USB Serial connection to my laptop, or am I experiencing one of many brain-dead moments where the answer is quite obvious but I keep ramming my head into the wall trying to accomplish something that is functionally impossible with the code I am trying to write?

I have scoured the forums trying to find anyone who has been in my position but I cannot seem to find anything. I appreciate those who can come to my assistance.

Here is my (very basic) test code for the communication/lighting duo I am trying to accomplish.

Code:
#include <TeensyDMX.h>



namespace teensydmx = ::qindesign::teensydmx;

teensydmx::Sender Univ_1{Serial1};

/**Ignore the extra universes, I'm saving these for later**/
//teensydmx::Sender Univ_2{Serial1};
//teensydmx::Sender Univ_3{Serial2};
//teensydmx::Sender Univ_4{Serial3};


byte buffer[64];
void setup() {
  
  Serial.begin(9600);
  
  Univ_1.begin();
  
  Univ_1.set(1, 255);
  Univ_1.set(2, 255);
  
  
}

void loop(){

  Serial.println(1);

}
 
I just tested this on a Teensy 4.0 and it seems to work as expected. Is it possible something isn't connected correctly?

I tested your code and I tested with adding a `delay(10)` after the `Serial.println(1)`.

Some notes:
1. I would use 115200 instead of 9600 (might not really make a difference here, but that's my usual embedded system default).
2. Set the channel values before calling begin() because then it's guaranteed the output will start at those values instead of a possible few frames at zero.
 
I just tested this on a Teensy 4.0 and it seems to work as expected. Is it possible something isn't connected correctly?

I tested your code and I tested with adding a `delay(10)` after the `Serial.println(1)`.

Some notes:
1. I would use 115200 instead of 9600 (might not really make a difference here, but that's my usual embedded system default).
2. Set the channel values before calling begin() because then it's guaranteed the output will start at those values instead of a possible few frames at zero.

Serial.begin does not take any account of the "baud rate" presented to it. It simply goes as fast as it can. You could use Serial.begin(0) and it would still funtion.
In fact the best entry is probably Serial.begin(9) since it uses a minimum of keystrokes and the more natural (for me in any case) to type than Serial.print(0).
 
I just tested this on a Teensy 4.0 and it seems to work as expected. Is it possible something isn't connected correctly?

It's entirely possible that I have something wired incorrectly, or I could have a faulty board (which would be quite unfortunate).

Did you test the code with an active connection to a light or some other DMX-controlled object? I am only running into issues when the board actively connects to the light. If the wires are removed from my breadboard, the code runs as normal.

I am currently using an old XLR cable which I spliced open into, and connection-tested to determine which pin corresponded with each wire. Since I am using Serial1 on the Teensy, I have XLR Pin 1 connected to Teensy pin GND, XLR Pin 2 connected to Teensy Pin 1, and XLR Pin 3 connected to Teensy Pin 0. I have tried flipping around the wires, but none output DMX except for the configuration which I have currently.
 
Thanks for the answer, I'll look into buying a couple of those. Once I implement the transceivers, I should be able to communicate both with the lights and my computer, correct?

Any idea why I was able to get an output from the board to the lights if the protocols aren't compatible?
 
Back
Top