Developing in C on the AVR ATmega328P: Frequently Asked Questions (FAQ)

5 minute read

Where I attempt to direct all of the questions, pertaining to Developing in C for the Arduino Uno.

How do I find my Serial port?

A: There is more than one way!

CLI methods

# identify using device
ls /dev/tty* | grep -E 'ACM|USB'

# identify using tio
tio -l

# if you have multiple devices, using tio will provide more information

GUI methods

  1. Open the Arduino IDE and go to Tools -> Port and write down the port which has (Arduino Uno) after it. If you aren’t using an Uno, it might not identify itself. Which means you might have to guess, or unplug your board and see which one goes away.
  2. Open CoolTerm, it will provide a drop-down of devices which can be connected to by, CoolTerm.

Why is learning C important for the Arduino Uno?

A: C is the ideal combination of a common language and a language which is “close” to the hardware. For example, the AVR assembly language allows writing directly to the hardware (the best example of “close”), except it is not commonly known or easily understood. On the other hand, Python is widely known and easily understood, however, due to it’s requirement to be compiled on-board, it is too large to fit into the memory of the ATmega328P (the microcontroller used by the Arduino Uno). The Arduino approach is to use C++, however, C++ is a little more abstract and requires more memory than C. It’s a good compromise for teaching, however, it is not the best language for embedded development.

Another very good answer is that many universities expect a student to understand and to have programmed in C. They don’t consider programming in the Arduino C++ framework sufficient.

I’ve installed the tool chain, tested it and everything works, however, I forgot how to get started!

A: Video:Setup Your Screen

What is the best way to open my code in my code editor?

A: Video:Editing Best Practices

What is the difference between the “command line” and the “terminal”?

A: Very little, the two terms describe a similar situation, and tend to be used interchangeably. Technically, the terminal is an application while the command line is an operating environment. The terminal is a common way of describing how to access the command line environment. There are multiple versions of the terminal application, depending on your operating system:

  • Windows: Terminal, cmd.exe
  • macOS: Terminal, iTerm, Warp
  • Linux: Konsole, Terminator, GNOME Terminal

Think of the command line as a lower level access to your computer. There are quite a few operations which either don’t have a graphical user interface (GUI) equivalent or they are more difficult in a GUI application. For example, deleting system files, changing folder permissions or changing specific behaviors of the operating system are readily available in the command line environment.

What is the difference between a code editor and Word or Google Docs?

A: A code editor is designed specifically to provide an efficient method of developing software. It will offer syntax highlighting (color-coding for a particular computer language such as Python, C, C++, Rust etc), an embedded file manager to make it easy to navigate folders of code, specific command capabilities such as commenting lines, indenting lines and showing invisible characters.

Word processors such as Microsoft Word and Google Docs are designed to facilitate writing reading material such as documents, articles or stories. These applications will insert invisible characters and content which will prevent a file from being read as a computer program.

What is the difference between a code editor and an Integrated Development Environment (IDE)?

A: A code editor provides the fundamental tasks to developing code. It may also offer a console to perform a limited number of terminal tasks. It’s principal function is to edit software, however, it will add the ability to build the software along uploading the hex file to an embedded microcontroller. Both Sublime Text and VS Code excel in these capabilities.

The IDE will add additional abilities to the code editor. Specifically, it adds sophisticated debugging and professional extensions. While all of this integration is valuable, it comes at a cost of complexity. Configuring and using an IDE properly requires significant knowledge of the desired language, development environment and IDE capabilities.

I recommend learning how to code before you spend a lot of time, learning how to use an IDE.

What is the best way to get the Lab content?

A: Developing in C for the ATmega328P: Using Git

What is the difference between 10C Labs for Arduino and AVR_C

A: The Labs are a superset of the AVR_C content. The Labs contain the same version of the AVR_C code, however, the Labs also contain eductational content for learning how to program the Arduino Uno in C. The README for AVR_C and this page: AVR_C Library Functions will remain identical, they contain important documentation as to the functions of AVR_C.

I’ve been told there is a “new” version of code on Github, what do I do?

A: The important thing is that you used the dev folder to do your development and not the template folder. If so, the process is simple:

# in your terminal application
cd Labs_10C_Class
# make sure you haven't changed anything outside of the dev folder
git status
# if so, you will want to save those changes outside of the 10C_Class folder
# get the latest from GitHub
git fetch origin main
# have it add all the changes to your folder
git merge origin main
# You might need to copy new template files to your dev folder
# I recommend you do this using your GUI file manager, Finder on Mac, Explorer in Windows

I don’t understand how to use analogWrite, or digitalRead, or “functionname”.

A: Look for a similarly named folder in the examples folder. For example, there is a folder called analogRead in the examples folder. Run make flash, in that folder to upload the example to your Uno then examine the code and use it to use the same function in your code.

The functions were designed to work, in a similar if not, identical manner in which the Arduino functions worked. It might also help to reference the Arduino Language Reference.

Comments powered by Talkyard.