2 problems

ian

Well-known member
Problem 1

I'm using Teensy 1.20, Arduino 1.0.6, on a W7 64bit machine with Audio library downloaded yesterday from PJRC

Yesterday I was playing with my Teensy3.1 & audio board. I compiled & loaded the PlaySynthMusic example & it worked nicely, however when I unplugged the Teensy USB cable & plugged it into another PC OR a USB PSU it wouldn't play. It will only play immediately after downloading to the Teensy. Unplugging & replugging to my 'host' PC causes the Teensy loader to run again (all by itself). This seems to happen with other programs too but I'd never noticed before.

I had a quick look at the code and can't see anything obvious to cause this, but I don't know what could. This brings me to:

Problem 2

I notice in the code:

//while (!Serial1) ; // wait for Arduino Serial Monitor

Is this commented out because it doesn't work? I've tried this in other programs & it doesn't work for me. I notice on Paul's site https://www.pjrc.com/teensy/td_download.html that there is a revision note for Version 1.13: 'Fix while(!Serial)' but it doesn't indicate what was fixed.

Can anyone confirm or provide advice?

Ian
 
When you plug Teensy into another PC, or simply 5V power, and you do NOT press the button, it's supposed to run whatever program you previously loaded. The very first time you plug a brand new Teensy in, the LED should blink, because we program it with the LED blink as part of the testing process here.

I don't know why your board is going into programming mode. The pushbutton and PROG pin would be the first places to check.


Regarding the commented out line, you do NOT want that. It will cause the code to sit and wait for the Arduino Serial Monitor window to be opened. It's commented out, because normally you do not want to have it just sit there and do nothing until you open that window. However, if you're trying to troubleshoot something in the code by printing stuff as it starts up, you might want to turn on by uncommenting that line.

But that line isn't related to the problem you're seeing. It exists for those cases where you want to modify the software and you need to enable a wait.

You're seeing something entirely different, as if something is going wrong with the PROG signal or pushbutton.
 
Clarification

Hi Paul,

I seem to have confused the issue by intoducing a second problem. To clarify:

Problem 1

The program DOES NOT run if Teensy is powered from another source. It only runs immediately after download. I'm not pressing the prog button at all. To check the prog button I've switched off 'Auto' on the Teensy loader & it switches itself back to Auto which might suggest a stuck button? However I've tried with 3 different Teensy 3.1s .(one fresh out of the packet) & they all do this.

Problem 2

I agree - this is a completely separate issue unrelated to the first. My point being that this doesn't work for me in ANY program.

Try this:

Code:
void setup()
{}

void loop()
{
  while(!Serial);
  delay (5000);
  Serial.println("Connected");
}

I can open & close the serial terminal all day & nothing is printed to it
NB in my OP it should be Serial & NOT Serial1

Cheers

Ian
 
Groan,

Problem 1 solved

My RTC battery was connected between Program & VBat thanks to a PCB fault :(

edit - as an afterthought I went back & checked my other 2 Teensys which now work auto/manual.
I'm thinking that Teensy loader is 'remembering' Program status between uses(?)

Ian
 
Last edited:
I can open & close the serial terminal all day & nothing is printed to it

Make sure you have the correct serial port selected in Tools > Serial Ports.

With Teensy unplugged, look at that menu. Then plug in Teensy and upload code. After the upload completes, look at Tools > Serial Ports. The freshly created port is the one for Teensy. Make sure that's selected. If you have the wrong one selected, you'll never see any data in the serial monitor.
 
Try this code:
Code:
char a;

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  while (!Serial)
  {
    if(Serial.available())
    {
      a=Serial.read();
      Serial.print(a);
    }
  }
  Serial.println("connected");
}

I can type in the terminal & have it echo back when (apparently) it isn't connected. I start up the terminal, type & it's echoed. It never exits the while(!Serial) loop.
Please tell me I'm not going daft - it's been quite a week...
 
Is it printing "connected"?

If not, how do you know you're communicating with Teensy and not some other device (like a modem in command mode) that simple echos characters?
 
Eh? No it isn't printing 'connected' that's my point
I've had a scout around and can't see any modems lurking under the desk ;) Indeed there are NO other USB devices apart from my printer.
I know that I'm talking to Teensy, just to prove it:

Code:
char a;

void setup()
{
  Serial.begin(9600);
  delay(5000); //time to enumerate
  Serial.println("This is teensy");  //this prints fine
}
void loop()
{
  while (!Serial)  //wait for serial to become available supposedly...
  {
    if(Serial.available())
    {
      a=Serial.read();  //this echoes everything I type
      Serial.print(a);
    }
  }
  Serial.println("connected");  //this never prints
}

