Serial Communications not working at all

I have 2 XIAOs TX to RX, RX to TX and grounds connected and can’t get them to communicate via serial.

SENDING XIAO CODE

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

void loop() {
Serial.write(5); // send a byte with the value 5

int bytesSent = Serial.write(“hi”); //send the string “hi” and return the length of the string.
}

RECIEVING XIAO CODE

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
// reply only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);

}
}

Any suggestions?

I think the default Serial port goes via USB.
Have you tried with Serial1 ?

Thank you I’ll give that a try, I thought I had read that serial1 doesn’t work on XIAO.

First of all, I would test with one XIAO: Connect a jumper between Pin 6 (Tx) and Pin 7 (Rx)
Then use the Arduino Serial Monitor to show the action

This simplest test might go something like this:

// Demo of Serial1 pins on Seeed XIAO
//
// davekw7x
// May, 2022
//
void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  
  // Wait for both serial ports to be ready
  while (!Serial) ;
  while (!Serial1);
  
  Serial.println("\nXIAO Test of Serial1 compiled on " __DATE__ " at " __TIME__ "\n");
  Serial.println("Connect a jumper between pins 6 and 7 of the XIAO,");
  Serial.println("and type some characters in the Serial Monitor\n\n");
} // End of setup()

void loop() {
  char serial_input;
  char serial_1_input;

  // Read from Serial port (USB), write to Serial1 Tx (XIAO Pin 6)
  if (Serial.available()) {
    serial_input = Serial.read();
    Serial1.print(serial_input);
  }

  // Read from Serial1 Rx (XIAO Pin 7), write to Serial port (USB)
  if (Serial1.available()) {
    serial_1_input = Serial1.read();
    Serial.print(serial_1_input);
  }
} // End of loop

(Tested on my XIAO — works as expected)

Once you can verify that, in spite of what you may have read somewhere, the Serial1 port on XIAO pins 6 and 7 works, you can try with two devices.

With the same software on both devices and Tx-Rx cross connected between them, I might use the Arduino Serial Monitor on one and a terminal emulator on a computer USB port for the other. (I use Tera Term on Windows, minicom on Linux.)

Regards,

Dave

Serial1Test

Thanks so much! I will post what I learn Monday.

Tested and is now working flawlessly. THANK YOU! I flashed the same code on two XIAOs and they communicate as well with the wiring shown in the pic my first post.

1 Like

If this is not working then try something from My Signal Boosters