Use the UART – see here

Menu > Tools > Serial Monitor sop see its output

Print const string

  Serial.println(F("Hello"));

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

Enable the serial port

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

Example

  Serial.print(F("Received: "));
  Serial.print(variable1, DEC);
  Serial.print(F(", "));
  Serial.print(variable2, HEX);
  Serial.print(F(", "));
  Serial.println(variable3, BIN);

Example – Displaying some values

  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);

Print array as char string

  Serial.println((char*)buffer);

Printing Multiple Strings

  Serial.println("Hello " + MyStringName);

Print A Character

  Serial.print((char)c);

Print 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--);
}
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 mini sites like this. We hope you find the site 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 on this site. 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 *