I am working with serial data coming from a sensor, the byte values I receive were puzzling to me as they would not print as characters which I know they are. Going back a couple steps I simply tried to convert an int to a character and print it but was unsuccessful. If you look at my code snippet, I define a character array "mystr" (I made it too large for a single int intentionally to make sure that mem allocation wasn't the problem) and an int "x". I then iterate from 32 to 49, expecting to get space, exclamation, quote, hash, dollar, etc. but have found no joy.
Using the code snippet below, the output is:
32 32 32 32 20 40 100000
Any thoughts on what I am doing incorrectly with itoa()? Thanks! Phil
char mystr[12];
int x;
for(x=32; x<50; x++){
(itoa(x, mystr, 10));
Serial.write(mystr);
Serial.print(" ");
Serial.print(mystr);
Serial.print(" ");
// print it out in many formats:
Serial.print(x); // print as an ASCII-encoded decimal - same as "DEC"
Serial.print("\t"); // prints a tab
Serial.print(x, DEC); // print as an ASCII-encoded decimal
Serial.print("\t"); // prints a tab
Serial.print(x, HEX); // print as an ASCII-encoded hexadecimal
Serial.print("\t"); // prints a tab
Serial.print(x, OCT); // print as an ASCII-encoded octal
Serial.print("\t"); // prints a tab
Serial.println(x, BIN); // print as an ASCII-encoded binary
}