i2c sending the ascii value of the symbol instead of the symbol?

Hi…yet another noob :)…so I have 2 arduinos connected using 2 wire. and this is what the master is doing:

void loop()
{
  sendCommand(4, '1', '9', '1');

  delay(500);
}

boolean sendCommand(int device, byte method, byte parameter, byte value)
{
  Wire.beginTransmission(device);
  Wire.write('<');
  Wire.write(method);
  Wire.write(':');
  Wire.write(parameter);
  Wire.write(':');
  Wire.write(value);
  Wire.write('>');
  Wire.endTransmission();
  Serial.println("(M:1) TRANSMIT SUCCESS");
}

the slave reads it as follows:

void setup()
{
  Wire.begin(4);                //
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}

void loop()
{
  delay(100);
}

void receiveEvent(int howMany)
{
  while (1 < Wire.available())
  {
    char c = Wire.read();
    Serial.print(c);
  }
  int x = Wire.read();
  Serial.println(x);
}

However the output on the slave over serial is “<1:9:162” everything else is correct except the last character which is represented by “62” instead of “>” im not sure if its how serial is interpreting it or if its how its being sent over the i2c protocol…PLEASE HELP :slight_smile:

It is doing exactly what you told it to do. It reads the '>' as an integer, not a char, so when you print it it is printed as 62.

Pete

P.S. reading until there is only one character is left is not the best way to do it. You aren't actually guaranteed that all the characters will have arrived while you are in the while loop.

Pete

OKAY i understand for the most part and yes i shall correct that then :)...and thanks for the help!