Basic Setup of RX/TX Serial Communication

I am trying to send serial data one way from a one arduino to a second one (master/slave setup). I have a few problems:

  1. What I gather from reading some of the other serial data posts is that arduino #1 rx connects to arduino #2 tx.....and #1 tx connects to #2 rx.
    I also assume they need to share a ground. Am I correct in this thinking or do they also need to share power?

  2. Also, I don't understand the code syntax to send serial data from #1 to #2 and how to receive that data in #2. I can read my pot input in #1, but then don't know how to send it.
    Do I need to designate
    int rxPin = 0;
    int txPin = 1;

and then in void setup()
void setup()
{
Serial.begin(9600); // ...set up the serial ouput in 0004 format
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
}
in my code? This seems logical to me, but I'm not sure.

  1. Lastly, do i send my pot data using the following syntax?
    Serial.print(dataFromPot);
    and how do i receive this in #2?

Seriously a simple thing, but can't find a tutorial to walk me through this step by step (hardware + software).
Thanks!!!!
Lynn

  1. What I gather from reading some of the other serial data posts is that arduino #1 rx connects to arduino #2 tx.....and #1 tx connects to #2 rx. I also assume they need to share a ground. Am I correct in this thinking

Correct. No need for power, but it could be convenient to share power - just depends on your scenario.

No need for all the pinMode() calls and so on - serial.begin() handles all of the for you.

  1. Lastly, do i send my pot data using the following syntax?
    Serial.print(dataFromPot);

That form of serial.print() results in an ASCII string representing that number being transmitted. That's great for some applications, but for direct consumption by another arduino it may be easier to send it in binary form so you don't have to convert it from ASCII back to binary. If the value was only one byte, you could send it with serial.print(mybyte, BYTE); and receive it with recbyte = serial.read(); Dealing with multiple bytes is similar, just a bit more complicated.

-j

awesome! thanks for the info. Now I am faced with reading the serial data transmitted from #1 arduino to the #2 arduino.

I am reading analog input from one and sending the data to the other.
#2 arduino needs to read the data in via int. But I get some crazy numbers. I can't seem to decode the ASCII chart.

I get the value I need via DEC if I print the following code on #1:

//Serial.println(ave);
Serial.print("dec = ");
Serial.println(ave, DEC); // print as an ASCII-encoded decimal

Serial.print("hex = ");
Serial.println(ave, HEX); // print as an ASCII-encoded hexadecimal

Serial.print("oct = ");
Serial.println(ave, OCT); // print as an ASCII-encoded octal

Serial.print("bin = ");
Serial.println(ave, BIN); // print as an ASCII-encoded binary

Serial.print("byte = ");
Serial.println(ave, BYTE); // print as a raw byte value

// delay 10 milliseconds before the next reading:
delay(10);

Yet when I send this to #2 the DEC value is not the same.

CODE:
if (Serial.available() > 0) {
// read the incoming byte:
inputVal = Serial.read();
//potVal = (int) inputVal;

// say what you got:
Serial.print("I received: ");
Serial.print("dec = ");
Serial.println(inputVal, DEC); // print as an ASCII-encoded decimal

Serial.print("hex = ");
Serial.println(inputVal, HEX); // print as an ASCII-encoded hexadecimal

Serial.print("oct = ");
Serial.println(inputVal, OCT); // print as an ASCII-encoded octal

Serial.print("bin = ");
Serial.println(inputVal, BIN); // print as an ASCII-encoded binary

Serial.print("byte = ");
Serial.println(inputVal, BYTE); // print as a raw byte value

// delay 10 milliseconds before the next reading:
delay(10);
}

VALUES RECEIVED:
I received: dec = 33
hex = 21
oct = 41
bin = 100001
byte = !
I received: dec = -85
hex = FFFFFFAB
oct = 37777777653
bin = 11111111111111111111111110101011
byte = «
I received: dec = -31
hex = FFFFFFE1
oct = 37777777741
bin = 11111111111111111111111111100001
byte = á

So lost with this! Any help I would be so greatful!
L

Yes that looks right.
Remember you are sending a number, it could be up to three bytes BUT you are only receiving a single byte and displaying that a number of ways.
Therefore what you receive is not what you send.