Teensy 4.1 serial communication issue

Tammo

New member
Hi, I recently started working with the Teensy 4.1 microcontroller. Unfortunately, I have troubles with serial communication. It seems like the board is not able to send anything to the computer over the USB cable (or it doesn't recognize that a serial monitor is connected). I will provide detail of my code and things I tried below.

First of all, I am working with the Arduino IDE version 2.0.3 and installed the teensy boards though the boards manager of the IDE. The teensy loader is version 1.58.

When I upload the example blink sketch, everything seems to work fine. I select the teensy 4.1 serial port (see the screenshot below), verify the blink.ino (see code below) file and press the programming button on the Teensy. Afterwards the LED on the Teensy starts blinking as expected.
Screenshot 2023-06-29 153312.png
Code:
const int ledPin = 13;

// the setup() method runs once, when the sketch starts

void setup() {
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
}

// the loop() methor runs over and over again,
// as long as the board has power

void loop() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
}

The problem occurs when I try to add any serial communication to the script. I do not see anything appearing in the serial monitor.
If I perform the exact same process but with a 'serial begin'- and 'serial print' -statement added, the program does not work. The code I upload is the following (commented "NEW" for the lines I added compared to the precious sketch):
Code:
const int ledPin = 13;

// the setup() method runs once, when the sketch starts

void setup() {
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);             //NEW
  while(!Serial);                 //NEW
  Serial.println("Hello World");  //NEW
}

// the loop() methor runs over and over again,
// as long as the board has power

void loop() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
  Serial.println("Loop");       // NEW
}

After verifying this code and pressing the programming button, I open the serial monitor in the IDE. I do not see anything printed to the monitor and do not see the LED blinking on the Teensy. This probably has something to do with the [while(!Serial);] line I added, and the code hangs in this loop. I also tried to remove this line, and keep everything the same as the previous code above. After verifying and pressing the programming button, the LED on the Teensy does blink, but nothing shows on the serial monitor.

Additionally I also tried to open the monitor while selecting the arduino COM port (COM11 in the screenshot above), without luck. I also tried to select a different USB type like 'Serial+keyboard+mouse+joystick'. But this didn't solve the problem either.
The USB cable seems to be fine, because I'm able to upload the blink sketch without any problem (also when changing the delays, the LED blinks at that different rate).

Hopefully someone has an idea what causes this behavior, because I'm not sure what to try next...

Some additional info:
  • My laptop is running Windows 10
  • Board: Teensy 4.1 purchased from Mouser
 
Is the small Teensy Loader window visible on your screen? It should appear automatically the first time you finish Verify or Upload. Best to move it to a place on your desktop where it remains visible, so you can keep an eye on it for troubleshooting.

During code upload, that Teensy Loader window will show your Teensy and status of programming. The whole process only takes only a second or two for small programs, so it's easy to miss if you're not watching at that moment. But if things aren't working, seeing the confirmation in that small window is pretty important to know whether code really was successfully loaded.
 
If uploading works, try setting Tools > USB Type to RawHID or MIDI. Those do not use serial protocol, so you will not see any COM port. Those use HID protocol to emulate serial, so you can still use Serial.print() to the serial monitor. As far as Windows is concerned, it is a completely different driver. So if this is some strange Windows serial driver issue, testing with HID can give an alternative way which doesn't use that driver.

Also with Windows, if things aren't working, try rebooting your machine. The sad reality of Windows is things sometimes get messed up in weird ways, but rebooting often solves those strange problems.
 
Thanks for the swift reply! The teensy loader indeed appears when I click the verify button. When I click the program button on the teensy, a progress bar appears on the teensy loader and afterwards a 'Reboot OK' message. This indeed is a fast process of around 1 second for the scripts I posted before.
The teensy loader gives the 'reboot OK'-message for each of the scripts I mentioned in my first post. So I think I can assume that the code is successfully loaded.
 
Check if some other application is blocking the COM port. E.g. some terminal, other uploaders, zombie tasks.... As Paul mentioned, rebooting shoud fix such things.
 
What might happen in your case:
the IDE opens and grabs the UART.
So, it is busy for any other tool, e.g. TeraTerm.

Try to change IDE not to open UART after flashing the FW.
It works fine for me.
BTW: it takes a while until the USB UART comes back after flashing the FW: you hear disconnects and connects on USB devices.
Do not try to open external UART tool too early. (I "monitor" by listening to the "USB Device Sounds"). It takes for me up to 2..5 seconds until MCU USB UART is available.
 
Back
Top