Serial Issue with Teensy

Status
Not open for further replies.

bhobbs

Member
This is a long shot, but I've been looking everywhere for a solution and can't seem to find it. I'm having intermittent issues with my Teensy 3.2 board holding a stable serial connection with my mac.

It's been happening with all the code I try to use. It isn't just limited to one set of code. It's also happening on two Teensy 3.2 boards. HOWEVER, I have a Chipkit Max32 and it's serial communication is running just fine.

So here's the test I've been using:

Code:
void setup() {
  Serial.begin(9600);
  delay(2000);
  Serial.println("welcome");

}
int i = 0;
void loop() {
  i++;
  Serial.println(i);
  delay(10);
}

It's a simple bit of code that counts up and sends it over serial. Chipkit, works fine. Looks like this:

1
2
3
4
5
6
7
8
9
10
....

But the Teensy boards' output is very jumpy and look like this:

1
5
12
13
18
20

I have swapped out the usb cables, boards, and used different serial software on my mac. Same results. Chipkit fine, teensy dropping the signal

I don't know where the source of this could be coming from. Wondering if you guys have any advice or know of any known issues with macs. I am running the newest version of El Capitan 10.11.4. And I am running Arduino 1.6.6
 
Last edited:
<EDIT>: Cross post - or it could be a known bug . . . Looks like it was expected to be fixed ... do you have TeensyDuino ver 1.26 or later?
Version 1.26
Add support for Arduino 1.6.6
Fix USB Serial on Macintosh 10.11 El Capitan

Note: you are compiling with :: Tools / USB TYPE / Serial right. This is then Serial communications over USB.

No MAC experience here - but the delay(10) might be a bit fast [not if all is working right of course] - perhaps see if it stabilizes for a longer time with a delay(100);

If that works maybe add a longer print in loop() like: Serial.println(" welcome back - count with me . . . ");

BTW: Code is easier to read and CUT/PASTE when wrapped like: code.PNG
 
Last edited:
You shouldn't need a delay(10); as the USB protocol stalls the function if the host is not ready to receive it. This is pretty unique to the Teensy 3.x though
 
So the delay(10); is relatively arbitrary. I tried delay(1000) and it's the same. When I originally discovered this problem, I was actually trying to implement CmdMessenger. When I couldn't get it to consistently work, I tried a few other simpler serial messaging libraries, until I decided to try my writing a custom solution. That's the point that I noticed that my serial commands weren't consistently making it from teensy->mac, so I wrote this little counting script as a way to test it on my only other board, the ChipKit.
 
I have access to a Mac with 10.11.2. I'll see if I can get it upgraded to the latest. Then I can try looking into this...
 
Can you please check which version of Teensyduino is installed? Use the Arduino > About menu to check.

Teensyduino 1.28

And I also just booted linux on my same computer, and the serial is working fine with it. Which rules out some sort of hardware problem on my computer.
 
I have a few updates.

Firstly, I should note that I'm not getting tty options in arduino (for any port, including chipkit max32).

Number 2, most interesting, TyQt serial works perfectly with the teensy all the time. I'll hop over to Arduino or CoolTerm and it will be jumpy again. It also only lists cu under the interfaces (I just started using it, idk if that's of significance).

Number 3, PySerial. It's giving me interesting results. It'll allow me to start connecting via cu, but then give me an error when I try to get it to readline(). And it will say resource busy with tty.

Code:
>>> ser = serial.Serial('/dev/cu.usbmodem1507781',9600)
>>> while True:
...     print ser.readline()
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "build/bdist.macosx-10.11-intel/egg/serial/serialposix.py", line 495, in read
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
>>> ser = serial.Serial('/dev/tty.usbmodem1507781',9600)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.11-intel/egg/serial/serialutil.py", line 180, in __init__
  File "build/bdist.macosx-10.11-intel/egg/serial/serialposix.py", line 294, in open
serial.serialutil.SerialException: [Errno 16] could not open port /dev/tty.usbmodem1507781: [Errno 16] Resource busy: '/dev/tty.usbmodem1507781'

It says resource busy for TTY. Even though nothing is connected to it.
 
TYQT is awesome - I always mention it in my posts - except for this one it seems. I've found the IDE SerMon to be fitful and lacking in the last few updates so happily use TYQT.

Nice to see the CODE wrapper - and I see 1.28 is the Teensy software answer. Did you confirm you are not compiling as RAWHID? As RAWHID it won't show a COM port - but that wouldn't explain chipkit.
 
Yea, I am compiling Serial.

I can remember past projects where I didn't have any problems with serial with the same computer, software, and arduino. In fact, the beginning of this project just a few months ago, I used rapid serial communication to tune some settings. I'm assuming the only difference would be the most recent mac update.

I find it really odd that Arduino's Serial, CoolTerm, SerialTools, and PySerial all experience the same glitch with Teensy (but not with Chipkit) and yet TYQT doesn't have the problem at all. Clearly the answer to this lies in the difference of how TYQT does serial vs the others.

Thoughts?
 
Set as USB type: Serial - cool.

TYQT isn't magic - but if it works - your hardware is working, and it is doing something right perhaps the others are not. It is under active development - with focus on working as it does. In fact I have to head over to the TYQT thread now as there is now a context menu applied at some effort that was missing so Teensy naming is more intuitive.

