Giter Site home page Giter Site logo

customsoftwareserial's Introduction

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 value
void setup() {
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.write("Hello World");

  customSerial = new CustomSoftwareSerial(9, 10); // rx, tx
  customSerial->begin(9600, CSERIAL_8N1);         // Baud rate: 9600, configuration: CSERIAL_8N1
  customSerial->write("Test message");            // Write testing data
}

void loop() {
  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:

Name Number of data bits Parity bit Number of stop bit
CSERIAL_5N1 5 None 1
CSERIAL_6N1 6 None 1
CSERIAL_7N1 7 None 1
CSERIAL_8N1 8 None 1
CSERIAL_5N2 5 None 2
CSERIAL_6N2 6 None 2
CSERIAL_7N2 7 None 2
CSERIAL_8N2 8 None 2
CSERIAL_5O1 5 Odd 1
CSERIAL_6O1 6 Odd 1
CSERIAL_7O1 7 Odd 1
CSERIAL_8O1 8 Odd 1
CSERIAL_5O2 5 Odd 2
CSERIAL_6O2 6 Odd 2
CSERIAL_7O2 7 Odd 2
CSERIAL_8O2 8 Odd 2
CSERIAL_5E1 5 Even 1
CSERIAL_6E1 6 Even 1
CSERIAL_7E1 7 Even 1
CSERIAL_8E1 8 Even 1
CSERIAL_5E2 5 Even 2
CSERIAL_6E2 6 Even 2
CSERIAL_7E2 7 Even 2
CSERIAL_8E2 8 Even 2

Testing

Test Configuration

Testing demo to test configuration's values

#include <CustomSoftwareSerial.h>

CustomSoftwareSerial* customSerial;

void setup() {
  Serial.begin(9600);
  
  Serial.println("**** DEFAULT ****");
  customSerial = new CustomSoftwareSerial(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();  
}

void loop() {
  
}

void printPort() {
  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) {
    case NONE:
      parityText = "None";
      break;
    case ODD:
      parityText = "Odd";
      break;
    case EVEN:
      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

customsoftwareserial's People

Contributors

glynhudson avatar ledongthuc avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

customsoftwareserial's Issues

To delay even parity bit without

507 writeParityBits(numberOfBits1);
508 tunedDelay(_tx_delay);
↓↓↓↓↓↓↓↓↓↓
507 writeParityBits(numberOfBits1);
508 if(this->_parityBit != NONE) {
509 tunedDelay(_tx_delay);
510 }

problem with myserial->readBytes

Greetings, the problem I have is that in the connection to 9600 bit 7 even parity, it does not capture the data correctly, if you could help me with that, I would be grateful.

Garbage @ 115200

First of all, I wanted to thank you for the library, very helpful. It is unbelievable that Arduino has so many constraints in terms of communication.

Right now, I'm using your library, but I'm having troubles with the baudrate. I can only have good data a 9600 bps. Changing to 115200 everything is just garbage. Unfortunately, my application does not allow something less that 115200 bps. In order to test the library, I did the following program. The following code uses the default pins (0,1) to transmit the word "Hello world". But I only get reliable data at 9600. Any answer will be much appreciated it.

#include <CustomSoftwareSerial.h>
CustomSoftwareSerial* customSerial;               // Declare serial
CustomSoftwareSerial* customSerial1;


//#include <SoftwareSerial.h>
#include <stdint.h>

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

unsigned int read_val=0;
void setup() 
{
  //Serial.begin(115200);
  while (!Serial) 
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  delay(10);

  customSerial = new CustomSoftwareSerial(10, 11); // rx, tx
  customSerial1 = new CustomSoftwareSerial(0, 1); // rx, tx
  customSerial1->begin(14400, CSERIAL_8N1);
  customSerial->begin(115200, CSERIAL_8N1);         // Baud rate: 9600, configuration: CSERIAL_8N1

  //portOne.begin(115200);
  delay(1000);
  //portOne.print(50,HEX);
  customSerial->print(50,HEX);
  customSerial1->print("Hello world");
}

void loop()
{
  while(true)
  {

    if (customSerial->available()) 
    {  
        read_val=customSerial->read();
        Serial.println(read_val);
        //Serial.println("Hello");  
     }  
   }  
 }

modbus and customSoftwareSerial

Hi
wanted to use this with Modbus

but got an error

Did I miss anything:

C:\Users\xxx\Documents\Arduino\libraries\ModbusMaster\src/ModbusMaster.h:74:10: note: candidate: void ModbusMaster::begin(uint8_t, Stream&) void begin(uint8_t, Stream &serial); ^~~~~ C:\Users\xxx\Documents\Arduino\libraries\ModbusMaster\src/ModbusMaster.h:74:10: note: no known conversion for argument 2 from 'CustomSoftwareSerial*' to 'Stream&' exit status 1 no matching function for call to 'ModbusMaster::begin(int, CustomSoftwareSerial*&)'

defined:
SoftSer1->begin(9600, SERIAL_8N2); //custom software serial node.begin(1, SoftSer1);
Error:
`Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

...error: no matching function for call to 'ModbusMaster::begin(int, CustomSoftwareSerial*&)'

node.begin(1, SoftSer1);

C:\Users\xxx\Documents\Arduino\libraries\ModbusMaster\src/ModbusMaster.h:74:10: note: candidate: void ModbusMaster::begin(uint8_t, Stream&)

 void begin(uint8_t, Stream &serial);

      ^~~~~

C:\Users\xxx\Documents\Arduino\libraries\ModbusMaster\src/ModbusMaster.h:74:10: note: no known conversion for argument 2 from 'CustomSoftwareSerial*' to 'Stream&'

exit status 1

no matching function for call to 'ModbusMaster::begin(int, CustomSoftwareSerial*&)'

`

missing .Listen

Missing .Listen function. SoftwareSerial use this to handle 2 ports. With customSoftwareSerial i cant use with 2 ports. can you help? what is to do?

Unknown code...

Hi
this variable is never used: uint8_t maxValueOfData
look at: CustomSoftwareSerial.cpp, Row:477:11
uint8_t maxValueOfData = round(pow(2, this->_numberOfDataBit - 1));
Thanks & Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.