SALES INQUIRIES: 1 (888) 767-9864

Use Serial.print() to display Arduino output on your computer monitor: Part 2

In many cases while using an Arduino, you will want to see the data being generated by the Arduino. One common method of doing this is using the Serial.print() function from the Serial library to display information to your computer’s monitor.

In this week’s episode we will talk about the intricacies of the Serial.print() function.  This is the second part of a two part series on the Serial.print() function (Click here for the first part).

Here are the exact topics we will cover in this lesson:

  • Adjusting the number of digits to be displayed after the decimal point with the Serial.print() function.
  • Adjusting the format to display with the Serial.print() function
  • Formatting the output with text and tabs

If you enjoyed this video, you should consider signing up for our free Arduino Crash Course – it has 19 high quality video training classes to help build your imagination with Arduino.

10 Comments

  1. […] In next week’s episode, we’ll talk about some more intricacies of the Serial.print() function. […]

  2. Avatar Manish Aggarwal on December 16, 2015 at 11:30 pm

    How can I print ” character on serial monitor ?

    • Avatar MICHAEL JAMES on December 16, 2015 at 11:50 pm

      Great question. Are you trying to print the ASCII representation of a value?
      You might try using Serial.write() instead (I think you had mentioned something about trying to display a backslash also). If you want the numbers to be displayed as text, use double quotes ” ” Hope this helps some!

      • Avatar Manish Aggarwal on December 17, 2015 at 12:17 am

        Sir that backslash problem was resolved using escape sequence ‘\’.But I accidentally wrote this Serial.print(’12’).Then at first I thought the IDE would give error.But it did not show any error.When I opened Serial monitor it showed this value ‘12594’…I am unable to understand how it is doing that??

    • Avatar Manish Aggarwal on December 18, 2015 at 11:10 pm

      When you output ’12’ you are outputting 2 characters, a ‘1’ and then a ‘2’, this results in hex 31 or dec 49 being transmitted followed by a 32hex / 50dec, if you concatinate the two into a single integer then you get 12594, sending the 10 works out to be 12592, 11=12593

      Binary of 49 = 00110001

      Binary of 50 = 00110010

      How these concatinate , depends on the compiler.

      Here these concatinate as : 00110001 00110010

      In some other compiler they may concatinate as :

      00110010 00110001

      The print statement is interpreting this as an integer (16bits) instead of two 8 bit characters because in C the character literal is defined as an int and your providing just the right number of 8 bit characters to make an int.

      If you type = ‘312’ , then the compiler would consider last two characters only because the size of int is 2 bytes in Arduino IDE…

  3. Avatar Manish Aggarwal on December 18, 2015 at 11:08 pm

    When you output ’12’ you are outputting 2 characters, a ‘1’ and then a ‘2’, this results in hex 31 or dec 49 being transmitted followed by a 32hex / 50dec, if you concatinate the two into a single integer then you get 12594, sending the 10 works out to be 12592, 11=12593
    Binary of 49 = 00110001
    Binary of 50 = 00110010
    How these concatinate , depends on the compiler.
    Here these concatinate as : 00110001 00110010
    In some other compiler they may concatinate as :
    00110010 00110001
    The print statement is interpreting this as an integer (16bits) instead of two 8 bit characters because in C the character literal is defined as an int and your providing just the right number of 8 bit characters to make an int.
    If you type = ‘312’ , then the compiler would consider last two characters only because the size of int is 2 bytes in Arduino IDE.

  4. Avatar Rumroom on March 22, 2016 at 2:04 am

    Thank you so much for your video, but how can I display text on the notepad?

  5. Avatar Luigi on August 2, 2016 at 11:31 am

    Thank you so much for your video, but how can I display text on the notepad?
    I have this problem. How do I view Arduino output on the PC monitor as Notepad

  6. Avatar Robert Cohen on February 8, 2017 at 6:26 pm

    A lot of these instructions remind me so much of when I used to program in C64 Basic so many years ago. Brings back happy memories of when I was much younger.
    Love your no BS approach to teaching, it’s like being back at TAFE. Thanks!

  7. Avatar Anupam Majumdar on September 11, 2017 at 8:06 am

    Nice and elaborate post.
    I have worked with arduino and then gradually shifted to ESP boards.

    Can you write something on esp boards? Not many good tutorials are available for this boards.

    Thanks,

    Anupam,

    Physics Blogger at http://physicsteacher.in

    latest post:http://physicsteacher.in/2017/09/07/centripetal-force-facts-you-must-know-centrifugal-force-washing-machine/

Leave a Comment