Serial.write(0x0d); // hex
Serial.write(13); // ASCII
Serial.write('\r'); // char
Is one more efficient? I read how it depends on the terminal program. So does that mean the IDE? (This is my first time working with serial comm.)
As mentioned before they are all the same. The thing you have to rememeber is that the compiler takes the human readable code you write and turns it into the instructions the processor can understand. If you want to explore ways the compiler does thing you can compile the program into the hex file and then compare. Or for even less detail, but much easier, look at the size of the file created when you compile in the IDE using just the one line in question inside the setup function
write(0x0d) ----> 1334 bytes write(13) ----> 1334 bytes write('\r') ----> 1334 bytes
For this simple example we can assume that all three of these are producing the exact same hex file. There are many more complicated example of different ways to do the same task that may produce more or less efficient code, but in this case the compiler is going to produce the same instruction set to the processor.
As pointed out in the comments, I am not saying that because they are the same size they must be the same hex code. As any single byte being written would produce the same size code, but not the same result. But when comparing two methods that we know are the same functionality ( 0x0d and '\r') and they produce the same size binary, then we can assume the compiler reduced them to the same code.
There is no difference between all the lines of code in your question. All representations stand for one value, containing one byte. There is only one implementation of
Serial::write(), which has a
uint8_t as parameter. So all the different representations result in a
Is one more efficient?
after compilation it is same for all notations. the function and the value are the same for all 3 notations.