two arduinos communicating together??

anthony8i:
ok so how can I write a sketch that; say I have led13 on and on my main arduino and second arduino reads if its on or off? or how can I turn the ledpin13 on or of using a switch? gives 1 or 0 on my monitor and the second arduino reads that?

Have you got the switch turning on and off the LED on the first (main) Arduino yet? If not, that is your starting point.

File -> Examples -> Digital -> Button

Get that working.

Yeah I got all that working.. But really need help with a sketch? I need 4 LEDs light up with a switch, send that data to 2nd arduino to mirror that same data? Don't know how or where to really begin on how write the two sketches to upload to the arduinos? Thanks

Like I suggested, go do some things on the Learning page - figure how to read an input pin, output that to the serial monitor.
Then read 2-3-4 inputs, combine them into 1 data byte, show that.
Then send that byte to the other board, read it there and set the outputs high & low depending on the state of the bits.

CrossRoads:
Like I suggested, go do some things on the Learning page - figure how to read an input pin, output that to the serial monitor.
Then read 2-3-4 inputs, combine them into 1 data byte, show that.
Then send that byte to the other board, read it there and set the outputs high & low depending on the state of the bits.

thanks! Yeah I do get the concept but I really need an example? Where I can work around it? I'll keep working on it. I really need a way or example to hook the two arduinos and have them communicate? I'll keep trying! Thanks

PaulS:

byte LEDpin 13;

Missing an equal sign!

The supplied example sketch is wrong. I submitted a bug report #901.

http://code.google.com/p/arduino/issues/detail?id=901

(edit) Confused myself there. I withdraw the above comment.

anthony8i:
thanks! Yeah I do get the concept but I really need an example?

Here is the button example:

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Now add some sending:

const int buttonPin = 2;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
  
  // initialize serial
  Serial.begin (9600);
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // send to other Arduino
  Serial.print (buttonState);  
  
  // give it a chance to react
  delay (100);
}

Confirm in the serial monitor that you see 0 or 1 being sent.

Now look at one of the serial examples to read in the 0 or 1 and light up the LED on the other board appropriately.

hey thanks I will upload this to my aduino; but do up load this to both arduinos? and to send the data I just connect the TX to RX right?

Only the second sketch will send data. You will need to write your own "receiver" sketch for the other Arduino. Here is an example: http://arduino.cc/en/Serial/read

Yes, to connect them, you connect the RX and TX. Remember that you might have to disconnect the RX and TX wires when uploading new code.

orangeLearner:
Only the second sketch will send data. You will need to write your own "receiver" sketch for the other Arduino. Here is an example: http://arduino.cc/en/Serial/read

Yes, to connect them, you connect the RX and TX. Remember that you might have to disconnect the RX and TX wires when uploading new code.

yes I do need to disconnect the sending wires, so I need to up load both sketches to the main arduino; then upload the read sketch to my receiving arduino? if i upload the read sketch to my sencond arduino will it read the sketch from main arduino or do i need to change the read(); sketch? for it to work?

I uploade botch sketches into my main arduino and gives me errors?

When you upload a sketch to the Arduino, any old sketch that was on there will be deleted. The first sketch given was just an example of an LED and button. Try uploading it and understanding how it works before asking more questions.

The second sketch is an extension that adds serial communication, so you can open your serial monitor (the little magnifying glass in the upper right hand corner) and see whether the button is pressed.

Your computer is receiving the serial messages, but using the Serial.read() sketch, your other Arduino can receive the serial messages too. You should try one Arduino at a time connected to the computer with both the write and read sketches before you combine them together.

I uploade botch sketches into my main arduino and gives me errors?

Does it or doesn't it? Only you can answer that.

Learning when to use a ?, and when not to, would serve you well.

If you are seeing errors, it would be good of you to share them. Otherwise, we can only assume that it is operator error.

How about working through some of the examples before you do much more? You don't upload two sketches at once to one processor. One replaces the other.

Work your way through some of the tutorials. If you think we are going to sit here and just give you your homework packaged up and ready to go think again.

The whole idea here is that you learn something. So go back to the IDE, upload a blink sketch, see if it works. Then upload the sketch that reads the button and flashes the LED. Confirm it does that. Then upload the sketch I suggested that sends the button state out the serial monitor. Confirm it does that. Then look at writing a sketch for the second Arduino to receive the serial data.