0
votes

I wish to send serial data from an Arduino Uno to an Arduino Nano via the available UART port.

On reception of data at the Nano end I have to check whether the data matches to "a" or "b". If it does, I have to send data back to the Uno.

I have used the following Code on the Nano side:

void GMP_OutputSerial(void)
{
  if(Serial.available())                                              // Check if serial data is avaiable
  {
    unSerialAvailable = Serial.read();                                // Read the data if serial data is available
    if(unSerialAvailable == 'A' || unSerialAvailable == 'B' || unSerialAvailable == 'a' || unSerialAvailable == 'b')          // Proceed only if available data is equal to A or B
    {
      /*
      if(g_stSensorParms.stAppParms.unFinalDistance > 80 || g_stSensorParms.stAppParms.unFinalDistance < 0)   
      {
        Serial.println("Distance: Out of range");
      }
      else
      {
        */
        Serial.print("Distance: ");                                     // Output Distance text on the serial monitor
        Serial.println(g_stSensorParms.stAppParms.unFinalDistance);      // Output the actual distance on the serial monitor
    }
  }
}

On the Uno side:

void loop()
{
  Serial.write(a);
  delay(1);
}

However, I see no communication happening. Power to the both the boards comes from an external supply = 5V.

TX line of Uno is connected to RX line of Nano and vice versa.

What am I doing wrong?

6
"I see no communication happening." -- You probably only mean that you are not seeing reception of the expected data. "Communication" involves transmission as well as receiving. You probably have not checked for transmission. You could use a 'scope on the Uno'x TxD pin, or sniff the port as @Keroronsk suggests.sawdust

6 Answers

3
votes

In Serial.write(a);, a is equal to 'A'? Or you really mean Serial.write('A')?

p.s. You can actually make cheap "sniffer" for serial port, by wiring 1ft. cable to DB9 connector, plugged in COM-port (or USB to serial adapter), and "see" actual data on the arduino RX\TX lines.

1
votes

From Arduino UNO

void setup()
{
   Serial.begin(9600);
}
void loop()
{
Serial.print("a");
}

From Arduino NANO

void setup()
{
Serial.begin(9600);
if(Serial.available()>0)
{
char a = Serial.read();
}
}
0
votes

Did you put a Serial.begin(9600) in the setup function of each board? It would also help if you posted the core running on the UNO. Or at lest confirm that you have verified that it works, for example replacing the Nano with a PC, like the OP wrote. The UNO has leds on both TX and RX lines, so you can easily verify if anything is transmitted, if you are using the "real" serial port. The arduino ide also comes with integrated, easy-to-use serial sniffer.

0
votes

Please declare char a='A' then write it like below.

char a='A';
void setup() 
{

    Serial.begin(9600);

}

void loop() 
{

     Serial.write(a);
     delay(10);
}
0
votes

The codes mentioned above should work properly, I suggest you to create some checksum to your string when you are trying to transmit as the serial connection between the two boards is not stable enough for large amounts of data.

0
votes

before uploading the script just remove the RX TX connections and after uploading successful re-connect them and chk it again . it's not that important to set the datarate at this time because even if the datarate between the two chips are not matched(which is most likely to happen) the error you will get is a distorted data ,so you will have transmission but not in the way you want