Developing in C for the ATmega328P: Using a Serial Monitor

3 minute read

Where I describe the different options for using a serial monitor and the serial software in AVR_C.

Introduction

Serial communications is a great low-cost way to communicate with the Uno. The USB cable which supplies power is also capable of communicating with the microcontroller. Each operating system has a variety of applications capable of providing serial communications.

All Platforms - Arduino IDE Serial Monitor

Arduino IDE Serial Monitor works for communicating with the Uno. As stated before, installing the Arduino IDE is great for debugging any issues between your PC and the Uno.

I recommend using the Serial Monitor initially to test the Uno serial connection. You start the monitor by one of the following options:

  • Arduino IDE -> Tools -> Serial Monitor
  • Shift-Control/Command-M
  • Clicking the icon in the upper right corner of the IDE. (See image below)
Arduino IDE Serial Monitor Icon

Arduino IDE Serial Monitor Icon

Large Version to see detail

Once the Serial Monitor is running, it needs to be setup properly. Make sure the correct port is in the upper left-hand corner, the “No line ending” is selected and the baud rate is 9600:

Check port, line ending and baud rate

Check port, line ending and baud rate

Large Version to see detail

The issue with the Serial Monitor is that it needs to be closed, every time you want to upload code to the Uno. If it isn’t closed, you will have an error such as this one:

make flash
avrdude -c Arduino -p atmega328p -F -V -P /dev/cu.usbmodem4201 -b 115200 -U flash:w:main.hex
avrdude: ser_open(): can't open device "/dev/cu.usbmodem4201": Resource busy
avrdude: opening programmer "Arduino" on port "/dev/cu.usbmodem4201" failed

avrdude done.  Thank you.

make: *** [flash] Error 1

Using CoolTerm

Closing Serial Monitor and re-opening it, every time you wish to upload to the Uno, can become a bit tiresome. To resolve this issue, CoolTerm is a very good serial monitor which has a Connect/Reconnect button to make it easier to use.

CoolTerm Page is available for all three platforms, macOS, Linux and Windows. Here are the Install Instructions by platform:

Windows

Steps to install or to watch video:

  1. CoolTerm - Download Win
  2. Right-click and “Extract All” to folder in Downloads folder
  3. Double-click on extracted folder, then again to reach CoolTerm.exe
  4. Click on CoolTerm.exe and note the Manage Application Tools at the top of the Explorer Window
  5. Click on Application Tools then Pin to TaskBar (see image)
Click on Coolterm.exe, then Application Tools then Pin to Taskbar

Click on Coolterm.exe, then Application Tools then Pin to Taskbar

Large Version to see detail

macOS

Steps to Install

  1. CoolTerm - Download macOS(Intel/ARM)
  2. Download macOS file then in the Downloads folder, double-click on it
  3. Double-click on the .dmg file to mount it
  4. Click on the mounted dmg file in Finder
  5. Drag CoolTerm to Applications
  6. Open the Applications folder and right-click on CoolTerm
  7. Select Open then click on Open, sometimes you have to do this twice…to open CoolTerm

Linux

The Cool Term developer admits the application isn’t “official” for Linux, so I would suggest other possible serial applications such as moserial. I have used moserial extensively and found it to work very well.

Installation of either application is best from your typical install method, “sudo apt install moserial” in the command line or via Software Center on Ubuntu or Pamac on ArchLinux(Manjaro).

Configuring Cool Term

Click on Connection -> Options and select the following: Serial Port

  • Port: port you have been using for the Uno.
  • Baudrate: 9600
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1 This should be all of the configuration, you will need to do.

Resources on Serial Communications

Comments powered by Talkyard.