Receiving all 0s with not cable connected to pins RXTX Arduino Mega

Hi all,

While trying to send/receive data to/from a device connected through the communication pins of my Arduino Mega, I've detected that I'm receiving 0 values continously. That behaviour is present even without connecting the cables to the device, only the cables with one end to the RX and TX and the other end to air.

I've tried this code

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  //Serial.print("INIT");
  byte dat;
  if(Serial1.available() > 0)
   {    
    dat=Serial1.read();   
    Serial.print("Received data of size: ");Serial.print(sizeof(dat));Serial.print(" With value (HEX): ");Serial.println(dat, HEX);
   }
}

It happens with an original Arduino Mega and with a board from another brand "SainSmart". Also, it happens with all three TX/RX pins (Serial1, Serial2, Serial3). When the cable detects some "resistance" like my fingers, I receive all 0s.

I've seen this post serial.available() receiving 0 (NULL) when nothing is connected - Networking, Protocols, and Devices - Arduino Forum, however, I don't know how to do the right connections properly.

I add a schematic of my hardware. One 1K ohm resistor is connected between Arduino and the device.

Can you help me?

Thanks

REM14:
I've seen this post serial.available() receiving 0 (NULL) when nothing is connected - Networking, Protocols, and Devices - Arduino Forum, however, I don't know how to do the right connections properly.

It will be easier to help if you tell us how you think things should be connected.

I add a schematic of my hardware. One 1K ohm resistor is connected between Arduino and the device.

I can't see any image. See this Simple Image Guide

...R

@Robin2. The system does not allow to upload an image "Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator. "

The connection is:

TX1 Arduino - 1k ohm - RX device
RX1 Arduino - 1K ohm - TX device
GND Arduino - GND device

I'm worried that because of the reception of "garbage" 0s, Arduino cannot process the real data from the device. I've tried to modify the baudrate and change resistance.

Sorry about the image.

REM14:
@Robin2. The system does not allow to upload an image "Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator. "

That is probably because you are trying to upload a JPG taken with a camera which includes EXIF data. A simple solution is to convert it to a PNG. Another option is to open the JPG in a photo editor and save a cropped version to a new file - I think that won't include the EXIF data.

...R

REM14:
I'm worried that because of the reception of "garbage" 0s, Arduino cannot process the real data from the device. I've tried to modify the baudrate and change resistance.

The advice in the other Thread you linked to in your Original Post is to connect an additional resistor (perhaps 4k7) between the Rx pin and 5v to hold the Rx line HIGH when there is nothing connected to it.

...R

If the TX from the device is connected to the Arduino RX with a cable, how can I connect it also to 5V?

Could you provide me with a basic draw?

REM14:
If the TX from the device is connected to the Arduino RX with a cable, how can I connect it also to 5V?

I presume you mean that it is connected to one of the Mega's Rx1, Rx2 or Rx3 pins. If so you will need to make an adapter that allows you to connect the pull up resistor and the cable.

For testing you can do it with a breadboard and some jumper wires.

...R