-1

i need to use another serial to send data from arduino teensy to processing because default serial (Serial.begin(9600)) already used for big program

i try to read some reference about how maybe i can change from which serial i want to receive (https://processing.org/reference/libraries/serial/Serial.html), but i dont think it can be change

void setup() {
  Serial.begin(115200); // already used 
  Serial2.begin(9600); // processing
}
void loop() {
  Serial.println("...") //big code that i am not allow to change
  Serial2.println("hello world");
  delay(1000);
}

i expected to get "hello world" in my processing repeatly, but i really dont have any idea how to write the code so i can get value from Serial2 instead from Serial

  • 4
    which version of Teensy are you using ? How are you connecting to [Serial2](https://www.pjrc.com/teensy/td_uart.html) pins ? If `Serial` is wired to the USB, do you have a second USB Serial converter to receive data from `Serial2`'s `TX` pin in Processing ? – George Profenza Jul 08 '19 at 21:27

1 Answers1

0

It depends on what Teensy module you are using and how you're doing the wiring.

Please see the Teensy Using the Hardware Serial Ports article for more details.

If possible I'd try their UART/USB example:

// set this to the hardware serial port you wish to use
#define HWSERIAL Serial1

void setup() {
    Serial.begin(9600);
        HWSERIAL.begin(9600);
}

void loop() {
        int incomingByte;

    if (Serial.available() > 0) {
        incomingByte = Serial.read();
        Serial.print("USB received: ");
        Serial.println(incomingByte, DEC);
                HWSERIAL.print("USB received:");
                HWSERIAL.println(incomingByte, DEC);
    }
    if (HWSERIAL.available() > 0) {
        incomingByte = HWSERIAL.read();
        Serial.print("UART received: ");
        Serial.println(incomingByte, DEC);
                HWSERIAL.print("UART received:");
                HWSERIAL.println(incomingByte, DEC);
    }
}

If that hows with the same USB connection at the same time, negotiate with your colleague so you get to use the easier one that simply shows up as another Serial port in Processing.

If that is not an option:

  1. double check the pinout the Serial Ports article above but also the logic level voltage (e.g. might be 3.3V, not 5V)
  2. get a USB Serial converter (for the right logic level) - this will show up as a different Serial port using Processing's Serial.list()
  3. connect Serial2's TX pin to the convertor's RX pin and read the data in Processing (similar to process to how you'd read Serial, just a different port name)
George Profenza
  • 50,687
  • 19
  • 144
  • 218