I get the announcement from setup()
I can type into the terminal. What I type is echoed back.
But it never drops out of the while(!Serial) loop
 
I wouldn't expect it to not drop out, Serial tests true once, unless you unplugged the serial (which means you wouldn't see output) it should never go false. the fact you can see the echo text is great, but what makes you think Serial (the port is available) would go false?
 
I wouldn't expect it to not drop out, Serial tests true once, unless you unplugged the serial (which means you wouldn't see output) it should never go false. the fact you can see the echo text is great, but what makes you think Serial (the port is available) would go false?
Code:
 while([B][U]![/U][/B]Serial) {
    // Serial is false or OP would not claim to see the echoed characters (not using the code above at least)
  }
'Serial' is never true or OP would see 'connected' in terminal, it would repeat as the code calling loop() would be allowed to continue calling it repeatedly.

Correct me if I'm wrong OP but the result you seem to be getting is pretty contrary, right? ;)
 
my bad, When I tested the code example I get the intro and connected as you would expect. This does seem odd.
 
Ian, this is a really bizarre problem. I really do want to get to the bottom of it, but to do so I'm going to need you to run some more tests.

Internally, the "(!Serial)" code is looking at 2 variables. Here's the actual code, in usb_serial.h on line 89:

https://github.com/PaulStoffregen/cores/blob/master/teensy3/usb_serial.h#L89

You should be able to access those 2 special C variables in your program. For example:

Code:
void loop()
{
  while (!Serial)  //wait for serial to become available supposedly...
  {
    if(Serial.available())
    {
      a=Serial.read();  //this echoes everything I type
      Serial.print(a);
    }
    Serial.printf("usb_configuration = %d\r\n", (int)usb_configuration);
    Serial.printf("usb_cdc_line_rtsdtr = %d\r\n", (int)usb_cdc_line_rtsdtr);
    delay(100);
  }
  Serial.println("connected");  //this never prints
}

My guess is your Windows 7 machine is not assigning the CDC line state correctly. Maybe? If so, why would be a huge mystery. Then again, if usb_configuation is still zero, well, that would be an even bigger mystery!

Please run this and let me know what the actual numbers are for those 2 variable when used with your computer?
 
Also, I really need to ask, are you using the Arduino Serial Monitor, or some other software to view the data?

Is there anything else possibly out of the ordinary with how you're viewing the incoming serial communication? Small details could matter, especially for trying to come up with a way to detect and fix this issue in future software versions.
 
Paul, sorry I've taken so long with this. TOO busy just now:(
I'm using the Arduino terminal. I don't think I'm doing anything odd...
This is what your code generates

This is teensy
usb_configuration = 1
usb_cdc_line_rtsdtr = 0

I tried connecting with Putty & bingo! It works exactly as it should!
I put my dunces cap on & thought about this - YES I am doing something! I use bluetooth on ALL of my PCs which seems to cripple Arduino :(
I use an alternative 'rxtxSerial.dll' to circumvent this, see: http://www.johngineer.com/blog/?p=97
I'm guessing this is the problem??!!
 
I use an alternative 'rxtxSerial.dll' to circumvent this, see: http://www.johngineer.com/blog/?p=97
I'm guessing this is the problem??!!

Oh, well that's certainly a new piece of information!

Since this conversation, the Arduino devs (finally) released Arduino 1.6.0. I'm working on Teensyduino support for it. The first beta should be available in a couple days.

Arduino 1.6.0 has switched from RXTX to JSSC. Supposedly it's better. It's certainly new and probably different.

Maybe in a week or so (after Teensy support is available for it) you could give 1.6.0 a try? I'd be really curious to hear if JSSC works better?
 
I'm ready for something that works reliably for strings in the serial monitor. Half the time I get this, when I hit my first entry to the Monitor (Teensy 3.1 Arduino 1.0.5 W7 64 bit)
java.io.IOException: Input/output error in writeArray
at gnu.io.RXTXPort.writeArray(Native Method)
at gnu.io.RXTXPort$SerialOutputStream.write(RXTXPort.java:1124)
at processing.app.Serial.write(Serial.java:526)
at processing.app.Serial.write(Serial.java:549)
at processing.app.SerialMonitor.send(SerialMonitor.java:203)
at processing.app.SerialMonitor.access$100(SerialMonitor.java:35)
at processing.app.SerialMonitor$4.actionPerformed(SerialMonitor.java:99)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
Code:
void setup()
{
  Serial.begin(9600);  // open serial port to host
  while (!Serial.available()) { // wait for COM port ready (user opens Monitor and presses send)
    delay(10);
  } 
  while (Serial.available()) {Serial.read();} // Eat whatever typed first
  Serial.print("LEDSign ");
  Serial.print(VERSION);
  ...
 
Back
Top