Send Number as byte throught serial

I'am trying to recive data from arduino to Android device

i saw an online guide for that he provided this code

void setup() { Serial.begin(115200); }

void loop() { byte msg[64]; int len; len = Serial.available(); if (len > 0) { len = Serial.readBytes((char*)msg, sizeof(msg)); // readBytes seems to need a char* not a byte* Serial.write(msg, len); } }

i tried that example and it is working perfectly!

i when i put Serial.write("3"); in the setup loop after Serial.begin(115200); it appears as question mark on my android device i guess that i'm not sending it as a byte i searched online but with not luck

any ideas ?

Serial.print("3");

Pete

el_supremo: Serial.print("3");

Pete

Thanks for fast replay, but this did NOT solved the problem , i'm still getting question marks instead of the number 3 !

I don't know your use, but does the 3 have to be sent as the character '3' (ASCII 51 in decimal) or as the binary value 3?

i guess that i’m not sending it as a byte

You may need to figure out weather you want to send a byte that represents the character “3” or a byte representing a binary 3. The print function should send a byte that represents the ascii character “3”. You may also have issues on the android device and not the arduino. On the arduino side you can test using the serial monitor.

fraizor:
i tried that example and it is working perfectly!

i when i put Serial.write("3");
…SNIP…
it appears as question mark on my android device

Is there a logical connection between “working perfectly” and “it appears as question mark” ?

Are you saying that Serial.write(msg, len) displays properly on the Arduino but Serial.write(“3”) does not?

Try Serial.write(‘3’); with single quotes or Serial.write(51); which is the Ascii value for ‘3’

…R

Your working program is overcomplicated, it copies input to output and tries to do that in 64 byte chunks. Why your android app displays a question mark on reception of the character '3' only you now.

I would do the copy like that (including sending a '3' and a 0x03)

void setup() {
  Serial.begin(115200);
  Serial.write('3');
  Serial.write(3);
}
void loop() {
  if (Serial.available()) {
    Serial.write(Serial.read());
  }
}

Thank you a lot guys your suggestions solved the problem ...

And the solution was . . ?