Skip to content

Latest commit

 

History

History
124 lines (89 loc) · 2.74 KB

README.md

File metadata and controls

124 lines (89 loc) · 2.74 KB

SomeSerial Build Status

An Arduino library to wrap multiple kinds of serials.

Before using this library, consider using Stream class to handle multiple kinds of serials.

#include <SoftwareSerial.h>

SoftwareSerial softSerial(10, 11); // RX, TX

void printStream(Stream* serial) {
  serial->print("hi at ");
  serial->println(millis());
}

void setup() {
  Serial.begin(115200);
  softSerial->begin(115200);
}

void loop() {
  printStream(&Serial);
  printStream(&softSerial);
  delay(1000);
}

Usage

Include

#include "SomeSerial.h"

Definition

USB Serial or HardwareSerial

For popular Arduino family.

SomeSerial someSerial(&Serial);

For official Arduino SAMD boards. (SAMD boards by Adafruit use Serial.)

SomeSerial someSerial(&SerialUSB);

SoftwareSerial

SomeSerial someSerial(10, 11); // RX, TX

or

SoftwareSerial mySoftwareSerial(10, 11); //RX, TX
SomeSerial someSerial(&mySoftwareSerial);

Be careful that not all pins support SofwareSerial.

Please check or test whether using pins for SoftwareSerial work or not.

SoftwareSerial

ArduinoProducts

ARM and ESP32 does not support SoftwareSerial.

Use like Serial

void setup() {
  someSerial.begin(115200);
}

void loop() {
  someSerial.println("Hello world!");
  delay(1000);
}

As HardwareSerial

if (someSerial->isHardwareSerial()) {
  someSerial->println("It is HardwareSerial");
  someSerial->thisHardwareSerial->println("Direct print to HardwareSerial");

}

As SoftwareSerial

if (someSerial->isSoftwareSerial()) {
  someSerial->println("It is SoftwareSerial");
  someSerial->thisSoftwareSerial->println("Direct print to SoftwareSerial");
}

As USBAPI Serial_

if (someSerial->isSerial_()) {
  someSerial->println("It is USBAPI Serial_");
  someSerial->thisSerial_->println("Direct print to USBAPI Serial_");
}

License

MIT

References