I2C - Wire.requestFrom()
Posted: Tue Sep 06, 2016 2:25 pm
I am would like to understand why is my array displaying 3 (funny) characters as shown in the images attached.
I successfully get the data from the slave. Then directly after the loop i print out the data and then i get funny characters at the end. Can some one explain to me what these characters are and why are they random values?
this is the code i use to read the data that the slave return.
I successfully get the data from the slave. Then directly after the loop i print out the data and then i get funny characters at the end. Can some one explain to me what these characters are and why are they random values?
this is the code i use to read the data that the slave return.
Code: Select all
void requestData(){
Serial.println("Request Returning");
//clean the array
for(int i =0;i<32;i++)
{
data[i]=' ';
}
delay(10);
if (Wire.requestFrom(slaveId,25))
{
int i =0;
while (Wire.available())
{
char c;
c=Wire.read();
if(c>0x1F && c<0x7F)
{
Serial.println(c);
data[i] =c;
}
i++;
}
Serial.println(data); //This is the line that i am getting the funny characters on. See image link below
}
else
{
Serial.println("Unable to");
Serial.println("Retrieve the data requested");
}
}