Serial port not recognised

Status
Not open for further replies.

markvr

Active member
Hi, I've just bought a teensy for the first time, after initial great success, am having trouble with the serial port.

It worked OK for an hr or two, i.e. I could use the serial monitor in the Arduino/Teensduino IDE to see my Serial.print() messages, but now whatever I do it doesn't work!
What I've tried (several times!)
  • Unplug everything, power down laptop, remove battery.
  • Plug power and batt back in, boot up - Windows 7 64bit
  • Load Teensdyuino
  • Plug in teensy
  • Open Serial monitor
  • Get error: "Serial port 'COM6' in use"
  • Then if I try again, get error: Serial port 'COM6' not found
Example code (if it is relevant?)
Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Hello");
  delay(1000);
}

I've read the troubleshooting pages (http://www.pjrc.com/teensy/troubleshoot.html) but don't quite follow if I'm doing something wrong. The "USB type" in the IDE is set to "serial".

I've also tried different USB ports, and uninstalling the serial driver in Windows "device manager", then reinstalling it when I plug the teensy USB back in again.

I've run out of ideas :( Is my Teensy faulty, or is there something else wrong?
 
I got it working again, and think this was something to do with a line in another sketch, and I don't think my example sketch above had loaded properly - I'm still not entirely clear when I need to press the reset button and when I don't, especially with serveral Arduino windows open at once.

Anyway, the culprit is:
Serial.println("Counter:" + i);
Where "i" is an integer. This seems to crash the serial port in someway that nothing can reopen it. Rebooting (again...), and loading the example "blink" sketch out the IDE - and checking it had loaded, because it obviously blinks the led! - seemed to allow the Serial port to open, obviously with no content though.

Then replacing the line above with the printf example from http://playground.arduino.cc/Main/Printf seems to allow me to finally print what I was trying to do

I remember doing the same thing on an actual Arduino now, but that threw a compile time error about int to char conversion or similar.

I wonder if the Teensyduino libs could be updated to do a similar thing, rather than silently crashing the serial port?
 
"Counter:" + i might not mean anything sensible, depending on what type i happens to be and depending on whether or not + has been overloaded (redefined).

Assuming i is an int and + has not been overloaded, the one thing you won't get is "Counter:1", "Counter:2", etc.

The literal string "Counter:" is a pointer to a null-terminated sequence of characters. Adding something to this, moves the pointer. So for example, if i is 1, "Counter:" + 1 would be equivalent to "ounter:". If i was outside the range 0..8, Serial.println() will get a pointer to whatever happens to be in memory at that offset, not what was intended. Possible an invalid memory access.
 
Unfortunately, Serial.println("Counter:" + i); does not work. You need Serial.println(String("Counter:") + i); to make it work as intended.
 
Thanks both!

Just to wrap this up for anyone else reading: I'd recommend having your program do something like constantly flash the onboard LED when it runs, so you know it is still running OK. Combination of the seperate boot loader & more complex usb/serial interaction makes it less clear than an arduino what's going on (well to me anyway!).

I spent a while chasing down other problems with the serial port comms, and eventually realised my program was crashing(*) the Teensy, which takes the serial port out as well. Once I added a couple of lines to flash the LED every sec, and found it stopped flashing, I realised what was happening, fixed my program and all was well finally!

(*) - if you do analogReadAveraging(x) with x > 16 it crashes the Teensy.

Paul (or anyone else!): are there any docs I've missed on the extra functions you've written for the Teensy, like analogReadAveraging() etc? I'm currently relying on googling the forums for info, and didn't realise the max for that fn was 16.

@pictographer - ah the joys of low level programming! I know where I am with Java & JavaScript, this is a new world to me. I miss having decent debugging tools and stacktraces :(
 
Last edited:
I spent a while chasing down other problems with the serial port comms, and eventually realised my program was crashing(*) the Teensy, which takes the serial port out as well.

Version 1.17-rc1 has a fix for this, so the USB still (usually) continues to work, even if your program crashed. Please give it a try and let me know if it solves the problem for this particular type of crash?


(*) - if you do analogReadAveraging(x) with x > 16 it crashes the Teensy.

It's supposed to work for 32. No matter what value you use, the code should not crash. It's probably a bug.

Could you please post a small but complete program which reproduces this problem? It's entirely possible this bug depends on something else, so having a known-to-reproduce program really helps me investigate and fix whatever's wrong.

Paul (or anyone else!): are there any docs I've missed on the extra functions you've written for the Teensy, like analogReadAveraging() etc? I'm currently relying on googling the forums for info, and didn't realise the max for that fn was 16.

Some, but not all, are documented on the website. I have a lot more work to do!
 
Hi Paul,

Version 1.17-rc1 has a fix for this, so the USB still (usually) continues to work, even if your program crashed. Please give it a try and let me know if it solves the problem for this particular type of crash?
Hmm the installer doesn't seem to recognise my Arduino folder, "next" remains disabled even when it's the correct folder. The previous version installed fine.

Code sample below. With analogReadAverage() > 16 the Teensy crashes, Windows complains about a USB malfunction, and the LED doesn't flash. The method of using IntervalTimers was taking from the Adafruit tutorial on analog sampling with Teensys - http://learn.adafruit.com/fft-fun-with-fourier-transforms/overview-1

Code:
IntervalTimer samplingTimer;

void setup() {
  samplingTimer.begin(samplingCallback, 1000000/20000);  //20khz
  analogReadAveraging(16); // with this > 16 teensy crashes
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH); 
  delay(1000);              
  digitalWrite(13, LOW); 
  delay(1000); 
}

void samplingCallback() {
  int val = analogRead(0);
}
 
In that case you may want to install a fresh current version of Arduino 1.0.5. That seems to the the remedy the situations most of the time.
 
Status
Not open for further replies.
Back
Top