The page on Using the Hardware Serial Ports is an excellent and comprehensive resource, which I strongly recommend students in my course go and visit when learning to do communications between Teensy's over a UART. The first thing that most of them do is try to run the example code on this page, to communicate between 2 Teensy's connected to different PCs.
Unfortunately, this example exhibits very counter-intuitive behaviour. Pressing one key on host machine A, causes Teensy A to emit a long string over its hardware serial port, to Teensy B. For each character that Teensy B receives over its hardware serial port, it then emits a long string to the Serial console on host machine B and sends another long string back to Teensy A, which emits further long strings on host machine A. The net result is that one key entered on host machine A causes hundred over characters to be displayed on host machines A and B. This is quite confusing, especially for weaker students.
I think this could be fixed simply, by replacing the lines:
with
and delete the following lines
This should lead to a much more expected behaviour that one button press leads to one character being displayed, and I think this would be helpful to any beginner Teensy user.
Thanks again for this great resource.
Unfortunately, this example exhibits very counter-intuitive behaviour. Pressing one key on host machine A, causes Teensy A to emit a long string over its hardware serial port, to Teensy B. For each character that Teensy B receives over its hardware serial port, it then emits a long string to the Serial console on host machine B and sends another long string back to Teensy A, which emits further long strings on host machine A. The net result is that one key entered on host machine A causes hundred over characters to be displayed on host machines A and B. This is quite confusing, especially for weaker students.
I think this could be fixed simply, by replacing the lines:
Code:
HWSERIAL.print("USB received:");
HWSERIAL.println(incomingByte, DEC);
with
Code:
HWSERIAL.write(incomingByte);
and delete the following lines
Code:
HWSERIAL.print("UART received:");
HWSERIAL.println(incomingByte, DEC);
This should lead to a much more expected behaviour that one button press leads to one character being displayed, and I think this would be helpful to any beginner Teensy user.
Thanks again for this great resource.