Weird problem getting Teensy to appear in ports in Arduino software

nicnut

Well-known member
Hi,

Wow something unusual just happened. I've been trying for an hour to upload a sketch to my Teensy 4.1. After trying over and over again, and google searching, I opened the Forum homepage, and magically the Teensy appeared in the port options and I was able to upload my sketch.

Here is a detailed description of my issue. I have a Teensy 4.1. I am trying to upload a Serial+ Midi USB type sketch. I am using a Mac M2, OS 14.7.2, Arduino software 2.3.6, Teensy loader 1.59.

I have been trouble shooting my text for several hours. I had another Teensy plugged in for a bit. I unplugged it and tried to upload my sketch to my Teensy, but it doesn't show up in the ports.

This is the error message I received in Arduino software:



Memory Usage on Teensy 4.1:
FLASH: code:12436, data:4040, headers:9120 free for files:8100868
RAM1: variables:4960, code:9744, padding:23024 free for local variables:486560
RAM2: variables:12416 free for malloc/new:511872
Teensy should be selected from "teensy ports" rather
than "Serial ports" in Arduino's Tools > Port menuNo Teensy boards were found on any USB ports of your computer.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
Failed uploading: uploading error: exit status 1

I kept plugging and unplugging the Teensy, same with the USB cable to the computer, restarted the software and the computer. Nothing worked. Then I come to this site and it somehow shows up.

If anyone has any suggestions when this happens again let me know. Could it be a power issue? It's only getting USB power.

Thanks, Nick
 
What happened when you pressed the "PROGRAM MODE BUTTON" as instructed in the message?
When I pressed the button on the teensy it didn't seem to change anything. I also pressed it in the Teensy software. My impression of what was going on was that the Teensy couldn't mount or be recognized by my computer, but I don't know. Then all of a sudden it was recognized and appeared as an available port to upload my sketch.
 
OK I am having the same issue now. I am trying to upload a sketch. The Teensy is not appearing in the available ports. I am pressing the button on the Teensy, then pressing upload on the software, but it's not working. I get the same error message that says to press the button. I will keep trying to plug in and unplug the teensy.
EDIT: I found out a workaround. I plugged in an old Teensy 3.6 and it immediately mounted, so i selected that port in Arduino software, then I unplugged it and plugged in the 4.1 and uploaded.
 
Last edited:
My guess is you might have a wonky USB cable which fits loosely into the USB connector. Maybe it has best electrical contact just before being fully pressed into the connector? Such cables sometimes work, sometimes fail, and the changes tend to come with unplugging and plugging back in.
 
Hi defragster. Ok this might be what the problem is. I plug my old 3.6 in and it immediately mounts, I plug the 4.1 in and it doesn't mount at all any more. Ultimately I need to run two Teensy 4.1 through a hub and into another hub and into my Mac. I hope those hubs will go the correct speed as well.

What exactly is the USB port that is on the Teensy 4.1? I am attatching images of the cable I am using coming out of the Teensy (4.1 or 3.6). Do I need a micro USB cable for this?

Then, coming out of the hub, I will need a fast USB C cable.

If you have any suggestions for finding fast cables please let me know. I am looking online now and some cables don't specify their speed.

Thank you so much for the comment, I am hoping this is what my issue is.



cable2.jpeg

cable11.jpg
 
Micro USB is the needed cable - it just has the faster USB support on the T_4.1 MCU processor that runs at the higher speed than the T_3.x processors would support. The USB support is native to the processor - unlike other or older Arduino units that shared a UART to a USB converter chip.

If you plug into a reliable fast Hub that is good then to power multiple Teensy 4.1 or other - with good cables. I have a multiport HUB and bought a set of different color 1 ft short Micro USB to fit on this desk and they work with no problem.

The cable quality has to be a new data cable, and I have had a working cable go to NOT WORKING after some use and swapping to a new cable made that work again.
 
