Paul, Prof,
I do not know if my RPi3 (running the latest 2019-04-08 release) and Teensy (3.6) problem is the same as you describe above but I believe I'm experiencing a similar issue when trying to communicate over the USB (connected as /dev/ttyACM0).
To test the connection I used a very simple Arduino sketch:
Code:
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello World");
delay(1000);
}
When viewing the output using the Serial Monitor I receive:
Code:
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
At which point the Monitor no longer outputs text and, although able to immediately respond to a the “Clear Output” button, takes approximately 20 seconds to close the window.
If, however, I physically unplug the Teensy and re-insert it while the Monitor is running then “Hello World” is printed once a second, ad infinitum, as I’d expect.
After seeing this correct behaviour in the Serial Monitor I am then able to execute the following C code, and it outputs the data correct to the console:
Code:
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
int main(void){
int fd, rdlen, counter = 20;
struct termios options;
char buffer[100];
if ((fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY))<0)
{
fprintf(stderr, "open() failed: %s\n",strerror(errno));
return EXIT_FAILURE;
}
if (tcgetattr(fd, &options)<0)
{
fprintf(stderr, "tcgetattr() failed: %s\n", strerror(errno));
return EXIT_FAILURE;
}
cfmakeraw(&options);
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CRTSCTS;
options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 2;
if (tcsetattr(fd, TCSANOW, &options)<0)
{
fprintf(stderr, "tcsetattr() failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
do
{
memset(buffer, 0, sizeof(buffer));
rdlen = read(fd, buffer, sizeof(buffer));
if (rdlen>0)
{
printf("Read: %s\n", buffer);
counter--;
}
} while (counter);
close(fd);
return EXIT_SUCCESS;
}
However, if I try running the same executable directly after a reboot then I find the same odd behaviour displayed by the Serial Monitor (before physically disconnecting and reconnecting the Teensy). Specifically, it provides a few lines of text output but then the executable hangs:
Code:
pi@raspberrypi:~ $ ./serial_port_test
Read: Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Read: Hello World
Hello World
Hello World
I also find similar behaviour when using the cat or screen commands.
I’m new to POSIX and Teensy coding so please forgive me if I’ve missed something obvious. 
Some of the things I’ve tried so far:
- No other components are connected to the Teensy
- Made sure to use cfmakeraw() when setting the serial options
- Made sure the user pi was in the dialup group
- Made sure the udev rules were the latest from pjrc.com and were copied to the correct folder
- Tried chmod to give access directly to /dev/ttyACM0
- Used stty with various settings (including sane, raw, -iexten, -echo, -echoe, -echok, -echoctl, -echoke, -onlcr and “min 1”)
Prof, have you been able to achieve any progress in overcoming these problems that you’ be willing to share?