Basic Serial I/O 'lag'?

Status
Not open for further replies.

grit

Member
Hi,

I want to use a teensy 3.1 as midi serial receiver and send it to another serial port + modify messages, etc.

Anyway, I've setup this code to start and test the workings of this all:
Code:
void setup() {
        pinMode(LED, OUTPUT);
        digitalWrite(LED,HIGH);
        // connected midi devices to pins labeled 0 and 1 on the bottom of the T3.1
        Serial1.begin(31250);
        // output for PC
        Serial.begin(9600);
        // stabilize
        delay(100);
}

void loop() {
    // anything in MIDI?
    if (Serial1.available() > 0) {
      incomingByte = Serial1.read();
      // echo to PC
      Serial.print(incomingByte,HEX);
     // echo to midi hardware
      Serial1.write(incomingByte);
    }
}
the pins 0 and 1 have the proper hardware on them, optocoupler on IN port etc. The hardware works on the arduino uno on which I've set this up earlier.


The problem is that proper data is displayed on the pc but it takes about a second before it's output again. Taking out the Serial.write to disable local echo does not help. Setting 'local' Serial speed to faster 38400 also does not change this behavior. The Teensy 3.1 is set to 24MHz, 'Serial' mode.

What am I doing wrong? is the Teensy to fast or something?

UPDATE: Even the 'EchoBoth' example on the Teensy library has this extreme delay, Is there a configuration think I should know of?
 
Last edited:
Try adding a Serial.flush(); Also Serial is usb, so will always be the fastest so changing it's speed should have no effect.
 
I tried the flush() but it was not the issue I'm afraid.

It took me 4 hours and a night's sleep to realise I might try another MIDI-device to send the notes to the Teensy: turns out the lag was in the MIDI-device...

everything nice and smooth now (shame).
 
Glad you found the problem.

I was going to hook up a test with 2 boards sending bytes and watch on my oscilloscope, later today. But I've done that sort of test before while developing the code and delays have never been more than 1 bit time.

Any idea how another MIDI device could introduce a 1 second lag?
 
Well, I totally overlooked that the MIDI device was a virtual one which already got some processing though a browser plugin. The programming in the Arduino environment also set the browser to inactive state which kept that processing to the background... *sigh*, this is all too painful... Luckily now that's sorted I've already progressed pretty much with my MIDI merger.

So why all this; I've connected a DSP-G1 chip to the serial of the Teensy in order to make it a standalone module.
 
grit !!! [Re: your midi merger in progress]

just joined forum after discovering teensy Whoa! gonna need to create:
Merging 4 midi INs to 1 midi OUT (3 INs would be OK as well)

with a teensy 3.1 (i guess) that functioning as the standard USB midi interface (on PC) seen by Reaper

-- great to be here -- this is my first forum reply -- no comment needed to this of course - hehe
I'll keep popping back and learn more i bet.

Great!!
 
Status
Not open for further replies.
Back
Top