Skip to content

Instantly share code, notes, and snippets.

@Pilooz
Last active November 5, 2019 09:53
Show Gist options
  • Save Pilooz/3422b1bc70f207838cebc4e631c471ad to your computer and use it in GitHub Desktop.
Save Pilooz/3422b1bc70f207838cebc4e631c471ad to your computer and use it in GitHub Desktop.
Serial communication between two arduinos

Sender (This is a Feather)

#include <Arduino.h>

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(115200);
  Serial1.begin(115200);
  pinMode(13, OUTPUT);
}

void loop() {
  // Serial.write(mystr,12); //Write the serial data
  if (Serial1.available()) { // Receive
    String readString = Serial1.readStringUntil('\n');
    Serial.println(readString);
  }
  else { // Send
    Serial1.print("Sent from Feather (millis) : ");
    Serial1.println(millis());
  }

  digitalWrite(13, !digitalRead(13));
  delay(1000);
}

Receiver (This a teensy 3.2)

#include <Arduino.h>

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(115200);
  Serial1.begin(115200);
  pinMode(13, OUTPUT);
  // The teensy is too fast to boot, let's slow it a little
  // to let enought time to Feather to boot too.
  delay(5000);
}

void loop() {
  // Serial.write(mystr,12); //Write the serial data
  if (Serial1.available()) { // Receive
    String readString = Serial1.readStringUntil('\n');
    Serial.println(readString);
  }
  else { // Send
    Serial1.print("Sent from Teensy (millis) : ");
    Serial1.println(millis());
  }

  digitalWrite(13, !digitalRead(13));
  delay(1000);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment