Serial communication error

My project is to send some sensor values from arduino mega and transfer it to arduino uno and then display on PC.Dont ask me to send data from mega to computer directly.Project is to develop long distance data transmission using powerline modem.Anyway coming to the topic ,I was able to serialy transmit my data and display on serial monitor in mega.But at the receving side(uno) its not recieving.I am attaching the Code.The serial.println() function in the transmission side is used because i want the string to be exactly recieved that way to PC So that the pc software is able to read it.(Android_bluetooth.ino is the transmitter section(mega) and reciever.ino is the reciever section program.)
Pls help me communicate bw transmitter and reciever section.

Transmission side serial communication code


text=text+no+","+v+","+AmpsRMS+","+kilos+":";
Serial.println(text);
text="";
delay(1000);

(NB:i have no idea about recieving section code,just copied from a related forum

Android_bluetooth.ino (2.48 KB)

reciever.ino (323 Bytes)

how is the connection (wires) from pin...to pin?

What serial port are you using on uno for connection to mega and what for connection to usb?

  text=text+no+","+v+","+AmpsRMS+","+kilos+":";
  Serial.println(text);
  sendAndroidValues();
  text="";

On every pass through loop(), you set text to an empty string. And, the next time, you add to that empty string, and assign the result to text. Makes no sense.

text = no+","+v+","+AmpsRMS+","+kilos+":";

Getyourspacekeyfixed.

On your receiver, you are using Serial to read incoming data (from the Mega AND from the PC) and to write to the Mega and the PC. That is not really a good idea. Use Serial to write to, and read from, the PC, and use an instance of Software Serial to read from/write to the Mega.

Your piss-poor indentation makes your code hard to read. Tools + Auto Format would help with the indenting.

On any given pass through loop(), you read a maximum of one character from the serial port. That hardly constitutes a valid reason to piss away resources using the String class.

@OP

1. Your Sender-MEGA codes are running in my MEGA (see screenshot below).

2. Receiver - UNO/NANO is connected with Software UART Port as Hardware UART Port is permanently engaged with Serial Monitor/IDE for debugging and uploading.

3. This is the Receiver-NANO sketch which has been tested with MEGA on wired connection. TX1 (MEGA) ------> 2 (NANO); RX1 (MEGA) <----- 3 (NANO); GND (MEGA) <--------> GND (NANO).

#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = DPin-2, STX = DPin-3
char text[50] = "";
int i =0;

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

void loop()
{
  byte n = SUART.available();
  if (n != 0)
  {
    char x = SUART.read();
    if (x != 0x0A) //no end mark ln is found
    {
      text[i] = x;
      i++;
    }
    else
    {
      Serial.println(text);
      i=0;
    }
  }
}

sm86.png

sm87.png

BTW: Read the receiver codes in the light of Post#2.

sm86.png

sm87.png

Yup,my transmission code is just exactly as it needed to be to read by the PC software i designed.But the problem is that this data have to go through uno before it reaches the pc.So i have to recreate the transmission side output exactly at the uno side.That i tried and failed 1000 times,because i have no idea how to do that.

ThottiKuttapan:
Yup,my transmission code is just exactly as it needed to be to read by the PC software i designed.But the problem is that this data have to go through uno before it reaches the pc.So i have to recreate the transmission side output exactly at the uno side.That i tried and failed 1000 times,because i have no idea how to do that.

Now, at the receiver side you have been able to store the received data in ASCII code in the array named char text. Try to isolate your data items from this array and save them to individual variables of correct types. Use the commas (,) as data separators and process the array. The first one you can do easily:

text[4] = 0x00;
int x = atoi(text);
Serial.println(x);   //shows: 1001

and so on… with variations! You may need to use atof() function?

The issue has been solved,Thanks everyone.But the funny thing is that mega is only giving Rx,Tx output to uno only if mega is connected to PC.When i connect my Mega to a 9V battery,Mega displays value in the lcd display,But Doesnot Transfer serial data to the uno.(Uno Doesnt get any input and Tx led of mega not blinking.ie serial data transmission doesnot take place.)Why does that happen.

It would make a lot more sense to use a Mega in place of the Uno as it has 3 spare HardwarSerial ports.

...R
Serial Input Basics - simple reliable ways to receive data.

ThottiKuttapan:
The issue has been solved,Thanks everyone.But the funny thing is that mega is only giving Rx,Tx output to uno only if mega is connected to PC.When i connect my Mega to a 9V battery,Mega displays value in the lcd display,But Doesnot Transfer serial data to the uno.(Uno Doesnt get any input and Tx led of mega not blinking.ie serial data transmission doesnot take place.)Why does that happen.

AFAIK, some megaclones (if you are using one of them), have the following "errors":

  1. pin19 is marked TX1, although actually is RX1. Same on pin 18 (marked Rx1 , is Tx1).
  2. There is no connection between Vin pin and PowerJack. So if you are using 9V in Vin, you may have NO power.

ThottiKuttapan:
The issue has been solved,Thanks everyone.But the funny thing is that mega is only giving Rx,Tx output to uno only if mega is connected to PC.When i connect my Mega to a 9V battery,Mega displays value in the lcd display,But Doesnot Transfer serial data to the uno.(Uno Doesnt get any input and Tx led of mega not blinking.ie serial data transmission doesnot take place.)Why does that happen.

help please

demkat1:
AFAIK, some megaclones (if you are using one of them), have the following "errors":

  1. pin19 is marked TX1, although actually is RX1. Same on pin 18 (marked Rx1 , is Tx1).
  2. There is no connection between Vin pin and PowerJack. So if you are using 9V in Vin, you may have NO power.

Bro i am connecting the 9v battery to powerjack instead of Connecting to pc with usb.
Arduino turns on and all that,Program is running and stuff.But the portion of serial transmission is not executing.is iv because 9v battery cant provide enough power