Hy Guys,
I have a KLP Module (transmitter/receiver) pair for sending and recieving bytes between two arduino boards. There was a lot of “noise” so i decided that I would send the same signal multiple times, and only concider it recieved if I recieved the same signal multiple times (I realize there are probably better ways of dooing this). The signals was going through with minimal loss and no noise, but ever 20th or so byte that I sent arrived completly wrong (ex, 1, 2, 3, 4, 5, 123, 6, 7) which led me to conclude that instead of the number 6 either the transmitter was sending 123 multiple times or the receiver was reading it incorrectly multiple times. I was reading other posts and I see that the receiver can take a couple of bytes to calibrate but in my expample im sending 9 and counting as recieved if i get 7 so I dont think this is my problem (at least not all of it).
Any idea what this might be/how I can solve it?
(I will also take suggestions on how to better ignore noise and make sure the signal goes through).
Using arduino decillima boards, code below (using their built in serial library):
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;
}
}
Receiver
// temp var for storing the byte from serial.read
int incomingByte = 0;
// stores the multiple input we are waiting for
int currentByte = 0;
// stores the number of times the same input has been seen
int numCurrentBytes = 0;
void setup(){
Serial.begin(2400);
}
void loop(){
if(Serial.available() > 0){
incomingByte = Serial.read();
if(currentByte == incomingByte)
{
numCurrentBytes++;
if(numCurrentBytes >= 7)
{
Serial.println(currentByte, DEC);
numCurrentBytes = 0;
}
}
else
{
numCurrentBytes = 1;
currentByte = incomingByte;
}
}
}