Hey Guys,
I have a KLP Module (transmitter/receiver) pair for sending and recieving bytes between two arduino boards. After filtering out the noise, most of what I receive is great, but every once in a while (20th or so byte) instead of receiving the expected byte I get a different one. Without going into details this byte comes in at the expected time and passes the noise filter (for the sake of this post lets assume its correct but the code is below). This means that the transmitter is sending the wrong number or the reviever is getting the wrong number. Do you know why this could be?
If it helps the noise filter is just two steps. First the transmitter sends 9 coppies of the same byte, then if the reveiver gets 7 of the same byte in a row (except 0) then it counts as correct, there are not very many lost bytes but some of them are getting replaced with the wrong number. This probaby means that either the transmitter is sending the wrong number 9 times, or when the receiver gets the number it is interpreting it the same wrong way every time.
Any Ideas?
Pooh
Transmitter
byte counter;
byte count;
unsigned long time;
void setup(){
Serial.begin(2400);
counter = 0;
count = 0;
time = millis() + 100;
}
void loop(){
if(millis() > time)
{
count = 0;
while(count < 9)
{
Serial.print(counter);
count++;
}
counter++;
time = millis() + 100;
}
//delay(2000);
}
Receiver
int incomingByte = 0;
// stores the multiple input we are waiting for
int currentByte = 0;
// stores the number of multiple inputs
int numCurrentBytes = 0;
void setup(){
Serial.begin(2400);
}
void loop(){
if(Serial.available() > 0){
incomingByte = Serial.read();
if(currentByte == incomingByte && incomingByte != 0)
{
numCurrentBytes++;
if(numCurrentBytes >= 7)
{
Serial.println(currentByte, DEC);
numCurrentBytes = 0;
}
}
else
{
numCurrentBytes = 1;
currentByte = incomingByte;
}
}
}