//Need help converting ASCII decimal values to characters in serial monitor;

I'm a newbie to programming in general. Trying to get this touchscreen by Reachtech going. It basically has it's own controller for storing and executing macros that I saved as xxxx.h files. These files can be called out uisng the command: <index #>. I've connected the screen's rs232 port to a max232 shield that's connected to arduino mega ---> pc.

According to the screen manual, each button press should return: r<index#>. The serial monitor spits out 3 number terms. I translated it with the table and in fact the data is correct. Now i just need a way to see it in readable terms so i can come up with some quick if/else statements for screen selection.

Here's the code:

#include <SoftwareSerial.h>

void setup()
{

Serial1.begin(115200);
Serial.begin(9600);
Serial1.print('\r');
Serial1.print('\r');
Serial1.print('\r');
Serial.println("Showing debug");
Serial1.println("bvs 50");
}

int i=1;
int ByteReceived;
void handle_button(void);
#undef SHOW_DEBUG
#ifdef SHOW_DEBUG
// these are undefined if SHOW_DEBUG is undefined,
// otherwise may be defined or not as needed
#define BUTTON_PRESS_DEBUG
#endif

void loop()
{
while (i==1){
Serial.println("Showing debug");
Serial1.println("z");
Serial1.println("m1");
i++;

}
if (Serial1.available() > 0)
{
ByteReceived = Serial1.read();
Serial.println(ByteReceived);
}
}

Serial monitor:
Showing debug
Showing debug
62
13
62
13
62
13
62
13
62
13
62
13
114
49
13
114
50
13
114
51
13
114
51
13
114
51
13
114
49
13
114
49
13
114
49
13

Any help would be appreciated. Go easy on the noob :slight_smile:

int ByteReceived;

Why do you use the name Byte in the variable, when the type is NOT byte?

I suppose you like names like:

int myFloat;
float myChar;

too.

    ByteReceived = Serial1.read();

What, exactly, does Serial1.read() return? Why does it need to return that type?

The answers are int and because some people fail to check that there is data to read, so we need some way to tell them that they are idiots. Since you DO check, you are not an idiot, so you can use a type that matches the type of data you expect to receive (such as char).

Try making the type char (use a less stupid name), and see what happens.

PaulS:

int ByteReceived;

Why do you use the name Byte in the variable, when the type is NOT byte?

Because in traditional C you use an int to receive a byte to be able to distinguish the out-of-band -1 error indicator? You still only get a byte.

.print() and .println() are for displaying things like integers and floats in human-readable form. Because you are passing it an integer it displays the numeric value of that integer in human-readable form.

If you just want to display a character as-received you can use .write() in place of .print(). The .write() function takes a character and displays it.

KeithRB:
Because in traditional C you use an int to receive a byte to be able to distinguish the out-of-band -1 error indicator? You still only get a byte.

I don't understand how that answer relates to the question I asked.