Serial Data Transfer Library Finished!

Status
Not open for further replies.

Power_Broker

Well-known member
As part of one of my personal projects, I decided to write a library to transfer UART serial data in a fast and reliable manner.

This library (SerialTransfer.h):
  • is non blocking
  • uses packet delimiters
  • uses consistent overhead byte stuffing
  • uses cyclic redundancy checksums
  • allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 255 bytes)

It can be found in the Arduino Library Manager (see attached screenshot) or at https://github.com/PowerBroker2/SerialTransfer

Here is an example set of Arduino sketches:

TX Arduino:
Code:
#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  myTransfer.txBuff[0] = 'h';
  myTransfer.txBuff[1] = 'i';
  myTransfer.txBuff[2] = '\n';
  
  myTransfer.sendData(3);
  delay(100);
}

RX Arduino:
Code:
#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  int8_t result = myTransfer.available();
  if(result == NEW_DATA)
  {
    Serial.println("New Data");
    for(byte i = 0; i < 3; i++)
      Serial.write(myTransfer.rxBuff[i]);
    Serial.println();
  }
  else if((result != NO_DATA) && (result != CONTINUE))
  {
    Serial.print("ERROR: ");
    Serial.println(result);
  }
}
screenshot.PNG
 
It looks like the library uses simple checksum instead of CRC?

Yep, looks like a simple checksum - no CCITT polynomial to be found. And it seems to be segmenting data inefficiently.

Checksums are ok, but less reliable than CRC.
 
Also, I updated the library a ton since originally posting this. One of the big updates is that I replaced the checksum portion with CRC-8 (polynomial 0x9B with a lookup table)
 
Recently finished writing the pip-installable Python package pySerialTransfer that is compatible with SerialTransfer.h. Now you can easily, quickly, and reliably communicate with Arduinos via Python!
 
Status
Not open for further replies.
Back
Top