Go Down

Topic: Making two boards talk (Read 483 times) previous topic - next topic

D0Cdet

Hello, I've been trying to make two Diecimila boards talk to once another over serial.

I've written a simple script for the board that transmits. It simply counts up to 1,000 and loops.
The script on the receiver board is supposed to look for the number 200, and blink pin 13.

However, it's pretty buggy, and I'm not sure what's wrong.

I have TX from the transmit board going to RX in the receive board.
It transmits, however, pin 13 on the receiver end lights everytime it receives a number

Any help would be greatly appreciated.


Transmit code:

void setup() {
 //2400 baud for the 434 model
 Serial.begin(2400);
}
void loop(){
   for (int i=100; i< 1000; i=i+100) {
     Serial.print(i, DEC);
     Serial.print("\t");
     delay(1000);
   }
}


Receive code:

int incomingByte = 0;
int ledPin = 13;

void setup() {
 //2400 baud for the 434 model
 Serial.begin(2400);
}
void loop(){
 incomingByte = Serial.read();

 if (incomingByte == 200) {
   pinMode(ledPin, OUTPUT);  
   digitalWrite(ledPin, HIGH);   // sets the LED on
   delay(1000);                  // waits for a second
   digitalWrite(ledPin, LOW);    // sets the LED off
   delay(1000);                  // waits for a second

 }
 incomingByte = 0;
}




Thanks in advance!

Cheater

Your sending human numbers but the receiving end is expecting computer numbers. :)

Best to make it count from 0 to 255 and remove the DEC from the serial print line.
Also remove the \t (optional - it doesnt matter). Then it should work correctly.

D0Cdet

Thanks for your help.

I tried what you said but it didn't work.

I'm wondering if I have to specify if the numbers are text?

Go Up