choosing a serial port on the Teensy 3.6?

Status
Not open for further replies.

Johnny Why

New member
How do I choose between the 3 serial ports on the Teensy 3.6?
I want to use TX2 and RX2 but can not find specifics on have to select that as an option.
J
 
There are pre-defined objects for each serial port. Serial.print prints to the USB serial port. To print to TX1/Rx1, use Serial1.print. For TX2/RX2, use Serial2.print. Similarly up through Serial6 on the 3.6.

Don't forget to call Serial2.begin with the correct baud rate.
 
Serial1 and Serial2 have hardware FIFO queues (first in, first out) that help reduce the requirements that the Teensy be ready to accept an interrupt when a character is available. If you expect to receive a lot of input, you want to use those two serial ports. The other 4 serial ports do not have the FIFOs, and so won't be able to be receive input as fast.

In addition if the hardware you are connecting to the Teensy supports RTS (request to send) and CTS (clear to send), you want to use that. Trasnmit enable, RTS. and CTS are hardware flow control bits that controls the flow of data if the Teensy cannot process it fast enough. Note, Serial4 does not support using CTS.

For each serial device the pins for receive, transmit, and CTS are fixed. RTS and transmit enable can be any digital pin. Serial1 can have alternate pins for receive, transmit, and CTS (but these pins are fixed also). You can get more information from this page:

So for Serial2, pin 9 is receive, pin 10 is transmit, and pin 14 is CTS. Note, that the Teensy only transmits voltage at 3.3v. This means if the device is expecting 5v, it may or may not see the 3.3v signal. The Teensy 3.6 is NOT 5v tolerant, so you must make sure that voltages coming to the Teensy 3.6 are 3.3v, via level shifting if the voltages are not 3.3v.

Depending on how the device is documented, you typically would connect the RX pin of the Teensy to the TX pin of the device, and TX pin of the Teensy to the RX pin of the device. But some devices try to be 'helpful', and their RX/TX pins are swapped, so you would connect RX->RX and TX->TX.

Even if your device is powered separately, you will need to make sure the Teensy and the device share a common ground.
 
Last edited:
Thank you. The exact syntax was eluding me. I appreciate the point about using 1 and 2 for the interrupt.
Johnny Why
 
Hey, responding to this thread might solve my problem as it is somehow same. I want to use Serial1/Serial2 for my IMU sensor data but its not showing anything on the serial. I have tried with ArduinoUNO and works fine but is causing some trouble with teensy3.6.
Its not even simply printing the data on serial.
For reference, below is my code. Thank you

Code:
#define LED 13

void setup()
{
  Serial1.begin(9600);
  while(!Serial1)
  {
    ;
  }
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}

void loop()
{
  int num = 1234;
  delay(2000);
  Serial1.print("Press any key to continue...");
  while (Serial1.available())
  {
    Serial1.read();
    }
    while (!Serial1.available());
    Serial1.println("Hello");
    Serial1.println(num, DEC);
}
 
On Uno, you get only Serial. It's both pins 0 & 1, and the connection to your PC.

On Teensy, Serial connects to your PC over USB, but it has nothing to do with pins 0 & 1. On Teensy, Serial1 goes to pins 0 & 1 and does nothing with the USB port. Unlike Uno where you get only one Serial that talks to both, on Teensy they are separate. This is good if you want to control them both. But it also means you do need to use the correct names.

Your question doesn't tell us much about what you've actually connected to the hardware and what you're actually trying to do. But this line, together with "not even simply printing the data on serial" makes this line stand out:

Code:
  Serial1.print("Press any key to continue...");

It you're expecting this to show up in the Arduino Serial Monitor, you need this (using Serial rather than Serial1).

Code:
  Serial.print("Press any key to continue...");

Likewise, if your code is waiting for data from the USB port, you would use Serial.available(). Using Serial1.available() will wait for a byte to arrive on pin 0, which is separate from bytes arriving on the USB cable.
 
Status
Not open for further replies.
Back
Top