Uno to Uno serial (Tx to Rx) not receiving / has noise on the signal?

Hi there,
We're eventually writing code that will send numbers down a wire and use them to do stuff with, but for now, we're just testing the serial connection from one Uno to another. We have the Tx Uno loaded with simple code to simply send out a number, and the Rx Uno loaded with simple code to receive that number and print it on the Serial Monitor. The two Unos are connected only with one wire from Tx on the sending unit to Rx on the receive unit. No shared ground (they will be 50 feet apart eventually, so we didn't assume we had to connect them). So here's what is happening: we send only the number 170 across the wire, and on the receive Serial Monitor screen it shows a 170 very infrequently, but for the most part shows a bunch of random numbers from 1 to maybe 150 or slightly higher. So for example you might get these numbers on the Serial Monitor in the course of a half second: 12 35 101 87 45 170 72 41 29 112

The code I've seen in examples doesn't all have delays, and I haven't seen anything telling me we have to have shared ground, but inserting a wire from GND on one board to GND on the other didn't have an effect. I'll list the Send code first, and then the Receive code. Any help would be greatly appreciated.

Send Code:

int SerialTest = 170;

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

void loop() {

Serial.print("I am sending this number: ");
Serial.println(SerialTest);

Serial.write(SerialTest);

delay(5);

}

Receive Code:

int SerialReceive = 0;

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

void loop() {

Serial.print("My receive variable has this value: ");
Serial.println(SerialReceive);

if (Serial.available() > 0) {
SerialReceive = Serial.read();
}

delay(5);

}

(deleted)

Okay, so here's what we get at the Receive end (see picture). I changed the code to send 177 instead of 170. So it's getting a 177 SOME of the time. Is something about Serial.read that needs to be configured somehow? Nobody ever writes anything about that, so we're stumped.

Serial.print("I am sending this number: ");
  Serial.println(SerialTest);

  Serial.write(SerialTest);

what are you trying to receive?
Why send SerialTest as ASCII and binary?

No shared ground (they will be 50 feet apart eventually, so we didn't assume we had to connect them)

Well, then you won't be able to communicate. You must share the ground signal between the two Arduinos. Digital ground (GND) is a reference. Without the reference, the two Arduino boards will not be able to communicate.

(deleted)

As to the shared ground, as I mentioned, we have connected the PWM grounds and the Digital grounds, to no avail.

The whole problem is the fact that we're getting so many different values at the Receive end, instead of just the 177. It shows up every now and then, as you can see in the picture, but not usefully. Where are the other values coming from? If the GNDs are connected and the boards have a wire from Tx to Rx, I can't see what else there is to connect. The Tx light on the Send unit is on, but the Rx light on the Receive unit is not lighting up at all - just the Tx light (on the Receive unit, which has nothing connected to the Tx pin). Is that because the Receive unit is sending to its serial monitor through the USB cable? We have the two boards reading serial monitors on separate computers.

In any case, not sure what to do to get a clean signal sent out of Tx on one end. It's a four-inch wire. It can't possibly be losing voltage or data.

Could the fact that the two boards are connected to different computers with their USB cables be un-syncing the Grounds or something?

Very confused.

(deleted)

Re: AWOL's post/question - we are trying to send motor controls to an ESC, which needs numbers between 1100 and 1900 to run (1500 is off), so in order to keep it small (fit in a byte), we're translating the numbers 1100-1900 into numbers from 110-190, then sending them, then multiplying them by 10 again at the bottom. But first we have to actually get the numbers from 110-190 able to be transmitted from one board to the other. I have attached the setup - we connected both the power GND and the Digital PWM GND, for good measure. Should it be a different connection?

Okay, so my understanding of serial.print was that it sent to the serial monitor, not out the Tx pin. Isn't that what serial.write() does? If they both send out the Tx pin, then how are they different? In any case, thanks for the idea. I'll give it a shot and see what happens on the Receive end.

(deleted)

Sorry: picture was just barely too large. Here's our setup



Moderator edit: image inlined

50 feet is too much for TTL level serial communication. You will need RS232 signals instead of TTL.

If you need both PC and other Arduino communication, you need a software serial setup or use an Arduino with more means for serial communication (e.g. Mega or Leonardo). On the Uno, TX and RX are also used for communication with the TTL-to-USB chip on the Uno that communicates with the PC.

We have a pair of serial-to-RS232 converters for increasing the usable distance down the wire from 25/30 feet to 1200 feet, so that will likely be fine.

The main point is that it now works! Thanks so much to everyone who contributed their thoughts and ideas, especially the sample code, which I guess simplified the send so much that it became readable. Here is what works now, using a joystick for input and sending it to the Mega, which can now read all of the serial inputs it gets, without other weird numbers (presumably created by serial.print commands being read as bytes or whatever).

Sending Arduino code:
const int analogInPinY1 = A1; // analog input pin from joystick Y coordinate/axis

int sensorValueY1 = 0; // value read from the joystick

byte serialOutY1 = 100; // value to send to bottom side servo

void setup() {

// initialize serial communications at 9600 bps:
Serial.begin(9600);

}

void loop() {

// get an analog input from the Y coordinate of the joystick
sensorValueY1 = analogRead(analogInPinY1);
// map it to the needed range of the analog out: change it from 0-1023 to 110-190
serialOutY1 = map(sensorValueY1, 0, 1023, 110, 190);

Serial.write(serialOutY1);

delay (100);

}

Receiving Arduino code:
int SerialReceive = 0;

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

void loop() {

Serial.print("SR: ");
Serial.println(SerialReceive);

if (Serial.available() > 0) {
SerialReceive = Serial.read();
}

delay(100);

}

Once again thank you to all, especially Mrs. Drew!

Remember to use code tags when posting code