0

I'm trying to send long String to Android via bluetooth.

but,

enter image description here

It looks like the picture.

some characters are changed.

how can I get an exact full string?

arduino code :

    for(int i=0;i<16;i++){
      String rec = String(P[i], HEX);
      if(rec.length()<2) rec = "0"+rec;
      BTSerial.println(rec);
      delay(50);

P is a byte array. Thanks.

1
  • in your code a } is missing Commented Aug 10, 2016 at 9:06

1 Answer 1

1

Try it without String objects:

// return '0' .. 'F'
char hexnibble(byte nibble) {
  nibble &= 0x0F; // just to be sure
  if (nibble > 9) return 'A' + nibble - 10;
  else return '0' + nibble; 
}

void loop() {
 byte P[16]; 
 //  ... fill P somehow ...
 char rec[33];
 for(int i=0;i<16;i++){
      rec[2*i] = hexnibble(P[i] >> 4);
      rec[2*i+1] = hexnibble(P[i] & 0x0F);
 }
 rec[32] = 0; // string terminator

Serial.println(rec); // just for debugging
delay(1000);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Happy to read it helped, even with the small syntax errror (sorry for that)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.