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

Thread: Serial Connection With Teensy 3.2 & Arduino Uno

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    7

    Serial Connection With Teensy 3.2 & Arduino Uno

    Hey,

    I can't find a definitive answer online as to how i correctly communicate from an Arduino Uno to a Teensy 3.2.

    I have been looking at https://create.arduino.cc/projecthub...-boards-d423e9 but cannot seem to get this to work with the teensy and arduino. I am aware that the serial on the teensy should be renamed to serial1 (correct me if i am wrong).

    Any help or links to tutorials would be much appreciated.

    Edd

  2. #2
    I didn't see sender code linked from that page - but it linked to this receiver code - with quick edits that should make it work.

    Assuming T_3.2 is the receiver with this untested code to Serial1 [ Tx pin 1 and Rx pin 0 and GROUND connected to proper pins on UNO, that is Rx goes to Tx in both directions ] - where the baud rate on .begin(9600) must match in both sketches:

    Code:
    int incomingByte = 0;   // for incoming serial data
    
    void setup() {
            Serial1.begin(9600);     // opens serial port, sets data rate to 9600 bps
    }
    
    void loop() {
    
            // send data only when you receive data:
            if (Serial1.available() > 0) {
                    // read the incoming byte:
                    incomingByte = Serial1.read();
    
                    // say what you got: echo out Serial1
                    Serial1.print("I received: ");
                    Serial1.println(incomingByte, DEC);
                    // say what you got: print out Teensy USB port
                    Serial.print("I received: ");
                    Serial.println(incomingByte, DEC);
            }
    }
    The "say what you got" part is left "Serial" to print out the T_3.2 USB type SERIAL port to the serial monitor on the PC. Though it could (also) Serial1.print() echo those two lines back out the same Serial1 port they came in on. <edit> updated to print to both ports Serial and Serial1

    <edit2>: on linked page scrolling down shows different receiver code than linked earlier - that lower code as shown won't give any outward indications it worked - just reads to a local variable.

    <edit3>: That is a very unhelpful example!
    >> And the sender code that is also lower has this: char mystr[3] = "Hello"; //String data
    To correctly hold the char string that should be char mystr[6] = "Hello"; //String data
    Last edited by defragster; 12-07-2017 at 10:37 AM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,943
    It should "just work" if you change all the Serial to Serial1 on the code for Teensy.

    But those 2 code samples on Arduino's site don't actually *do* anything, so how will you know if it's working? Defragster's code is better. But you can only run that on the Teensy side. If you want to transmit from Teensy to the Arduino Uno, you'll need to craft different code for Uno that actually *does* something you can observe to know if it's really working.

    The connections are identical to how that Arduino page describes. We get these questions pretty regularly, where it turns out the problem is some simple mistake in connecting the wires. If you're still having trouble, I'd highly recommend taking some photos to post here. We're pretty good at spotting these sorts of mistakes, if you show us photos of the actual wiring.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,943
    One more possible issue, the code on the web page has at least one very sloppy error.

    Code:
    char mystr[3] = "Hello"; //String data
    The array size needs to be at least 6 bytes, for the 5 characters plus a null terminator byte.

  5. #5
    Looks like Paul and I found the same issues - bad example indeed.

    If you put the linked provided Sender code on the UNO - with the indicated change to string length, it should be working and spitting out 'HELLO'.

    Then compile and upload posted code above for Teensy with 'Tools / USB Type "Serial" ' and then start the IDE SerMon with the USB cable connected to the Teensy. As above it will show progress out the USB port as it echos it back to the UNO.

    Once you have that working you may be on the way to bigger and better things.

  6. #6
    Moderator KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,145
    Also in cases like this it might help to see your wiring. That is do you have RX (UNO) -> TX1(Teensy) and TX(UNO) ->RX1(Teensy) and a ground wire.

    Also If I remember correctly on the UNO, the Serial port object talks to both the USB port as well as pins 0 and 1

  7. #7
    Moderator MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,548
    One thing to think of is that the Uno is a 5v system and the Teensy 3.x is a 3.3v system. Now, the Teensy 3.2 can tolerate 5v on the digital pins, but whether the Uno will notice 3.3v data bits might be a question. You might need to use a level shifter between the Uno and Teensy. Unlike i2c, you would only need a unidirectional shifting in each direction, but it may be simpler to get one of the bi-directional shifters, instead of getting separate 3.3v->5v and 5v->3.3v shifters. However, the bi-directional shifters have their own issues, and you might not be able to use the higher speeds.

    If you are doing high speed serial, you might need to use the RTS/CTS flow control pins, or use a lower speed.

    As KurtE notes, on the Uno (but not some of the later Arduino systems), the USB and serial ports are tied together.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,943
    Uno can receive 3.3V signals on its 5V pins.

  9. #9
    Junior Member
    Join Date
    Dec 2017
    Posts
    7
    Hey All,

    I have defragster's code on the Teensy and the serial monitor is throwing out the USB serial data just fine.

    I does not seem to be getting the serial data from the arduino.

    Any suggestions?

    Edd

  10. #10
    IIRC that sketch will only send to USB what is Received from the UNO - that shows the UNO is sending. Also the UNO sketch only sends to the Teensy - and does not read received input like the above sketch does.

    To see any feedback from the UNO it would need to have USB data displayed to SerMon and it would need to read it from the incoming serial pins - I'm not sure how that works with the UNO.

    You could modify the UNO Send sketch to print micros() - then you'd see more than the static string display.

    Hopefully that gets you somewhere?

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,943
    Quote Originally Posted by eddcaton View Post
    I have defragster's code on the Teensy and the serial monitor is throwing out the USB serial data just fine.

    I does not seem to be getting the serial data from the arduino.
    I'm confused. Defragster's code only transmits when it hears data (arriving on Serial1) from the Arduino. How could it be "throwing out the USB serial data just fine" if it's not hearing anything from the Arduino?

    Maybe I've just misunderstood what you've said?

    Any chance you could actually SHOW us what's happening, rather than telling? Screenshots and photos would be best.

  12. #12
    Moderator KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,145
    Also would again help to see actual picture of the setup. And see the current actual code

    It would maybe help me understand
    I have defragster's code on the Teensy and the serial monitor is throwing out the USB serial data just fine
    Is the Serial monitor hooked up to Teensy or UNO?

    If UNO and IF your code on the UNO is still
    Code:
    char mystr[6] = "Hello"; //String data
    
    void setup() {
      // Begin the Serial at 9600 Baud
      Serial.begin(9600);
    }
    
    void loop() {
      Serial.write(mystr,5); //Write the serial data
      delay(1000);
    }
    Note: Updates size of mystr...

    Everytime you do the Serial write. The "Hello" will print in the Serial monitor of the UNO.... And also should be sent out over the TTL pins...

Posting Permissions

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