Having Trouble Communicating between two arduinos

I am doing a project where an arduino Mega is receiving some data through its Rx0 pins and it has to send the data to another arduino uno using TX1 pin. arduino mega is perfectly receiving data from RX0 but it is not sending the data through TX1. A guidline will help me. I tried Serial.write() to write the RX0 value to TX1 pin. but its not working. what am i doing wrong?

what am i doing wrong?

Several things. You posted in the forum without reading the "How to post in this forum" guidelines. I know that because those pages tell you to post your code AND provide as much information as possible. For instance, a wiring diagram and/or photo of your setup is necessary. For all we know, for instance, you have not connected the grounds between the Arduinos and your code doesn't do what you say it does.

I am sorry I posted like this . I am new but that cannot be an excuse.

I am using a hacked mindflex chip for the project. my project is about brain computer interfacing. i am going to drive a robot (actually 2 dc motors) using the value that i get from the headset. I used the tutorial from : How to Hack Toy EEGs | Frontier Nerds , followed the process and successfully received output from the headset.

As my robot will be wireless so I had to use 2 arduinos for that. one arduino mega 2560 which receives the brainwave data and it sends the data through bluetooth to send the data as string with comma separated value to the robot arduino which is an arduino uno. (at the moment i wanna use direct wired communication). then the uno will parse the data and then the data can be used to move the robot.

i am using software serial on arduino mega to get the brainwave data.
this is the code i am using for the arduino mega:

// Arduino Brain Library - Brain SoftSerial Test

// Description: Grabs brain data from software serial on pin 10 and sends CSV out over the hardware serial
// More info: https://github.com/kitschpatrol/Arduino-Brain-Library
// Author: Eric Mika, 2014

#include <SoftwareSerial.h>
#include <Brain.h>

// Set up the software serial port on pins 10 (RX) and 11 (TX). We'll only actually hook up pin 10.
SoftwareSerial softSerial(10, 11);

// Set up the brain reader, pass it the software serial object you want to listen on.
Brain brain(softSerial);

void setup() {
    // Start the software serial.
    softSerial.begin(9600);
    
    // Start the hardware serial. 
    Serial.begin(9600);
}

void loop() {
    // Expect packets about once per second.
    // The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
    // "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"    
    if (brain.update()) {
        Serial.println(brain.readErrors());
        Serial.println(brain.readAttention());
  
  if (softSerial.available())
    Serial.write(softSerial.read());  
  }
}

for the uno part this is the code:

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

There is no errors but i cannot see any output on the other arduino uno.

i connected RX1>TX and TX1>RX of the arduino uno and mega using wire.

thank you for your reply and please let me know what you want to know more. and sorry again for not reading the forum rules.

i am using software serial on arduino mega to get the brainwave data.

Why? There are 4 hardware serial ports. Use one of them!

Only one instance of SoftwareSerial can listen at a time. You are using two. Which one should be ignored?

On the Uno, are you using the hardware serial instance to talk to the Mega or the PC? Both makes little sense. Why do you need two Arduinos involved?

PaulS:
Why? There are 4 hardware serial ports. Use one of them!

I used 2 hardware serial ports earlier (serial and serial1) but it was the same result so used software serial just for checking.

PaulS:
Only one instance of SoftwareSerial can listen at a time. You are using two. Which one should be ignored?

I dont need the TX of the software serial as my brainwave chip only needs RX pin of the mega.

PaulS:
On the Uno, are you using the hardware serial instance to talk to the Mega or the PC? Both makes little sense. Why do you need two Arduinos involved?

on the uno I am using hardware serial instance to talk to the mega. but i also need to see the data on my pc so that i know if data is coming or not.

I need two arduinos as uno will be actually be used to control completely separated robot which will be controlled using the value that is gets through bluetooth .

basic arduino to arduino serial test code. You need to develop your basic serial communication setup before working on any of the other project parts.

//zoomkat 3-5-12 simple delimited ',' string tx/rx 
//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino rx pin to the receiving arduino rx pin. 
//Connect the arduino grounds together. 
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test
//A diode between the slave tx and master rx is suggested 
//for isolation, with diode band attached to slave tx side. 
//

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.print(readString); //prints string to serial port out
        Serial.println(','); //prints delimiting ","
        //do stuff with the captured readString 
        readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

