Skip to content

An Arduino library to wrap multiple kind of serials.

Notifications You must be signed in to change notification settings

asukiaaa/SomeSerial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An Arduino library to wrap multiple kind of serials.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages