I am trying to use Arduino to use string type data via Xbee.
In a segment of my code in void loop,
I have:
if (XBee.available())
{
char c = XBee.read();
if (c == 'q')
{
delay(1000);
XBee.write('A');
Serial.println("A sent");
}
}
The above works and 'A' is sent.
However, when I try to modify the code to send a variable (generated by a light sensor) as shown below, I get 'no matching function for call to 'SoftwareSerial::write(String&) error' for the line 'Xbee.write(data)'.
if (XBee.available())
{
char c = XBee.read();
if (c == 'q')
{
delay(100);
String data;
data=String(event.light);
Serial.println(data);
delay(1000);
XBee.write(data);
Serial.println("value sent");
}
}
Why do I get this error and how can I successfully modify my code to send variables?
Thanks UKHeliBob, that worked! Seems like I'll just stick to Xbee.print from now on. Also I'm just wondering if there are situations where using xbee print might be more advantageous?
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable.
You can send data in a compatible format with code like this