Ok, I purchased several high speed USB cables. I am getting the same result. The 4.1 isn't mounting. I have two of them and tried both of them with several cables. The 3.6 I have mounts immediately.
Another thing that I think is interesting is that when I plug either 4.1 in, the red LED blinks 4 times, then pauses, then blinks 4 times, etc. Does this indicate anything? I don't think that's in my code. Is there anything else I can try to resolve this?

If I can't figure it out I guess I can go back to using Teensy 3.6. This seems strange to me because I was doing a project with a Teensy 4.1 earlier this year and never had this problem. Any suggestions are greatly appreciated.
 
when I plug either 4.1 in, the red LED blinks 4 times, then pauses, then blinks 4 times, etc. Does this indicate anything?

Yes, 4 blinks means something has gone wrong. The blink code as documented on this page. Scroll down to "Troubleshooting & Diagnostic Blink Codes"


Usually 4 blinks means something is wrong with the 24 MHz crystal. Sometimes this can be caused by debris or leftover flux chemical if soldering to the nearby pins. Sometimes cleaning with isopropyl alcohol and allow it to fully dry fixes this problem.
 
OK thank you PaulStoffergen. I will try and clean my Teensy and see if that works. Is the crystal on the opposite side of the pins? I didn't solder anything to the pins, I am using some headers that plug into the pins and all my connections are soldered to that.

Here is some additional info. I shut down my computer, restarted, pressed the reset button on the teensy and plugged it into my computer. After a few seconds I got a solid red LED, then I released the reset button. The LED turned orange and the board mounted and I was able to upload a sketch. Then after unplugging and plugging in again the board won't mount and I get the 4 red blinks on the Teensy LED again.

I will try and clean the 4.1s and see what happens. If you have any other suggestions please let me know.
 
Hi Everyone. Ok I want to share some more information regarding my issue. I was doing another project with a Teensy 4.1 earlier this year, and have never had any issues with that board. I just plugged it in and it mounted right away. I plugged it into all the same USB hubs and cables I tried with the problematic 4.1 boards and this older one mounted immediately.

I also tried cleaning the problematic board with isopropyl alcohol and that didn't solve anything.

Is it possible that the code I uploaded to my new Teensy's did something to make it not mount? One of the sketches is pretty simple so that would seem unlikely. I was doing USB type: Serial + MIDI. Maybe only a certain number of serial devices can mount at a time.

Thank You.
 
Hi everyone. I hope I am not posting too much in this forum, but I do want to share my thoughts and progress on this issue in case anyone can offer feedback.

So the 2 Teensy 4.1s I have don't mount and are not seen by Arduino software, nor by my computer. I have high speed cables and I cleaned them with Alcohol and that didn't help. However, they used to be seen by my computer and mounted fine. I have one Teensy 4.1 that mounts right away, and my old 3.6s mount right away.

I think either I uploaded some code to the new Teensy 4.1s that is causing them to not mount, or something occurred while I was uploading to them that caused the problem. Let me know if either of these sound plausible. Also, when I was first uploading to them I used USB type: MIDI + Serial. I don't need the serial part so I will now just be uploading as MIDI.

I am including my code here in case anyone wants to check and see if there is something that could be causing my problem.

Also, Originally I had many many lines of comments in the uploaded version. I deleted that, so this is a shorter amount of lines of code. The code is essentially taking analog and digital sensor input and outputting MIDI data.

Thank you. Nick

Code:
#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 1;
const int MIDIchannel = 1;  // this will only apply to midi channel 1


// the MIDI continuous controller for each analog input
const int controllerA0 = 1;    //  control change 1, ribbon
const int controllerA1 = 2;    //control change 2
const int controllerA2 = 3;    //control change 3
const int controllerA3 = 4;    // control change 4
const int controllerA4 = 5;    // control change 5
const int controllerA5 = 6;    // control change 6
const int controllerA6 = 7;    // control change 7
const int controllerA7 = 8;    // control change 8
const int controllerA8 = 9;    // control change 9  last ribbon
const int controllerA9 = 10;   // control change 10 joystick
const int controllerA10 = 11;  // joystick
const int controllerA11 = 12;  // control change 12
const int controllerA12 = 13;  // control change 13  joystick

