Serial monitor problems arduino 1.6.13/ teenly lc

Serioius serial monitor problems HELP!!!!!!!

I am having similar problems. Serial monitor was never reliable with the Arduino IDE and windows. I always had to screw around with everything i could, running into Java crashes if data was sent too quickly all sorts of other problems. Had to add delays to prevent Java crashes and that made it impossible to do real time debugging.

I was using the serial monitor somewhat reliably a day or two ago and now there is nothing i can do to keep it running for more than a second or two. Here are some details. Arduino 1.8. The latest Teensyduino. Windows 10 64 bit. I have not changed anything since the time when the serial monitor was working fairly reliably. I have tried several teensy 3.5 and 3.6 boards, different cables and rebooted the computer many times.

Now i get a blank monitor window most of the time but occasionally a little data for about a second and then it freezes. Closing the monitor and opening it does not help. If i recompile and reload to the teensy i can some times get the serial monitor window to work but now only briefly. I have changed USB sockets between usb2 and usb 3 ports. I turned off bluetooth, changed baud rate up and down, added a delay in the code after serial begin and used this suggested code:
void setup() {
Serial.begin(57600);
while(!Serial && millis() < 5000 );
I can't think of anything else to try and really need the monitor. I am debugging a very complicated sketch and need the monitor. I have a very good reliable computer but it is running windows :) any other suggestions? I have no problem uploading compiled code so i doubt it is a cable or socket problem especially since i have tried three cables and two different boards 3.5 and 3.6.
 
the thing with serial monitor is if your flooding it with values like millions of lines long as well itll crash the IDE and youll have to restart it to restore functionality again

whats your OS? not just windows, VERSION
also your complete code, what you posted only enables the native usb.
 
Last edited:
windows 10 64 bit as mentioned above. here is the main loop. the sketch is over 1200 lines. i am gong to make a complete working simplified version of the sketch to see if it will break with what i just discovered seems to break it. The sketches uses accelstepper and the teensy audio library. using the audio shield too. If i use stepper stepper.moveTo (); it works and the monitor displays the changing values. If i use stepper.runToNewPosition(); the serial monitor crashes. runToNewPosition is blocking but shouldn't the serial monitor keep running?

#include <Encoder.h>
#include <EEPROM.h>
#include <AccelStepper.h>

// Audio Stuff
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

int speed;

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputI2S audioInput; // audio shield: mic or line-in
AudioAnalyzePeak peak_L;
AudioAnalyzePeak peak_R;
AudioAnalyzeRMS rms_L;
AudioAnalyzeRMS rms_R;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

AudioConnection c1(audioInput, 0, peak_L, 0);
AudioConnection c2(audioInput, 1, peak_R, 0);
//AudioConnection c3(audioInput, 0, rms_L, 0);
//AudioConnection c4(audioInput, 1, rms_R, 0);
AudioConnection c5(audioInput, 0, audioOutput, 0);
AudioConnection c6(audioInput, 1, audioOutput, 1);

AudioControlSGTL5000 audioShield;
void loop() {
uint8_t leftPeak;
uint8_t rightPeak;
uint16_t totalPeak;
uint16_t speed_value;
if(fps > 24) {
if (peak_L.available() && peak_R.available() ) {
fps=0;
leftPeak = peak_L.read() * 10;
rightPeak = peak_R.read() * 10;
totalPeak = (leftPeak + rightPeak) * 10;
speed = 300 * totalPeak;
Serial.print("totalPeak ");
Serial.println(totalPeak);
}
}
stroke = totalPeak;
stepper.setMaxSpeed(speed);
// stepper.runToNewPosition(stroke);
stepper.moveTo (stroke);

read_encoders();
}
 
Does the unreliable behavior change between setting Tools > USB Type to Serial vs MIDI? This is important, because Serial mode uses the serial driver (USBSER.SYS) and MIDI uses Window's HID driver to emulate serial.

Does adding or removing a USB hub make a difference? You might think hubs don't matter, but they do indeed matter tremendously. With a USB 2.0 hub, Windows will use the EHCI driver to talk 480 Mbit/sec to the hub, and the conversion to 12 Mbit/sec happens by a transaction translator within the hub. But if there no hubs at all between Teensy and your PC, then Windows will use the OHCI driver to talk 12 Mbit/sec.

Less like to matter, but also worth trying is plugging into different USB ports on your computer. Even if they're on the same USB controller, Windows is a little silly about storing duplicate groups of settings for each physical port. It's possible, but unlikely, that these settings could be corrupted in the Windows registry.

Also unlikely is a flaky USB cable or hub. Usually bad cables are all-or-nothing, but we've had cases where they sometimes work. Not long ago on this forum we had a guy report troubles where some boards worked and others didn't, and after much effort he discovered it was all due to a previously good cable going bad. These problems are relatively rare, but so easy to check, so don't overlook trying with another cable.

If none of these make any difference, it's also quite possible something is wrong with Java.

Recently, a release of the nVidia drivers caused all sort of problems with many Java programs (not just Arduino). Other things can go wrong with Java... but first, please try those suggestions above so we can at least get some info about whether the problem is USB or USB driver related.
 
I guess I should have also stated the obvious thing... to do Windows/USB/Java testing with a relatively simple program running on the Teensy side!
 
As noted - the Teensy can generate data faster than even USB can take and get passed for usable display on the monitor.

You might search forum for TyCommander and give that a try. It has some better features on connectivity - and reconnecting - but seems to have similar limits on overwhelming high speed useful display in some regards.

Try a simpler test sketch perhaps just to do simpler prints - try the edit/compile/upload and see if it acts differently. Use elapsedMillis - watch millis() - or use delay(1000) to limit the print repeat rate then print once per second some changing string with millis() or something.

If you use TyCommander it will quickly connect and reconnect on power up. Or with tools / integrate to Arduino: it will stop serial during upload and automatically reconnect more reliably than I've seen SerMon do very often.
 
There's also a possibility everything is working perfectly on your PC and the problems could all be on the Teensy side.

Especially if you're making use of interrupts and printing from both main program and interrupt context, data loss or corruption might be happening on Teensy before the USB is involved at all.

Bugs with pointers or incorrectly sizes arrays can corrupt memory, also causing terribly mysterious problems.

While trying to isolate the issue, run a very simple program on Teensy that just prints data very quickly from loop().
 
working but ???

I cut the program down to a bare minimum and could finally find the problem. It was in fact something stupid. I had a variable assignment outside of a loop it should have been. This gave accelstepper bogus values but for some reason one method did not care and the other did. Because i was having a series of serial monitor problems with both this and other sketches and boards i made the false assumption that it was a serial monitor problem. Now i can address the serial monitor problems when they happen again using all the suggestions from this forum. I am going to get TyCommander as that might be all i need when the serial monitor does mess up.

My latest testing was done choosing USB MIDI. Here is the code that works including the location where i assigned the variable incorrectly. I know this was a stupid mistake but still do not understand why it worked with moveTo and not runToNewPosition hopefully, one of the forum's geniuses can explain this to me so i can avoid similar problems in the future :) now to get TyCommander and see what that does. Thanks everyone for forcing me to look at this in a better way than i had before.


#define ENCODER_DO_NOT_USE_INTERRUPTS
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
#include <EEPROM.h>
#include <AccelStepper.h>

// Audio Stuff
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputI2S audioInput; // audio shield: mic or line-in
AudioAnalyzePeak peak_L;
AudioAnalyzePeak peak_R;
AudioAnalyzeRMS rms_L;
AudioAnalyzeRMS rms_R;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

AudioConnection c1(audioInput, 0, peak_L, 0);
AudioConnection c2(audioInput, 1, peak_R, 0);
AudioConnection c5(audioInput, 0, audioOutput, 0);
AudioConnection c6(audioInput, 1, audioOutput, 1);

AudioControlSGTL5000 audioShield;

AccelStepper stepper(AccelStepper::DRIVER,3,4);

int count = 0;
int encoder_scale;
int min_stroke;
int max_stroke;
int max_speed;
int max_stroke_setup;

long stroke;
long acceleration;
//long min_acceleration;
//long max_acceleration;
//long acceleration_setup;
//long acceleration_default;
//unsigned long CW_count;
//unsigned long CCW_count;
int speed;

boolean encoder;

void setup() {
Serial.begin(57600);
while(!Serial && millis() < 5000 );

Serial.println("begin setup");
AudioMemory(6);
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(1);

max_speed = 30000;
acceleration = 200000; // do not change from 200000 unless there is a really good reason
stepper.setMaxSpeed(max_speed);
stepper.setAcceleration(acceleration); // 80000 is fast enough might make it less
stepper.setPinsInverted(true,true,true);
stepper.setMinPulseWidth(20);
stepper.setCurrentPosition(0) ;

pinMode(1, INPUT_PULLUP); // determines if three knob controller is connected
pinMode(3, OUTPUT); // step
pinMode(4, OUTPUT); // direction

}

elapsedMillis fps;

void loop() {
uint8_t leftPeak;
uint8_t rightPeak;
uint16_t totalPeak;
uint16_t speed_value;
if(fps > 24) {
// Serial.println("over 24");
if (peak_L.available() && peak_R.available() ) {
fps=0;
leftPeak = peak_L.read() * 10;
rightPeak = peak_R.read() * 10;
totalPeak = (leftPeak + rightPeak) * 10;
speed_value = 300 * totalPeak;
stroke = totalPeak;
Serial.print("totalPeak ");
Serial.println(totalPeak);
Serial.print("stroke ");
Serial.println(stroke);
}
// stroke = totalPeak; this is the wrong place for updating the value and caused serial monitor to not work
}

speed = constrain ((speed_value),0,max_speed);
stepper.setMaxSpeed(speed);
// comment out one of the following lines to choose runToNewPosition or moveTo
stepper.runToNewPosition(stroke);
// stepper.runToNewPosition(0);
// stepper.moveTo (stroke); stepper.run();
 
in case anyone wants to run the code, i noticed that a smily face was substituted for a : followed by a D in this line. "AccelStepper stepper(AccelStepper:: DRIVER,3,4);" i guess there s some way to post code that is not modified with emoticons etc?
 
when posting code wrapping it in
[C0DE] // Code here
// NOTE: CODE is given in all upper case to be recognized - Zero/0 was used to allow display
[/C0DE]
blocks should prevent such 'funny' edits.
 
smilies etc

it looks like there is also an option to disable smileys if you use the advanced editor. this shroud not be a smiley :) nor this D:
 
Using the CODE blocks is the best way - it preserves indenting and presents code in a readable way - on adavanced there is a #/Hash icon to insert the CODE tag:

Code:
const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputI2S audioInput; // audio shield: mic or line-in
AudioAnalyzePeak peak_L;
AudioAnalyzePeak peak_R;
AudioAnalyzeRMS rms_L;
AudioAnalyzeRMS rms_R;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

AudioConnection c1(audioInput, 0, peak_L, 0);
AudioConnection c2(audioInput, 1, peak_R, 0);
AudioConnection c5(audioInput, 0, audioOutput, 0);
AudioConnection c6(audioInput, 1, audioOutput, 1);

AudioControlSGTL5000 audioShield;

AccelStepper stepper(AccelStepper:RIVER,3,4);

Random indented code sample::
Code:
void rx_callback2( void ) {
  uint32_t jj, rx_size2;
  rx_size2 = Serial2.available();
  if (rx_size2 > 256) {
    rx_size2 = 256;
  }
  if (rx_size2)
  {
    Serial2.read(&rx_data2[rx_count2 & 0xff], rx_size2);
    for (jj = 0; jj < rx_size2; jj++)
    {
      if (rx_data2[(rx_count2 & 0xff) + jj] != (((rx_count2 & 0xff) + jj) & 0xff))
      {
        if ( !GoneBad )
          printf("MISMATCH_2 %02x %02x @ %08x (%08x)\r\n", rx_data2[(rx_count2 & 0xff) + jj], (((rx_count2 & 0xff) + jj) & 0xff), (rx_count2 + jj), tx_count2);
        GoneBad = true; //while (1) { }
      }
    }
    rx_count2 += rx_size2;
  }
}

<EDIT>:: BTW - to make code consistent before copying from IDE - a:: Ctrl+T - will format the code uniformly for indents and spacing.
 
Last edited:
Back
Top