ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Hardware Serial is unable to send String Object #1083

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.String temp;
2. temp+= X; temp+=", "; temp+=Y;
3. serial.write(temp)

What is the expected output? What do you see instead?

I expect to see "X, Y" be sent and received from arduino to arduino, however, I 
get this: no matching function for call to 'HardwareSerial::write(String&)'

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Im using version V1.0, on Windows XP with a Ard Mega to Ard Uno

Please provide any additional information below.
Im trying to send 3 sets of data to my Uno "X, Y, state", to control my robot. 
Right now, I am interfacing a 3.2 TFT touch screen with the mega and trying to 
send the data. Im not sure if the touch screen will slow the rate of sent data. 
With that in mind, I dont want to send the data in an array and have a For loop 
split the data on the other side. Mainly because I might lose the data on the 
way.

Can I send my data in a string, like I want, or do I need to send it as an 
array, or is there something else I can do?

Original issue reported on code.google.com by mascoloa...@gmail.com on 26 Oct 2012 at 2:02

GoogleCodeExporter commented 9 years ago
"write" is a primitive method supporting only char and buffers (with length.)
Strings are not primitive data types.  You want "Serial.print(temp);"

Original comment by wes...@gmail.com on 26 Oct 2012 at 2:40

GoogleCodeExporter commented 9 years ago
To clarify, im send my data Via bluetooth, and I need the robot to 
"Serial.read" the incoming data and function accordingly. What do I need to do?

my code:

int X,Y,state;
String command;

void setup()
{ 
  Serial1.begin(9600);
}

void loop()
{
  command+= X;//sensor data
  command+= ', '; //some white space
  command+= Y;//sensor data
  command+= state; //other data
  Serial1.write(command); //send via bluetooth to robot
}

I am unable to compile this because of Serial1.write(), I get an error. How can 
I send my data correctly?

Original comment by mascoloa...@gmail.com on 26 Oct 2012 at 3:14

GoogleCodeExporter commented 9 years ago

  // do it like this:

  Serial1.print(command); //send via bluetooth to robot

Original comment by paul.sto...@gmail.com on 29 Oct 2012 at 7:07