const int controllerD14 = 14;  // toggle, control change 14
const int controllerD15 = 15;  //  Button, control change 15
const int controllerD16 = 16;  //
const int controllerD17 = 17;
const int controllerD18 = 18;  //
const int controllerD19 = 19;
const int controllerD20 = 20;
const int controllerD21 = 21;
const int controllerD22 = 22;
const int controllerD23 = 23;
const int controllerD24 = 24;
const int controllerD25 = 25;
const int controllerD26 = 26;
const int controllerD27 = 27;
const int controllerD28 = 28;
const int controllerD29 = 29;
const int controllerD30 = 30;



// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5);  // which is appropriate for good
Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5);  // to rapid touch, you can
Bounce button7 = Bounce(7, 5);  // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5);  // goes out of order because other pins double as analog inputs, ctlin 26

Bounce button24 = Bounce(28, 5);
Bounce button25 = Bounce(29, 5);
Bounce button26 = Bounce(30, 5);
Bounce button27 = Bounce(31, 5);
//Bounce button28 = Bounce(32, 5);


void setup() {


  pinMode(0, INPUT_PULLUP);  // for button swithces
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(28, INPUT_PULLUP);
  pinMode(29, INPUT_PULLUP);
  pinMode(30, INPUT_PULLUP);
  pinMode(31, INPUT_PULLUP);



  usbMIDI.setHandleControlChange(myControlChange);
  //setupLedDisplays();
}

// store previously sent values, to detect changes
int previousA0 = -1;
int previousA1 = -1;
int previousA2 = -1;
int previousA3 = -1;
int previousA4 = -1;
int previousA5 = -1;
int previousA6 = -1;
int previousA7 = -1;
int previousA8 = -1;
int previousA9 = -1;
int previousA10 = -1;
int previousA11 = -1;
int previousA12 = -1;


elapsedMillis msec = 0;



void loop() {

  {

    button0.update();  //  this button code works, goes from 0 to 127 when pressed
    button1.update();
    button2.update();
    button3.update();
    button4.update();
    button5.update();
    button6.update();
    button7.update();
    button8.update();
    button9.update();
    button10.update();
    button11.update();
    button12.update();
    button24.update();
    button25.update();
    button26.update();
    button27.update();
    //button28.update();
    



    if (button0.fallingEdge()) {  // this deals with reading the button swithces
      usbMIDI.sendControlChange(controllerD14, 127, channel);
    }

    if (button0.risingEdge()) {
      usbMIDI.sendControlChange(controllerD14, 0, channel);
    }

    if (button1.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD15, 127, channel);
    }

    if (button1.risingEdge()) {
      usbMIDI.sendControlChange(controllerD15, 0, channel);
    }

    if (button2.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD16, 127, channel);
    }

    if (button2.risingEdge()) {
      usbMIDI.sendControlChange(controllerD16, 0, channel);
    }

    if (button3.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD17, 127, channel);
    }

    if (button3.risingEdge()) {
      usbMIDI.sendControlChange(controllerD17, 0, channel);
    }

    if (button4.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD18, 127, channel);
    }

    if (button4.risingEdge()) {
      usbMIDI.sendControlChange(controllerD18, 0, channel);
    }

    if (button5.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD19, 127, channel);
    }

    if (button5.risingEdge()) {
      usbMIDI.sendControlChange(controllerD19, 0, channel);
    }

    if (button6.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD20, 127, channel);
    }

    if (button6.risingEdge()) {
      usbMIDI.sendControlChange(controllerD20, 0, channel);
    }

    if (button7.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD21, 127, channel);
    }

    if (button7.risingEdge()) {
      usbMIDI.sendControlChange(controllerD21, 0, channel);
    }

    if (button8.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD22, 127, channel);
    }

    if (button8.risingEdge()) {
      usbMIDI.sendControlChange(controllerD22, 0, channel);
    }

    if (button9.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD23, 127, channel);
    }

    if (button9.risingEdge()) {
      usbMIDI.sendControlChange(controllerD23, 0, channel);
    }

    if (button10.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD24, 127, channel);
    }

    if (button10.risingEdge()) {
      usbMIDI.sendControlChange(controllerD24, 0, channel);
    }

    if (button11.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD25, 127, channel);
    }

    if (button11.risingEdge()) {
      usbMIDI.sendControlChange(controllerD25, 0, channel);
    }

    if (button12.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD26, 127, channel);
    }

    if (button12.risingEdge()) {
      usbMIDI.sendControlChange(controllerD26, 0, channel);
    }

    if (button24.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD27, 127, channel);
    }

    if (button24.risingEdge()) {
      usbMIDI.sendControlChange(controllerD27, 0, channel);
    }



    if (button25.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD28, 127, channel);
    }

    if (button25.risingEdge()) {
      usbMIDI.sendControlChange(controllerD28, 0, channel);
    }

