Skip to content

Instantly share code, notes, and snippets.

@wojciech-zurek
Last active January 17, 2020 09:15
Show Gist options
  • Save wojciech-zurek/021e4f5c10681ca78fc73faad5f964aa to your computer and use it in GitHub Desktop.
Save wojciech-zurek/021e4f5c10681ca78fc73faad5f964aa to your computer and use it in GitHub Desktop.
Arduino example demonstrates how to print ASCII values in decimal, hexadecimal, octal, and binary.
#include <Arduino.h>
int character = 0;
void setup()
{
Serial.begin(9600);
Serial.print("Echo start\r\n");
}
void loop()
{
if (Serial.available() > 0)
{
character = Serial.read();
Serial.print("ascii: ");
Serial.write(character);
Serial.print("\t\tdec: ");
Serial.print(character);
Serial.print("\t\thex: ");
Serial.print(character, HEX);
Serial.print("\t\toct: ");
Serial.print(character, OCT);
Serial.print("\t\tbin: ");
Serial.println(character, BIN);
}
}
Linux:
stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
tail -f /dev/ttyUSB0
ascii: A dec: 65 hex: 41 oct: 101 bin: 1000001
ascii: a dec: 97 hex: 61 oct: 141 bin: 1100001
echo -n "Aa" > /dev/ttyUSB0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment