Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: choosing a serial port on the Teensy 3.6?

  1. #1
    Junior Member
    Join Date
    Feb 2017
    Location
    Borrego Springs, CA
    Posts
    3

    choosing a serial port on the Teensy 3.6?

    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

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,134
    you mean 6 serial ports. check the teensy card the pins are listed there

  3. #3
    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.

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,367

    Cool

    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 by MichaelMeissner; 04-04-2017 at 05:57 AM.

  5. #5
    Junior Member
    Join Date
    Feb 2017
    Location
    Borrego Springs, CA
    Posts
    3
    Thank you. The exact syntax was eluding me. I appreciate the point about using 1 and 2 for the interrupt.
    Johnny Why

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,808
    For the syntax, look at the example code in File > Examples > Teensy > Serial.

  7. #7
    Junior Member
    Join Date
    Mar 2019
    Posts
    18
    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);
    }

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,808
    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.

  9. #9
    Junior Member
    Join Date
    Mar 2019
    Posts
    18
    Thank you for your reply. I would like to redirect you to my actual question neing asked on this forum here in the thread. https://forum.pjrc.com/threads/55342...937#post199937. Let continue in this thread.

    Thank you
    -Rakeh

  10. #10
    Administrator Paul's Avatar
    Join Date
    Oct 2012
    Posts
    342
    closing this thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •