Pages: [1]   Go Down
Author Topic: Serial Communication Btwn 2 Arduinos  (Read 429 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, everyone. I'm trying to learn how to communicate serially between 2 Arduinos. I can send and receive PWM values, but I have not figured out how to send strings. I have 2 Arduino Mega 2560s. I want to be able to see the full character string in the serial monitor of Arduino1, but no matter what character string I send, I get only the last one to print to the monitor. How do I get the entire string to print?

Connections:
Arduino1 GND --> Arduino2 GND
Arduino1 rx3 --> Arduino2 tx3
Arduino1 tx3 --> Arduino2 rx3
Arduino1 --> Laptop via USB

Arduino1 (Base) Code:
Code:
void setup(){
  Serial.begin(9600);
  Serial3.begin(9600);
}

void loop(){
  if (Serial3.available()){
    char x = Serial3.read();
    Serial.print(x);
  }
}

Arduino2 (Remote) Code...ignore the commented out code:
Code:
void setup(){
  Serial.begin(9600);
  Serial3.begin(9600);
 
  //Serial2.begin(4800);
  //Serial2.write('!GPS');
}

void loop(){
    /*if(Serial2.available()){
    char x = Serial2.read();
    Serial3.write(x);
  }*/
 
  char x = 'ABCDEFG';
  Serial3.write(x);
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


char x = 'ABCDEFG';

is wrong

char x[] = "ABCDEFG";
or
char x[8] = "ABCDEFG";   // 8 chars from 0 to 7, including a terminating \0.

for (int i =0; i< strlen(x); i++) Serial.print(x);

hope this helps..
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
  char x = 'ABCDEFG';
Which SINGLE key did you press to assign this value to this character?
Logged

Pages: [1]   Go Up
Jump to: