Use the UART – see here

Menu > Tools > Serial Monitor sop see its output

Enable the serial port

  //Serial.begin(9600);    //May as well run it at fast speed of 115200
  Serial.begin(115200);
  while(!Serial)
    ;

Strings

Print const string
  Serial.println(F("Hello"));

Note the “F( )” avoids the compiler storing the string in RAM (dynamic) memory by default

Print array as char string
  Serial.println((char*)buffer);
Printing Multiple Strings
  Serial.println("Hello " + MyStringName);
Print A Character
  Serial.print((char)c);

Specific variable types

Integer
  Serial.print(variable1, DEC);
Hex
  Serial.print(variable2, HEX);
Binary
  Serial.println(variable3, BIN);
Float
  Serial.println(my_float_value, 3);

Will print to 3 decimal places

64bit value
//Serial.print does not support 64bit, so we use this
void SerialPrintUint64 (uint64_t value)
{
  char rev[22]; 
  char *p = rev + 1;

  while (value > 0)
  {
    *p++ = '0' + ( value % 10);
    value /= 10;
  }
  p--;
  //Print the number which is now in reverse
  while (p > rev)
    Serial.print(*p--);
}

Examples

  Serial.print(F("Received: "));
  Serial.print(variable1, DEC);
  Serial.print(F(", "));
  Serial.print(variable2, HEX);
  Serial.print(F(", "));
  Serial.println(variable3, BIN);
  Serial.println(tx_data[0], HEX);
  Serial.println(tx_data[1], HEX);
  Serial.println(tx_data[2], HEX);
  Serial.println(tx_data[3], HEX);
  Serial.println(tx_data[4], HEX);
  Serial.println((p_buffer - tx_data), DEC);
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *