Skip to content

Latest commit

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

CustomSoftwareSerial

Built with WeBuild

Alternative SoftwareSerial in Arduino. CustomSoftwareSerial library allow you configure and custom parity bit, stop bits and number of data bits. Hope it useful for you.

You can download from v1.0.tar.gz or v1.0.zip

Install

After downloading the package, follow step in http://www.arduino.cc/en/guide/libraries

Quick tutorial

Simple demo to use CustomSoftwareSerial

#include<CustomSoftwareSerial.h>
CustomSoftwareSerial* customSerial; // Declare serial// Init valuevoidsetup() {
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.write("Hello World");
customSerial = newCustomSoftwareSerial(9, 10); // rx, tx
customSerial->begin(9600, CSERIAL_8N1); // Baud rate: 9600, configuration: CSERIAL_8N1
customSerial->write("Test message"); // Write testing data
}
voidloop() {
if (customSerial->available())
Serial.write(customSerial->read());
if (Serial.available())
customSerial->write(Serial.read());
delay(1000);
}

Supported Configuration

We support configurations to setup stop bit, parity bit and number of data bits:

NameNumber of data bitsParity bitNumber of stop bit
CSERIAL_5N15None1
CSERIAL_6N16None1
CSERIAL_7N17None1
CSERIAL_8N18None1
CSERIAL_5N25None2
CSERIAL_6N26None2
CSERIAL_7N27None2
CSERIAL_8N28None2
CSERIAL_5O15Odd1
CSERIAL_6O16Odd1
CSERIAL_7O17Odd1
CSERIAL_8O18Odd1
CSERIAL_5O25Odd2
CSERIAL_6O26Odd2
CSERIAL_7O27Odd2
CSERIAL_8O28Odd2
CSERIAL_5E15Even1
CSERIAL_6E16Even1
CSERIAL_7E17Even1
CSERIAL_8E18Even1
CSERIAL_5E25Even2
CSERIAL_6E26Even2
CSERIAL_7E27Even2
CSERIAL_8E28Even2

Testing

Test Configuration

Testing demo to test configuration's values

#include<CustomSoftwareSerial.h>
CustomSoftwareSerial* customSerial;
voidsetup() {
Serial.begin(9600);
Serial.println("**** DEFAULT ****");
customSerial = newCustomSoftwareSerial(9, 10);
printPort();
Serial.println("**** CSERIAL_5N1 ****");
customSerial->begin(1200, CSERIAL_5N1);
printPort();
Serial.println("**** CSERIAL_6N1 ****");
customSerial->begin(1200, CSERIAL_6N1);
printPort();
Serial.println("**** CSERIAL_7N1 ****");
customSerial->begin(1200, CSERIAL_7N1);
printPort();
Serial.println("**** CSERIAL_8N1 ****");
customSerial->begin(1200, CSERIAL_8N1);
printPort();
Serial.println("**** CSERIAL_5N2 ****");
customSerial->begin(1200, CSERIAL_5N2);
printPort();
Serial.println("**** CSERIAL_6N2 ****");
customSerial->begin(1200, CSERIAL_6N2);
printPort();
Serial.println("**** CSERIAL_7N2 ****");
customSerial->begin(1200, CSERIAL_7N2);
printPort();
Serial.println("**** CSERIAL_8N2 ****");
customSerial->begin(1200, CSERIAL_8N2);
printPort();
Serial.println("**** CSERIAL_5O1 ****");
customSerial->begin(1200, CSERIAL_5O1);
printPort();
Serial.println("**** CSERIAL_6O1 ****");
customSerial->begin(1200, CSERIAL_6O1);
printPort();
Serial.println("**** CSERIAL_7O1 ****");
customSerial->begin(1200, CSERIAL_7O1);
printPort();
Serial.println("**** CSERIAL_8O1 ****");
customSerial->begin(1200, CSERIAL_8O1);
printPort();
Serial.println("**** CSERIAL_5O2 ****");
customSerial->begin(1200, CSERIAL_5O2);
printPort();
Serial.println("**** CSERIAL_6O2 ****");
customSerial->begin(1200, CSERIAL_6O2);
printPort();
Serial.println("**** CSERIAL_7O2 ****");
customSerial->begin(1200, CSERIAL_7O2);
printPort();
Serial.println("**** CSERIAL_8O2 ****");
customSerial->begin(1200, CSERIAL_8O2);
printPort();
Serial.println("**** CSERIAL_5E1 ****");
customSerial->begin(1200, CSERIAL_8O2);
printPort();
Serial.println("**** CSERIAL_6E1 ****");
customSerial->begin(1200, CSERIAL_6E1);
printPort();
Serial.println("**** CSERIAL_7E1 ****");
customSerial->begin(1200, CSERIAL_7E1);
printPort();
Serial.println("**** CSERIAL_8E1 ****");
customSerial->begin(1200, CSERIAL_8E1);
printPort();
Serial.println("**** CSERIAL_5E2 ****");
customSerial->begin(1200, CSERIAL_5E2);
printPort();
Serial.println("**** CSERIAL_6E2 ****");
customSerial->begin(1200, CSERIAL_6E2);
printPort();
Serial.println("**** CSERIAL_7E2 ****");
customSerial->begin(1200, CSERIAL_7E2);
printPort();
Serial.println("**** CSERIAL_8E2 ****");
customSerial->begin(1200, CSERIAL_8E2);
printPort(); }
voidloop() {
}
voidprintPort() {
Serial.println("Port's information of CustomSoftwareSerial");
Serial.print("- Number of data bit: ");
Serial.println(customSerial->getNumberOfDataBit());
Parity parity = customSerial->getParity();
char* parityText;
switch(parity) {
caseNONE:
parityText = "None";
break;
caseODD:
parityText = "Odd";
break;
caseEVEN:
parityText = "Even";
break;
}
Serial.print("- Parity bit: ");
Serial.println(parityText);
Serial.print("- Number of stop bit: ");
Serial.println(customSerial->getNumberOfStopBit());
Serial.println("");
}

Little story

A sunny day, I implement an library to control BLE HM-10 module through serial port but I recognize the Arduino's SoftwareSerial doesn't support parity bit. The stop bit only support one. So, I create and share this project for someone who need it.

If you got any problem or question, let me know. Thanks

About

Alternative SoftwareSerial in Arduino. CustomSoftwareSerial library allow to configure and custom Parity Bit and Stop Bit.

Resources

Stars

68 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages