Send string from mega to mega


i trying send string 1 mega other , have done doing this:
code: [select]

void setup() {
  // initialize both serial ports:
  serial.begin(9600);
  serial1.begin(9600);
}

void loop()
{
  serial1.write("0;200;");
  delay(2000);
}


that works great. wanted build string before sent it. took next step further , tried saving same string variable , send variable, this:

code: [select]

void setup() {
  // initialize both serial ports:
  serial.begin(9600);
  serial1.begin(9600);
}

void loop()
{
  string boss = "0;200;";
  serial1.write(boss);
  delay(2000);
}


this seems work fine(or else did me) getting error: "no matching function call 'hardwareserial::write(string&)' "

not sure why error happening because sending same string. appreciated. if has better way send string "serial1.write()" command ears well.

thanks in advance

hi!

change
code: [select]
serial1.write(boss);
to
code: [select]
serial1.print(boss);

actually, write() expects 1 byte or array of bytes argument.
but print() handles lot of datatypes.



Arduino Forum > Using Arduino > Programming Questions > Send string from mega to mega


arduino

Comments