If TYQT is working - use it - At times like these having TYQT makes Teensy better as debugging and seeing/trusting the output is otherwise difficult. It handles multiple online units as individuals and many other things the IDE doesn't support.

TYQT is awesome for raw speed and utility as I've found it ... Koromix uses some refined native code for USB serial, and it wasn't so fast months back and he gave it it's own thread to keep up with the Teensy running closer to 1MByte/sec you can effectively get on USB (it can go higher but the OS/HUB etc may be a limiting factor). The IDE uses JAVA which isn't as well refined and buffers fill and consume RAM with aborted heaps of garbage it seemed - and PySerial can work fast another poster found - but without some proper tuning or whatever he did - it was fitful. I used another commercial product and it was awful at keeping up with a Teensy - also putty/teraterm presented issues in usage. - formatting and otherwise - Not what you are seeing but just to say that TYQT has good and unique code - as I've seen it on Windows.
 
On my MacBook Pro 13" (early 2011) running OSX 10.11.5 beta, the serial output is correct in all serial monitors, be it in the Arduino IDE (1.6.5), in the Eclipse Arduino IDE, or on TyQt.
 
here on 10.11.5 (MacBook Pro (Retina, Mid 2012)) with a teensy-LC i experience this:
(Arduino 1.6.9 and Teensduino 1.29-beta3)

- uploading the sketch after plugging the teensy to usb: serial output dropping bytes
- uploading the sketch again usually produces smooth serial output. probably without data-loss
- uploading it a third time did _sometimes_ cause the original problem again
- uploading it after this output is usually fine

ok. just tried the sequence again (above sequence was same a couple of times).
now the first-time upload after plugging it in was fine, but the third-time uploading it produced chunky output.

...
 
I tested this today on an iMac running El Capitan 10.11.5, running the sketch in msg #1 and viewing with the Arduino Serial Monitor.

I was unable to reproduce the problem. Here's a screenshot:

sc.png

Edit: just to be clear, I uploaded several times. Every attempt showed the same results in the serial monitor. I never saw even once a missing number. Each time, I looked only at the first 30 numbers (auto-scroll disabled).
 
Last edited:
hm. seems hardware dependent then.

first time upload just worked, the second time i uploaded it missed numbers:

Screen Shot 2016-07-10 at 10.15.01.jpg

is there something i can try?
some changes in the code to get some details about the problem?
 
I'm experiencing the same symptoms on my Mac. Tried with Teensyduino 1.37 Arduino 1.8.3, then uninstalled and tried with 1.6.9.

//CODE HERE
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Serial.begin(9600);
}

void loop() {
digitalWrite(13, HIGH);
Serial.print("Hello: ");
Serial.println(millis());
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
// END CODE

And getting results like this
Hello: 78856
Hello: 82856
Hello: 100856
Hello: 138857
Hello: 158857


I've tried using different usb cables and different chips (3.2 and 3.5).
Using OS X 10.10.5 Macbook Pro Retina, 15-inch Mid 2014

Here's the bogus part, I was able to get the serial port to function normally when I used parallels.

I'm able to read on the mac using TYQT, however using any other program, I still get sporadic data.
 
Last edited:
Hey. So I was able to fix it. For other reasons I had to wipe my mac clean and start over. That fixed it and I installed most of the software I had before just fine. I think (bc of time machine) my Mac had the soul of a 10 yr old computer. As a healthy new spry computer, it works great. And it solved a whole slew of other performance and battery issues I was having.
 
I tried deleting and then reinstalling all my arduino and teensy libraries with no luck. Any idea what other libraries I could try to reinstall? Not afraid to go in there with a chainsaw :p
 
That's really odd. I don't use a Mac but it's hard to believe its USB-serial could be so broken. If TyQt works, that's a solution. It's all I use now.

This is not your problem but I always set up my serial monitor port like this. Over USB baud rate doesn't really mean anything, it runs as quickly as it can, so I always set it to the max common speed of 115 kbaud. And always put a wait with timeout since it takes a few hundreds of msec typically for the serial port to be ready for use.
Code:
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  // Wait here for up to 10 seconds to see if we will use Serial Monitor, so output is not lost
  while((!Serial) && (millis()<10000));    // wait until serial monitor is open or timeout,
Oddly I just found a test program where I forgot to call Serial.begin(baud) and it made no difference.
This led me to look into what Serial.begin() does.
Apparently there is no Serial class; it's HardwareSerial.
or Teensy HardwareSerial and looking at this it is surprising that serial comms would work without the call to begin() as it sets up transmit and receive buffers.
 
Apple had some pretty serious driver bugs with El Capitan.

Fortunately, everything seems to be fixed in the latest Sierra.
 
Had this problem for a long time but just used rawHID plus Arduino Serial monitor for debugging. I've finally updated to Sierra (10.12.6) and was excited that this would be gone but the problem is the same. Deleted arduino and teensyduino and preferences.txt (was causing problems after the update for some reason) and reinstalled latest. Also dealt with the problem discussed in https://forum.pjrc.com/threads/44403-MacOS-Sierra-port-problem that crops up for me once in while.

It works fine once in a while but usually not. Same behaviour with Teensy 3.1, 3.2, 3.5, and 3.6. Any ideas or am I an anomaly?
 
Status
Not open for further replies.
Back
Top