Developing in C for the ATmega328P: Raspberry Pi and VS Code Setup Part 2

Where I demonstrate how to use VS Code on your PC to develop code on your Raspberry Pi for the Arduino Uno (ATmega328P).

Introduction#

Now that you have the best setup for developing code for the Arduino Uno, how do you use it?

One program for both#

You will be using VS Code on your computer (Mac or Windows) to interact with the Raspberry Pi. It provides both the code editor as well as the terminal to perform administrative exercises along with CLI applications like a serial monitor (tio).

Developing in C for the ATmega328P: Raspberry Pi and VS Code Setup Part 1 (Bookworm)

DEPRECATED As of December 2025, the instructions have been updated for Trixie,. I setup the Standard C tool chain for the ATmega328P on the Raspberry Pi, however I use VS Code on my Mac (or Windows) for development and connect via SSH to the Raspberry Pi.

Note: There is a new, “easy” version is due to using Raspberry Pi OS Trixie, which now provides fairly up-to-date tools for the AVR microcontollers. This “easy” version is shorter and easier than the build method (Version 2 below). For those that wish to build the latest tools, use this version.

Developing in C for the ATmega328P: Make, Makefile and env.make

Updated: Where I discuss a simplified approach to development automation using make in AVR_C, add the ability to use Arduino tools.

Introduction#

The previous explanation provided the Makefile from Elliot Williams and can be viewed here. I have made several significant changes to the file since:

  • moved the device programming setup to env.make at the root folder
  • use one Makefile at the root folder then use “include ../../Makefile” in the file makefile, which is in each of the examples in the examples folder
  • added a DEPTH variable to each local makefile (the one in the examples folder)
  • removed some of the targets to simplify the file
  • added additional targets which help explain the make options, including make help
  • Added two variables, which allow you to use either the Arduino toolchain or the avr-gcc toolchain, OS and TOOLCHAIN

Here are detailed instructions as to how to use make, the Makefile and env.make to configure and execute your development process.

Developing in C for the ATmega328P: Buffer Overflow

Where I use examples from “The C Programming Language”, Kernighan & Ritchie, to demonstrate string copies, using pointers and how to check for buffer overflows.

Introduction#

I find it very helpful to periodically review/read “The C Programming Language”, Kernighan and Ritchie (K&R). In this past review, I ran across some examples provided on pages 105-6 (Second Edition) as to using pointers to copy strings. There were 4 examples provided, with the last commented as “the idiom should be mastered”, which is an implication of “this is a programming best practice”. Perhaps, for the code in question is quite simple and extremely powerful, that said, it leads to the issue of buffer overflows, for which I provide a mechanism to resolve.

Serial Applications for Embedded Development

Where I discuss various serial monitor applications and why I believe CoolTerm is the best one.

Introduction#

The serial port is an invaluable, if not mandatory tool, for developing programs in embedded computing. Given the popularity of software development for embedded computers, one would think there would be a clear answer or solution. For several years, I wasn’t able to determine the best solution. However, after more work on my part to understand a specific solution, I can conclusively say use this multiplatform, free solution: CoolTerm

Developing in C for the ATmega328P: Using a Serial Monitor

Updated: Where I describe the different options for using a serial monitor and the serial software in AVR_C and change my recommended programs.

Introduction#

CoolTerm appears to be malware on some systems and PuTTY, its important to install from the proper site, has better security. PLEASE ENSURE YOU DOWNLOAD IT FROM THIS SITE ONLY: https://freeware.the-meiers.org/

For macOS, I do likeSerial, however, this is a $40 serial program. For free, the solutions is tio, which can be easily installed using Homebrew or CoolTerm.

Developing in C for the ATmega328P: Using the GNU Linker to Enhance printf()

Where I describe how to use the GNU Linker wrapper capability and variable arguments to enhance printf() for better debugging.

Introduction#

This recent post fascinated me. It describes a feature of the GNU linker called wrapping which allows you to replace an existing symbol (command) with a new version. The example describes adding a timestamp to printf(). While, for me, this might be a solution looking for a problem, I really liked the idea. And at the very least wanted to add the concept to AVR_C.

Developing in C on the RP2040: Exploring Blink

Where I develop multiple versions of blink to better understand the timing API and bit-setting hardware API in the Pico C SDK in learning how to program the Pico in C.

Sources#

Introduction#

The Pi Pico family of microcontroller boards have an incredible price/performance ratio. Ranging in price from $4 to $10, the Pico can provide a low-cost, high-performance dual-core Cortex M0-based board with or without wireless or installed headers (for easy breadboarding).

Developing in C on the RP2040: macOS

Updated: Feb 27, 2023: Where I install the tools and frameworks necessary to develop code in C on the RP2040 on a macOS platform.

Sources#

Introduction#

Just as I did for the Linux platform, in this entry I’ll work through the steps required to be successful with developing code in C for the RP2040 on the Mac. Updated: This entry has been tested on both an Intel 2018 MacBook Pro and a M1 2020 Mac Mini.

Developing in C for the ATmega328P: I/O Ports

Where I describe how to improve the performance of your programs by accessing the input/output (I/O) ports on the Arduino Uno, natively.

Introduction#

The Arduino framework and Uno hardware has performed an admirable job in abstracting much of the complexity of the ATmega328P into something which is easier to understand. This approach works well for a beginner in microcontrollers and embedded C programming. Once you begin to understand how the ATmega328P works, its not unusual to find the Arduino simplification is holding you back.