ASCII
Try It
If you would like to try printing something using ASCII encoding, you can try it out using Arduino. See this tutorial for getting started with Arduino.
Open the Arduino IDE and paste in the following code:
language:c
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.write(0x48); // H
Serial.write(0x65); // e
Serial.write(0x6C); // l
Serial.write(0x6C); // l
Serial.write(0x6F); // o
Serial.write(0x21); // !
Serial.write(0x0A); // \n
delay(1000);
}
Run it on your Arduino, and open a Serial console. You should see the "Hello!" appear over and over:
Notice that we had to use Serial.write()
instead of Serial.print()
. The write()
command sends a raw byte across the serial line. print()
, on the other hand, will try and interpret the number and send the ASCII-encoded version of that number. For example, Serial.print(0x48)
would print 72
in the console.
Also, notice that we used the ASCII character 0x0A
, which is the "line feed" control character. This causes the printer (or console in this case) to advance to the next line. It is similar to pressing the 'enter' key.