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.
I used screen command but after that Arduino IDE serial monitor didn’t work well like before using screen command. I don’t know how to fix it
You can’t have the screen command and the Serial Monitor working at the same time, but other than that, they should not affect one another. Does the baud rate set in the Serial Monitor still match your sketch? What is going wrong?
I tried it but it doesn’t show anything in MacOS Ventura 13.2. It seems that what I type in the terminal goes into the Arduino through the Serial.available() and Serial.read() functions, but nothing is printed on the terminal from Serial.println().
Any ideas, about what I could be missing?
I am currently running macOS Ventura 13.3.1. I don’t know how you are uploading your code to the Arduino, but I could not get printing to work in both the Arduino IDE’s Serial Monitor and the screen utility simultaneously. It had to be viewed in one or the other.
I used the following simple program to test printing to the serial port.
Since I wrote this Quick Tip, Arduino has included serial port monitoring capability directly into the arduino-cli utility. So instead of using
you can now use the following
and just press CTRL-C to exit. I believe this is a better experience.
Hi John,
Thanks for this worthwhile article!
I was running ‘screen’ on my Ubuntu 22.04.3LTS as a replacement for the Serial Monitor. Main reason was that I wanted to do Escape sequences for cursor control. That does not work in the Serial Monitor, but it works in screen.
On your suggestion I tried Arduino-cli (SNAP version 0.35), but ran into a problem:
XNB-laptop:~$ arduino-cli board list
Port Protocol Type Board Name FQBN Core
/dev/ttyACM0 serial Serial Port (USB) Adafruit Feather M4 CAN (SAME51) adafruit:samd:adafruit_feather_m4_can adafruit:samd
The board I want to monitor is there (same board/port as with screen)
However, when I want to use the monitor this goes wrong:
XNB-laptop:~$ arduino-cli monitor -p /dev/ttyACM0 -c baudrate=115200
Monitor port settings:
baudrate=115200
Port monitor error: listen tcp 127.0.0.1:0: listen: operation not permitted
I have been looking everywhere but can´t find any solution. Port settings cannot be the problem since the same port works fine with the IDE Serial Monitor as well as with screen.
Any suggestions??
Hmm, that is a strange one. Sorry, I don’t have any suggestions. Try asking your question on the Arduino Forum.