Poor Serial Output from Mega 2560 to CoolTerm Serial Monitor

Hello,

I’m attempting to use CoolTerm as a serial monitor for debugging purposes when working with an Arduino Mega (2560), but have noticed that CoolTerm is not accurately receiving the serial data being transmitted to it from my Mega. (FWIW, I’m running on a Mac - OS 10.9.1). CoolTerm seems to be displaying serial data from the Arduino Mega in short bursts every 5 - 15 seconds even though it should be displaying a continuous stream of values every second.

I originally noticed this when attempting to debug a large sketch wherein I’m configuring my Arduino to receive MIDI data being transmitted from a MIDI controller and use the MIDI signals to control a variety of LEDs, servos, and a stepper motor.

This is my serial data flow configuration:
MIDI Controller MIDI output —> Hairless MIDI/Serial Bridge —> Arduino Mega —> CoolTerm

For testing purposes, I created a much simpler sketch to rule out any other possible issues in my code:

#include <MIDI.h>

int testVal; 

//=================ARDUINO SETUP FUNCTION=====================
void setup() {
  //MIDI & serial setup
  MIDI.begin();
  Serial.begin(57600);
  MIDI.turnThruOff();
  MIDI.setHandleControlChange(ControlViaCC);
  
  testVal = 0;  
}

//================VOID LOOP FUNCTION======================

void loop() {
  
  while(MIDI.read())
    true;
    
  Serial.println(testVal);
}

//==============CC CALL BACK================
void HandleControlChange (byte channel, byte number, byte value);

void ControlViaCC (byte channel, byte number, byte value)
{ 
  if (number == 71) //rotary encoder 'B1' on axiom controller
  {
    testVal = value; //pure CC value (0-127) for testing purposes
  }
}

In spite of its simplicity, when running this code on my Mega, CoolTerm still displays delayed serial transmissions in irregular bursts.

I’ve ensured that the baud rate settings of my Arduino, the Hairless MIDI Serial Bridge, and CoolTerm are all set to transmit and receive at the same rate (in this example, 57600 baud, 8 data bits, no parity, and 1 stop bit.)

I ran the same code using the same connection configuration and baud rate settings as above on an Arduino Pro Mini (3.3V, 8Mhz w/ ATmega328), and CoolTerm picks up the serial data transmitted from the Arduino Pro Mini just fine (in a continuous stream of values in real time).

All other things being equal, it seems like the Mega is the only variable creating the delayed serial transmission to CoolTerm. Why does the serial output from my Mega display in CoolTerm in an irregular and delayed fashion while the serial output from my Arduino Pro Mini does not?

Thank you in advance for your help.

Has anyone else ever had this issue when using a Mega or other arduino? I'm still at a loss as to what to do to be able to establish accurate serial output monitoring of my Mega and can't figure out why my Mega's serial output is behaving this way...

FWIW, I managed to find a work-around to this issue. While I don't conclusively know what was causing the Mega's poor serial output from its Serial0 port, I have a suspicion it has something to do with the ending bytes of the MIDI input messages I was sending it garbling the serial output. Anyone else's theories are welcome.

My work around was fairly simple, I connected an FTDI to USB cable I got from Sparkfun (https://www.sparkfun.com/products/9718) to the Serial1 port of the Mega and configured my test sketch to output the test variable values through this port. When monitoring the output from this port with CoolTerm or with the Arduino Serial monitor, the values streamed through in real-time as I hoped without any of the delay and irregularity I was experiencing earlier. It's kind of awkward having to connect two USB cables to the Arduino and my computer, but it does the job for now.