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

4 minute read

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

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.

The IDE will add additional capabilities to the code editor. It will add the ability to build the software along with an integrated approach to catching and fixing the errors found while building. It also has integrated capabilities in uploading and debugging the software. 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. Its best to learn how to edit, build, upload and debug software as separate tasks before attempting to do so in a complex, integrated environment.

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.

How do I find my Serial port?

A: Use the Arduino IDE to determine Serial Port

Comments powered by Talkyard.