Arduino error detection by PARITY check

Hello people...
I am learning programming of arduino and I wanted to know how to implement the parity error detection of my recieved text from another arduino transmitter.

I am using lifi in which uses light blinking to transmit 1 & 0 bits through light to another reciever arduino...

So, how I can come to know weather the recieved bits are all correctly recieved by using parity error detection?

Below is code which enables me to write anything in between a start byte of < nd stop byte of > at serial port of transmitter and then sends it to reciever on which serial port I see the sent data....

TRANSMITTER CODE:

char x;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}

void loop() {
 if(Serial.available()>0)
{
   x=Serial.read();
   Serial1.print(x); 
}}
RECIEVER CODE:

const byte numChars = 15;
char receivedChars[numChars];

boolean newData = false;

void setup() {
    Serial3.begin(9600);
    Serial.begin(9600);
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
    while (Serial3.available() > 0 && newData == false) {
        rc = Serial3.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

You would have to implement that yourself. You need to decide on the parity you want (odd/even) and have the transmitter make sure that it does that. The receiver checks to make sure the parity is as expected and then accepts the byte received. This requires an additional bit per byte. If you are using a library to send/receive, you might not be able to do it unless it supports it.

An alternative might be to calculate some sort of checksum over an entire message you transmit and have the receiver check that.

Parity is worthless. Use a CRC.

In what sense -- having no real value or use?

GolamMostafa:
In what sense -- having no real value or use?

In the sense that, despite being a trivial effort, it is not worth the time and effort to implement.

blh64:
You would have to implement that yourself. You need to decide on the parity you want (odd/even) and have the transmitter make sure that it does that. The receiver checks to make sure the parity is as expected and then accepts the byte received. This requires an additional bit per byte. If you are using a library to send/receive, you might not be able to do it unless it supports it.

An alternative might be to calculate some sort of checksum over an entire message you transmit and have the receiver check that.

Plz guide me how to do checksum then...how to calculate or generate checksum?
Actually as I am sending bytes of text from 1 serial port to another serial port of another arduino I want to know how to apply checksum on it?

However you want to implement it. I would suggest you google "arduino checksum algorithm" and leverage all the work others have done. Whatever is easy for you to understand and implement

Perhaps the simplest kind of checksum to implement would be a, well, check_sum_: just add up the bytes (of course, treating each byte as its numerical value: a number from 0 to 255), and use the result as the checksum.

@OP

It appears from your original post that your are receiving text message over UART Port which is asynchronous serial protocol, and it supports only 'parity bit' for data validity check. You may choose one of the following options for 'parity' check bit; but, you have to write codes yourself to take advantage of it.

Serial.begin(speed, config)

Parameters

Serial: serial port object. 

speed: in bits per second (baud) - long

config: sets data, parity, and stop bits. Valid values are

SERIAL_8N1  (the default: 8 data bits, no parity, 1 stop bit)
SERIAL_8E1  (8 data bits, even parity, 1 stop bit)
SERIAL_8O1  (8 data bits, odd parity, 1 stop bit)

Example

Serial.begin(9600, SERIAl_8E1);

GolamMostafa:
@OP

It appears from your original post that your are receiving text message over UART Port which is asynchronous serial protocol, and it supports only 'parity bit' for data validity check. You may choose one of the following options for 'parity' check bit; but, you have to write codes yourself to take advantage of it.

Serial.begin(speed, config)

Parameters

Serial: serial port object. 

speed: in bits per second (baud) - long

config: sets data, parity, and stop bits. Valid values are

SERIAL_8N1  (the default: 8 data bits, no parity, 1 stop bit)
SERIAL_8E1  (8 data bits, even parity, 1 stop bit)
SERIAL_8O1  (8 data bits, odd parity, 1 stop bit)




**Example**


Serial.begin(9600, SERIAl_8E1);

Thnx I will try to implement it meanwhile any other advices from u all will be appreciated...