Go Down

Topic: Serial Communication Btwn 2 Arduinos (Read 542 times) previous topic - next topic

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: [Select]
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: [Select]
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);
}

robtillaart


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..
Rob Tillaart

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

PaulS

Quote
char x = 'ABCDEFG';

Which SINGLE key did you press to assign this value to this character?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy