Hello,
I have recently been working with sending data from one Arduino Duemilanove to another using infrared transmission. I have the system transferring data but for some reason, the data is getting all hashed up. Here is the code:
Transmitter code
//generates 38kHz carrier wave on pin 9 and 10
//sends data via TX every 500ms
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
// Clear Timer on Compare Match (CTC) Mode
bitWrite(TCCR1A, WGM10, 0);
bitWrite(TCCR1A, WGM11, 0);
bitWrite(TCCR1B, WGM12, 1);
bitWrite(TCCR1B, WGM13, 0);
// Toggle OC1A and OC1B on Compare Match.
bitWrite(TCCR1A, COM1A0, 1);
bitWrite(TCCR1A, COM1A1, 0);
bitWrite(TCCR1A, COM1B0, 1);
bitWrite(TCCR1A, COM1B1, 0);
// No prescaling
bitWrite(TCCR1B, CS10, 1);
bitWrite(TCCR1B, CS11, 0);
bitWrite(TCCR1B, CS12, 0);
OCR1A = 210;
OCR1B = 210;
Serial.begin(2400);
}
void loop()
{
Serial.println("testing");
delay(500);
}
Receiver code:
void setup()
{
Serial.begin(2400);
pinMode(13, OUTPUT);
}
void loop()
{
// if incoming serial
if (Serial.available()) {
readSerial();
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(10);
}
void readSerial() {
char val = Serial.read();
Serial.print(val);
}
The code is open-source and was not written by me. It appears to function well. I'm not sure if the hashed data is due to hardware problems or code problems. Any help would be great.