i2c byte data to char

Hello !

How do i convert Byte (Uint8_t) comming from:

uint8_t datastring;

Wire.requestFrom(0x60,67); //Lets fetch the stuff; 67Bytes of fun.
datastring |= Wire.receive();

to a char string?
Lots of commas in between, but they are cruciel to be kept.
further on - last two bytes will be
k

as far as I know char is signed in Arduino -127/+128 and datastring will be 0-255

thanks for Help !

I'm curious to know also.

My first try would be type casting. Does this work?

char test = (char)datastring;

Something like this should work. I wouldn’t worry about the different data types, the compiler isn’t.

const int WANTED_NUMBER = 67;

uint8_t datastring [WANTED_NUMBER]; 

bool getData ()
{

  if (Wire.requestFrom (0x60, WANTED_NUMBER) < WANTED_NUMBER)
    return false;  // didn't get number we wanted

 // get each byte
  for (byte i = 0; i < WANTED_NUMBER; i++)
    datastring [i] = Wire.receive ();
    
  return true;  // OK
  
}  // end of getData

If you are planning to treat it as a “C” string you might add a terminating 0x00 byte:

const int WANTED_NUMBER = 67;

uint8_t datastring [WANTED_NUMBER + 1]; 

bool getData ()
{


  if (Wire.requestFrom(0x60, WANTED_NUMBER) < WANTED_NUMBER)
    return false;  // didn't get number we wanted

 // get each byte
  for (byte i = 0; i < WANTED_NUMBER; i++)
    datastring [i] = Wire.receive ();
    
  datastring [WANTED_NUMBER] = 0x00;  // terminating null
  
  return true;  // OK
  
}

Thanks, that worked !!