if (button26.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD29, 127, channel);
    }

    if (button26.risingEdge()) {
      usbMIDI.sendControlChange(controllerD29, 0, channel);
    }
if (button27.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD30, 127, channel);
    }

    if (button27.risingEdge()) {
      usbMIDI.sendControlChange(controllerD30, 0, channel);
    }


  }


  // only check the analog inputs 50 times per second,
  // to prevent a flood of MIDI messages
  if (msec >= 3) {  //  i changed this value to 10 from 20 for faster updates
    msec = 0;

    int n0 = map(analogRead(A0), 0, 1023, 0, 127);
    int n1 = map(analogRead(A1), 0, 1023, 0, 127);
    int n2 = map(analogRead(A2), 0, 1023, 0, 127);
    int n3 = map(analogRead(A3), 0, 1023, 0, 127);
    int n4 = map(analogRead(A4), 0, 1023, 0, 127);
    int n5 = map(analogRead(A5), 0, 1023, 0, 127);
    int n6 = map(analogRead(A6), 0, 1023, 0, 127);
    int n7 = map(analogRead(A7), 0, 1023, 0, 127);
    int n8 = map(analogRead(A8), 0, 1023, 0, 127);
    int n9 = map(analogRead(A9), 0, 1023, 0, 127);
    int n10 = map(analogRead(A10), 0, 1023, 0, 127);
    int n11 = map(analogRead(A11), 0, 1023, 0, 127);
    int n12 = map(analogRead(A12), 0, 1023, 0, 127);


    // only transmit MIDI messages if analog input changed
    if (n0 != previousA0) {
      previousA0 = n0;
      if (n0 < 5) n0 = 0;
      usbMIDI.sendControlChange(controllerA0, n0, channel);
    }

    if (n1 != previousA1) {
      previousA1 = n1;
      if (n1 < 5) n1 = 0;
      usbMIDI.sendControlChange(controllerA1, n1, channel);
    }

    if (n2 != previousA2) {
      previousA2 = n2;
      if (n2 < 5) n2 = 0;
      usbMIDI.sendControlChange(controllerA2, n2, channel);
    }
    if (n3 != previousA3) {
      previousA3 = n3;
      if (n3 < 5) n3 = 0;
      usbMIDI.sendControlChange(controllerA3, n3, channel);
    }

    if (n4 != previousA4) {
      previousA4 = n4;
      if (n4 < 5) n4 = 0;
      usbMIDI.sendControlChange(controllerA4, n4, channel);
    }

    if (n5 != previousA5) {
      previousA5 = n5;
      if (n5 < 5) n5 = 0;
      usbMIDI.sendControlChange(controllerA5, n5, channel);
    }

    if (n6 != previousA6) {
      previousA6 = n6;
      if (n6 < 5) n6 = 0;
      usbMIDI.sendControlChange(controllerA6, n6, channel);
    }

    if (n7 != previousA7) {
      previousA7 = n7;
      if (n7 < 5) n7 = 0;
      usbMIDI.sendControlChange(controllerA7, n7, channel);
    }

    if (n8 != previousA8) {
      previousA8 = n8;
      if (n8 < 5) n8 = 0;
      usbMIDI.sendControlChange(controllerA8, n8, channel);
    }

    if (n9 != previousA9) {
      previousA9 = n9;
      if (n9 < 3) n9 = 0;
      usbMIDI.sendControlChange(controllerA9, n9, channel);
    }

    if (n10 != previousA10) {
      previousA10 = n10;
      if (n10 < 3) n10 = 0;
      usbMIDI.sendControlChange(controllerA10, n10, channel);
    }

    if (n11 != previousA11) {
      previousA11 = n11;
      if (n11 < 3) n11 = 0;
      usbMIDI.sendControlChange(controllerA11, n11, channel);
    }

    if (n12 != previousA12) {
      previousA12 = n12;
      if (n12 < 3) n12 = 0;
      usbMIDI.sendControlChange(controllerA12, n12, channel);
    }
  }

  // MIDI Controllers should discard incoming MIDI messages.
  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
  while (usbMIDI.read()) {
    // ignore incoming messages
  }
}





