I2C issue

Hi,

Anyone to help me to solve the issue in this very basic code ?
error: no matching function for call to 'TwoWire::send(String&)'

#include <Wire.h>
String toSend;

void setup()
{
Wire.begin(2); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event

}

void loop()
{ toSend=toSend+analogRead(0)+";";
if (toSend.length()>20) {toSend="";}
delay(100);
}

void requestEvent(){
Wire.send(toSend);
}

Thanks to all.

Seb

The String object is not the same as an character array which is expected by the wire library. Seehttp://arduino.cc/en/Reference/StringObject You need to use the toCharArray() to create the char array. Unfortunately the page toCharArray() - Arduino Reference does not describe the params needed.

// toCharArray() copies the internal representation of a string to an array of char. 
// buf = pointer to an array of char
// bufzsize = size of the array copied to
void String::toCharArray(char *buf, unsigned int bufsize)

so change your code to

#include <Wire.h>

String toSend;

void setup()
{
 Wire.begin(2);                // join i2c bus with address #2
 Wire.onRequest(requestEvent); // register event
}

void loop()
{
  toSend += analogRead(0)+";";
  if ( toSend.length()>20 ) toSend="";
  delay(100);
}

void requestEvent()
{
  char buffer[32];
  toSend.toCharArray(buffer, 32);
  Wire.send(buffer);
}