Arduino to Arduino Serial Communication

How do I get started on Arduino to Arduino Serial Communication?

I'm working on a larger scale project, but first, I need the Arduinos to communicate over serial ports.

Right now I'm just trying to blink an LED, but failing miserably. The cords are connecting RX -> TX, TX->RX, and grounds are connected. An LED is in pin 13 of board 2.

My code:

Board 1: void setup() { Serial.begin(9600); }

void loop() { Serial.print(1); delay(2000); Serial.print(2); delay(2000); }


Board 2

define LED 13

int c = 0;

void setup() { pinMode(LED, OUTPUT); Serial.begin(9600); }

void loop()

{ if(Serial.available()) { c = Serial.read(); }

if(c == 1) { digitalWrite(LED, HIGH); }

if(c == 2) { digitalWrite(LED, LOW); } }

By default Serial.print() prints a string representation of the parameter. So Serial.print(1) will actually print the character '1'.

In Board 2 try replacing the line:

if (c==1)

with:

if (c=='1')

And similarly for the second case.

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

The LED blinks very briefly, but I don't know if that is related to the program or not. Also, do you have to connect the boards to an external power source for this to work or can I leave them connected to my laptop? (One of them, anyways. My external power source is being faulty).

And, any tutorials for more advanced Serial communication (or even just basic really) would be very appreciated.

I'm very new to Arduino and very, very new to Serial Communication, so bear with me please. :)

Thank you!

Thank you the LED is blinking now.

However, the LED is off for 2 seconds, on for 2 seconds, then blinks off once very quickly and on again very quickly before repeating the cycle.

Any suggestions?

Very simple serial led on/off code.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

void setup() {
    Serial.begin(9600);
        pinMode(13, OUTPUT);
        Serial.println("serial blink 0021"); // so I can keep track of what is loaded
        }

void loop()
{
  while (Serial.available() > 0){
    char c = Serial.read();
    if (c == '1') digitalWrite(13, HIGH);
    if (c == '0') digitalWrite(13, LOW);
  }
}

Thank you.

However, my computer won't let me view the serial monitor if the RX/TX pins are attached.

In place. Each other. How I described in the first post :)

However, my computer won't let me view the serial monitor if the RX/TX pins are attached.

Is your computer mad at you? Otherwise that doesn't make much scense.