void myControlChange(byte channel, byte control, byte value)  // for LEDs, MIDI output

{

 
}
 
If for any reason a sketch does confuse a Teensy and ability to talk to the host for programming, then the Program Button should always correct that.

Not sure about the code having any problem, though this looks odd and could be pelting the Host with unwanted Midi messages:
Code:
      previousA12 = n12;
      if (n12 < 3) n12 = 0;

As long as the tested n# value is out of range it will then send a 0 value to the host on each loop?

Not sure how MIDI works - does each message out get one back? If so then they may be piling up before the end of loop() where they are discarded?

To not send repeat zero values the test perhaps could look like - where the goal if properly typed - is to only send the ZERO value one time until the n# goes to an acceptable value. This would be needed for all such tests if it makes sense:
Code:
    if (n11 != previousA11 && (0 != previousA11 && n11 < 3)) {
      if (n11 < 3) n11 = 0;
      previousA11 = n11;
      usbMIDI.sendControlChange(controllerA11, n11, channel);
    }
 
Hi Defragster, thanks for the code. What I was trying to achieve in my code was to only send a new midi value if it changed, and if the value is below 3 it sends a 0. I won't be using the sensor in that low range, and that was just a safeguard to make sure it sends a 0 when the sensor is not activated.

I will try out your code and see how that works.

I think too many MIDI messages can cause a flood of data and potentially cause problems so it's probably best to filter out as much unnecessary info as possible. Thank you so much for taking a look.
 
Can test the logic with a USB Debug print in the OLD code as posted #14, just one at first, and seems you'll see it sending out '0' each loop() pass [some thousands or millions]

Then leave that in with the p#15 suggested logic and the '0' (or valid value) message should only go out once when the updated 'if()' logic is correct.
 
Hi I wanted to give an update. Defragster I tried to incorporate your bit of code, but the midi controller on that number would only output a 0, zero, so I went back to the code I put in #14.

I could get the new, problematic Teensy 4.1 to mount and I uploaded the code the that. It worked for a bit. If I unplugged it, it wouldn't mount, or take a minute to mount. It still seemed very buggy.

So I took a Teensy 4.1 I got last year, used in another project that has never been a problem. I uploaded the code to this Teensy and, at least for now, seems to work fine. Everytime I plug it in it mounts immediately. I think it's likely I damaged the other teensys somehow, or somehow the first code I put on them gave them some issues. For now my issue seems resolved. I ordered some new Teensy 4.1s so I can finish this project. My fingers are crossed that everything keeps working.
 
@nicnut - got back to give it another think ... might be right? If not the goal should be clear:

Send out valid change value once on change, or 'zero' when it goes invalid the first time.

Code:
    if ((n11 != previousA11 && n11 >= 3) || (0 != previousA11 && n11 < 3)) {
      if (n11 < 3) n11 = 0;
      previousA11 = n11;
      Serial.printf( "n11: val=%d ch#=%d\n", n11, channel);
      usbMIDI.sendControlChange(controllerA11, n11, channel);
    }
 
Hi defragster. Thanks for this bit of code. It seems to make sense to me. I'll try it out and see what happens. Thank you again.
 
Back
Top