comparing data

hello fellow hackers
I have a problem I am trying to send radio data across 2 radio links.The connection is fine. Only thing is that i want the receiving end of the code to compare the signal thats coming in with the signal that was sent out.
I want to know how much the signals accuracy was affected by covering the radio links with different thing. I'm sending out abc...z(this could be any thing)then the receiving end might get some anomoles (like "abd...z")because of signal blocking.heres are the code i am using right now.

#include <SoftwareSerial.h>

//Radio receiver

#define rxPin 2
#define txPin 3

byte incomingByte = 0;

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);

void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
rfSerial.begin(2400);
Serial.begin(2400);
}

void loop() {
incomingByte = rfSerial.read();
Serial.println(incomingByte, DEC);
incomingByte = 0;
delay (500);
}

#include <SoftwareSerial.h>

//Radio Transmitter
#define rxPin 2
#define txPin 3

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
byte outgoingByte = 0;

void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
rfSerial.begin(2400);
Serial.begin(2400);
}

void loop() {
Serial.println(outgoingByte, DEC);
rfSerial.println(outgoingByte, BYTE);
outgoingByte++; //add 1 each time it loops untill it hits 255
delay(10);
}

Only thing is that i want the receiving end of the code to compare the signal thats coming in with the signal that was sent out.

How is the receiver to know what the sender sent? Unless you sent some additional information, like known start and stop characters, and a character count and check-sum, the receiver has no way of knowing whether what it received matches what the sender sent.

You could sent <26|abcdefghijklmnopqrstuvwxyz> and the receiver could receive <26|123def456jkl789pqr987vwx65> and still think everything received was what was sent.

Or, did I miss something?

sorry i didn't make that clearer the signal that is being sent out is a constant abc...z so the receiver knows that what its supposed to get is abc...z it would compare the incoming signal with that.I am doing this to figure out how much signal is blocked by different materials .

This is how I would do it

char good[] = {"abcdefghijklmnopqrstuvwxyz"};
byte index;

void setup()
{
   Serial.begin(9600); // Or whatever...
}

void loop()
{
   index = 0;
   while(Serial.available() && index < 26)
   {
       char aChar = Serial.read();
       if(aChar != good[index])
       {
           Serial.flush(); // Dump the rest of the pending data

           // Print out where the mismatch occurred
           Serial.print("Bad character received when index = ");
           Serial.println(index, DEC);

           // Print out what the mismatch is
           Serial.print("Received ");
           Serial.print(aChar);
           Serial.print(" instead of ");
           Serial.println(good[index]);

           // Get out of the while loop
           break;
        }
        index++; // Advance to the next good character
   }
}

wow thx ill try that right now :slight_smile:

i dont see any thing wrong with the code but all im getting is
Bad character received when index = and some boxes in there were the data is supposed to be .I dont know if its my transmitter or the receiver. For the transmiter i think that i am sending the info all at once would the recever keep that in a buffer untill its ready or is it flushed.

This is the receivers with the added code from above

#include <SoftwareSerial.h>

//Radio receiver
#define rxPin 2
#define txPin 3
char good[] = {"abcdefghijklmnopqrstuvwxyz"};
byte index;

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);

void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
rfSerial.begin(2400);
Serial.begin(2400);
}

void loop() {
index = 0;
while(Serial.available() && index < 26)
{
char aChar = Serial.read();
if(aChar != good[index])
{
Serial.flush(); // Dump the rest of the pending data

// Print out where the mismatch occurred
Serial.print("Bad character received when index = ");
Serial.println(index, DEC);

// Print out what the mismatch is
Serial.print("Received ");
Serial.print(aChar);
Serial.print(" instead of ");
Serial.println(good[index]);

// Get out of the while loop
break;
}
index++; // Advance to the next good character
}
}

this is may altered transmitting end

#include <SoftwareSerial.h>

//Radio Transmitter
#define rxPin 2
#define txPin 3
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
char good[] = {"abcdefghijklmnopqrstuvwxyz"};
byte index;

void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
rfSerial.begin(2400);
Serial.begin(2400);

}

void loop() {
index = 0;
Serial.print("abcdefghijklmnopqrstuvwxyz");
rfSerial.println("abcdefghijklmnopqrstuvwxyz");
index++; //add 1 each time it loops
delay(10);
}

Have you tried NewSoftSerial, instead of SoftwareSerial? Many issues were corrected in NewSoftSerial. I don't know whether they affect you, or not.