How to use TX and RX pins on Arduino Duemilanove

Hi I have a simple question, and I have spent more than 3 hours searching this with no result.. I want to send data from UNO arduino to Duemilanove Arduino, but it is not working!! I am using wires as the following: UNO TX > Duemilanove RX UNO RX > Duemilanove TX

this is my sketch for the sender (Uno Arduino)

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.print("ON");
  delay(1000);
  
  Serial.print("OF");
  delay(1000);
}

and this is the receiver sketch (Duemilanove )

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

void loop(){
  if(Serial.available() > 0){
    digitalWrite(13,HIGH);
    delay(100);
    Serial.flush();
  }
  else {
    digitalWrite(13,LOW);
  }
}

any advice ??

You DO realize that you can't use the Rx & Tx pins on the UNO as a HOST because they are tied to the USB via the FTDI chip. (AFAIK). I think you need a second serial port, like Software Serial.

Accroding to the reference page: flush() Description: Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)

If you are using >= Arduino 1.0 on your Duemilanove, then I assume the light remains on, because the Serial buffer never gets emptied. Try replacing the flush() with

while(Serial.available() { Serial.read(); }

Dear TRex
I have tried your solution but with no result.

Dear raschemmel
I have tried to use Software serial, and I have connected uno pin 10 > duemi pin 11
and uno pin 11 > duemi pin 10 (and tried to switch the pins too).
I have tried the following code but with NO result !!

Sender

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  mySerial.begin(9600);
}

void loop()
{
  mySerial.print("ON");
  delay(1000);
  
  mySerial.print("OF");
  delay(1000);
}

Receiver

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup(){
  mySerial.begin(9600);
}

void loop(){ 
  while(mySerial.available() > 0){ 
    mySerial.write(mySerial.read());
  }
}

any thing to do??

Let's go back to your first two sketches. The transmitter sends "ON", "Of",... The receiver waits for serial data, any serial data, and upon receiving serial data digtalWrites 13 HIGH, and some other stuff. Don't have a delay in the receiver part -and- In the receiver sketch, you should be examining this received data - to determine a course of action (which you are not.)

raschemmel: You DO realize that you can't use the Rx & Tx pins on the UNO as a HOST because they are tied to the USB via the FTDI chip. (AFAIK). I think you need a second serial port, like Software Serial.

One can use the Rx and Tx pins to send and receive to an external serial device (like another arduino) as long as there is no application on the PC responding to anything sent to it and sending anything back to the arduino. It just gets problematic when one needs to upload a new sketch where usually you have to disconnect the external wiring on the Rx and Tx pins.

thanks all for your response but nothing has worked so far, I can use the same code to send from uno to uno with no problem. but I cant use the sketch for uno > Duemilanove

any suggestion on any help?

You need to connect the GND from UNO to Duemilanove. Do you have this?

Dear luisilva no I havent done that, I will try it and let you know

on the Duemilanove, if you have that attached to your PC, you can debut it yourself by just adding characters into the serial monitor.

but there is a problem in your code… Serial.flush (as was pointed out) does not do what you believe it to do there.

you need to process (consume) the entries as you receive them, and I broke that down into a single character entered in this example you can load onto your arduino…

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

void loop(){
  if(Serial.available() > 0)
  {
    char myChar = Serial.read();
    Serial.print("Wow, I just got an: ");
    Serial.println(myChar);
    if (myChar == 'N') digitalWrite(13,HIGH);
    else digitalWrite(13,LOW);
  }
}

if you like that… then modify the master… and connect the two crossing TX/RX pins

void setup()
{
  Serial.begin(9600);
}

void loop(){
  Serial.print("N");
  delay(1000);
  
  Serial.print("0");
  delay(1000);
}

edit made a paste booboo

hamzehhirzallah:
nothing has worked so far, I can use the same code to send from uno to uno with no problem.
but I cant use the sketch for uno > Duemilanove

luisilva:
You need to connect the GND from UNO to Duemilanove. Do you have this?

hamzehhirzallah:
Dear luisilva
no I havent done that, I will try it and let you know

There’s a profound contradiction afoot here.
I don’t think that “the sketch” is doing what you think it is and there are other issues as well.