raihanzz:
I tried Serial.write() to write the RX0 value to TX1 pin. but its not working. what am i doing wrong?

If you want to write to TX1 you use Serial1.write()

Serial.write() writes to TX0

You may find serial input basics useful

...R

zoomkat:
basic arduino to arduino serial test code. You need to develop your basic serial communication setup before working on any of the other project parts.

thank you for your reply. that code will show me the characters on the serial. but can I change those data into integers somehow? all my strings are coming like this:

200,0,0,70022,1415627,296609,25469,7758,19291,6073,220596

200,0,0,156935,1214616,65576,66807,66404,93299,3214,115150

200,0,0,809665,189860,112964,133943,41532,31662,36654,108499

but can I change those data into integers somehow? all my strings are coming like this:

How are you storing the data? That has a huge impact on how you parse the data.

PaulS:
How are you storing the data? That has a huge impact on how you parse the data.

I am not storing the data now as this data is changing in every second and i am not sure how i can store it.

Below is some basic servo test data that shows the conversion of a captured String into an integer for use wth a servo. Your data packet appears to be terminated with a cr/lf and internally delimited with commas. Do you have control of the format the data packet is using?

//zoomkat 3-5-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

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

  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-delomit-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like 700, or 1500, or 2000,
  //or like 30, or 90, or 180,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          myservo.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          myservo.write(n);
        }

        //do stuff with the captured readString 
        readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

zoomkat:
Do you have control of the format the data packet is using?

yes i have some control. like if i want to use the 2nd value of the string, i have to write

Serial.println(brain.readAttention());

i printed that on the arduino mega and saw output in pc. but i dont know how to send this single data to another arduino serially as the data is changing every second.
for more information check the "function overview" section of the link : GitHub - kitschpatrol/Brain: Arduino library for reading Neurosky EEG brainwave data. (Tested with the MindFlex and Force Trainer toys.)

or more information check the "function overview" section of the link : GitHub - kitschpatrol/Brain: Arduino library for reading Neurosky EEG brainwave data. (Tested with the MindFlex and Force Trainer toys.)

I'm not going to dig thru that site to figure out what you are doing (you need to post any code there that might need to be looked at). Below is some serial capture and parsing code similar to what you may need. I used a * as the packet end of data marker instead of cr/lf as the * is easier to work with for testing.

//zoomkat 11-12-13 String capture and parsing  
//from serial port input (via serial monitor)
//and print result out serial port
//copy test strings and use ctrl/v to paste in
//serial monitor if desired
// * is used as the data string delimiter
// , is used to delimit individual data 

String readString; //main captured String 
String angle; //data String
String fuel;
String speed1;
String altidude;

int ind1; // , locations
int ind2;
int ind3;
int ind4;
 
void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 11-12-13"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like 90,low,15.6,125*
  //or 130,hi,7.2,389*

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == '*') {
      //do stuff
      
      Serial.println();
      Serial.print("captured String is : "); 
      Serial.println(readString); //prints string to serial port out
      
      ind1 = readString.indexOf(',');  //finds location of first ,
      angle = readString.substring(0, ind1);   //captures first data String
      ind2 = readString.indexOf(',', ind1+1 );   //finds location of second ,
      fuel = readString.substring(ind1+1, ind2+1);   //captures second data String
      ind3 = readString.indexOf(',', ind2+1 );
      speed1 = readString.substring(ind2+1, ind3+1);
      ind4 = readString.indexOf(',', ind3+1 );
      altidude = readString.substring(ind3+1); //captures remain part of data after last ,

      Serial.print("angle = ");
      Serial.println(angle); 
      Serial.print("fuel = ");
      Serial.println(fuel);
      Serial.print("speed = ");
      Serial.println(speed1);
      Serial.print("altidude = ");
      Serial.println(altidude);
      Serial.println();
      Serial.println();
      
      readString=""; //clears variable for new input
      angle="";
      fuel="";
      speed1="";
      altidude="";
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

I am not storing the data now

Then you haven't a hope in hell of parsing it.

as this data is changing in every second

During which time the Arduino has executed 16,000,000 instructions.

raihanzz:
thank you for your reply. that code will show me the characters on the serial. but can I change those data into integers somehow? all my strings are coming like this:

Did you study serial input basics that I mentioned in Reply #6 ? It includes a parse demo.

...R