Electronics Software Development

Quick Tip: Using The Screen Utility To View Arduino Serial Output

Quick Tip Graphic
Written by John Woolsey

Skill Level: Intermediate

The Arduino IDE is the basis for almost all Arduino based programming and board management. The built-in Serial Monitor allows us to view serial output from the attached board.

With the advent of the arduino-cli command line utility, people can now use their own trusted source code editors for developing their sketches and the arduino-cli utility for compiling and uploading those sketches to their boards. One drawback to this approach, however, is the inability to view a sketch’s serial output while the sketch is running. The screen command line utility comes to the rescue. This utility is available on most macOS and Linux based systems.

Note, if you are not yet familiar with the arduino-cli utility and want to give it a try, please see the Using The Arduino Command Line tutorial and the Arduino Command Line Cheatsheet for assistance.

Before using the screen utility, we first need to retrieve some information. The first is the serial port to which your Arduino board is attached. This is accomplished by running the following command to list your system’s available serial ports both before and after plugging in your Arduino board and seeing which one was added.

$ ls /dev/tty.*

The /dev/tty.usbmodem14202 port appeared on my Mac with an Arduino Uno WiFi Rev2 attached.

The second piece of information we need is the baud rate (number of bits per second) of the serial connection to the board. This is specified within our sketch with the Serial.begin(9600); statement when printing serial output is utilized. The 9600 argument, in this case, is the baud rate. You may use other baud rates, e.g. 115200, but just make sure you know which rate is actually being used or you will see strange characters in the serial output when they don’t match.

We now have all of the information we need and are ready to see the screen utility in action. Compile and upload a sketch to your board using the arduino-cli utility. This should probably go without saying, but make sure your sketch actually does print something using the Serial.println() function.

Open a terminal window and attach the screen utility to your board’s serial output with the following command by replacing the <port> and <baud> fields with the actual information retrieved previously for your setup.

$ screen <port> <baud>

In my case, this becomes

$ screen /dev/tty.usbmodem14202 9600

Once connected, you should see your sketch’s serial output being printed to the screen. Not bad, eh?

To disconnect the screen utility, press CTRL-a followed by CTRL-\ and then press y at the prompt asking if you really want to quit.

The screen command line utility can be quite handy for viewing serial output when we want to use our own code editors. With it, I no longer need to copy code into the Arduino IDE just to use the Serial Monitor.

By the way, if you are on a Windows system, I understand a terminal program, such as Putty, should provide similar functionality to the screen utility.

About the author

John Woolsey

John is an electrical engineer who loves science, math, and technology and teaching it to others even more.
He knew he wanted to work with electronics from an early age, building his first robot when he was in 8th grade. His first computer was a Timex/Sinclair 2068 followed by the Tandy 1000 TL (aka really old stuff).
He put himself through college (The University of Texas at Austin) by working at Motorola where he worked for many years afterward in the Semiconductor Products Sector in Research and Development.
John started developing mobile app software in 2010 for himself and for other companies. He has also taught programming to kids for summer school and enjoyed years of judging kids science projects at the Austin Energy Regional Science Festival.
Electronics, software, and teaching all culminate in his new venture to learn, make, and teach others via the Woolsey Workshop website.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.