My Teensy (3.1) outputs serial data but it can't be read by my arduino!

Hi,

This is my first time using the RX/TX pins on the Arduino and Teensy to try to read data coming from the Teensy. The code is hacky but only because I’m trying to test the water :smiley: .

I’m encountering a case where the Arduino will print out messages that I’ve typed into the Arduino’s Serial Monitor but it does not display messages that should be sent over the Teensy’s TX pin. I checked the teensy’s serial monitor and the message the teensy’s suppose to send over to the arduino via its TX pin is printed correctly into the teensy’s serial monitor.

Since I’m seeing messages in serial monitor for both devices, could it be that serial communication is occurring between each respective devices and their USB ports back to my computer, to be displayed on my serial monitor and not to each other?

Hardware setup is pretty simple:

  • Arduino connected to COM4
  • Teensy 3.1 connected to COM5
  • Arduino’s TX/RX connected to Teensy’s RX/TX, respectively.

The Teensy sends a message every second, indefinitely:

void setup() {
  Serial.begin(9600); // Teensy Serial obj. always communicates at 12Mbps
}

void loop() {
  Serial.write("x<Hello>asdf"); 
  delay(1000); 
}

The Arduino Uno checks its Serial Buffer and stores strings enclosed by the “<”, “>” characters e.g., “…” gets stored into a character array as “helloworld\0”.

#define LED_PIN 13
#define BUF_SIZE 100

char msg_Buf[BUF_SIZE];

void initPins(){
  pinMode(LED_PIN, OUTPUT); 
}

void clearMsgBuf(){
  int i;
  for(i=0; i<BUF_SIZE; i++)
    msg_Buf[i] = '\0';
}

int parseSerial(){
  char startMarker = '<'; 
  char endMarker = '>';
  char rc; 
  boolean startRead = 0;  
  int index = 0; 
  
  if(Serial.available() > 0){ //If there's stuff in serial 
    //Find start of msg using startMarker; if startMarker not found
    rc = Serial.read(); 
    while((rc != startMarker) && (Serial.available()>0)){ rc = Serial.read();}
    if(rc == startMarker){ startRead = 1;}
      else{ return 0;}

    //Start reading until '>' is encountered
    while((Serial.available()>0) && (startRead==1)){  
      rc = Serial.read(); //Reads byte from Serial buffer
      if(rc != endMarker){
        msg_Buf[index] = rc; 
        index++; 
      }else if(rc == endMarker){
        startRead = 0; //Stop reading
      }
    }
    msg_Buf[index] = '\0'; //Null terminate the msg array
    return 1; 
  } 
  return 0; //Nothing in serial.  
}//End parseSerial()

void setup(){
  initPins();
  Serial.begin(9600);
  Serial.println("==Arduino ready to receive Serial Input=="); 

}

void loop(){
  parseSerial(); 
  Serial.println(msg_Buf); 
  clearMsgBuf(); 
  
  delay(500); 
  Serial.println("..."); 
}

The Teensy 3.1 is a 3.3 volt device. Most Arduino boards are 5.0 volt devices. Connecting the five volt Arduino transmit pin to the three volt Teensy receive pin may damage the Teensy. Unless the receive pin is five volt tolerant. Is it?

The Uno uses the Rx and Tx pins when communicating with the PC (I don't know about the Teensy).

Try creating a SoftwareSerial port on your Uno so you can use two different pins to talk to the Teensy.

...R

I'll have to check the Teensy's datasheet. PaulStoffregen in this thread mentions that Digital/Analog Pins on the Teensy 3.1 are 5V tolerant. I'm guessing (without any justification) that he meant that any digital-capable pins are 5V tolerant but to be safe, I'm just going to use a voltage divider :expressionless: ...

Robin2:
The Uno uses the Rx and Tx pins when communicating with the PC (I don't know about the Teensy).

Try creating a SoftwareSerial port on your Uno so you can use two different pins to talk to the Teensy.

...R

I actually got the Teensy to communicate with the Arduino! After some experiments, I learned that both uC need to begin serial communication at the same baud rate and:

Serial.write() on the Teensy drives serial communication back through USB and to my Teensyduino IDE. SerialX.write() where 'X' = 1,2,3 (though I only tested with X=1), drives serial communication through the RX1/TX1 pins on my Teensy (which were connected to my Arduino's TX/RX pins, respectively).

Arduino only has 1 UART RX/TX pair, so Serial.write/read() writes to and reads from pins 0/1.

From http://www.pjrc.com/teensy/teensy31.html

All digital pins are 5 volt tolerant on Teensy 3.2 & 3.1. However, the analog-only pins (A10-A14), AREF, Program and Reset are 3.3V only.

But the Teensy 3.0 and LC are not 5V tolerant.

Pete

ElusivePi:
Arduino only has 1 UART RX/TX pair, so Serial.write/read() writes to and reads from pins 0/1.

That’s why I suggested SoftwareSerial.

…R