Where I setup the Standard C toolchain (avr-gcc) for the ATmega328P on macOS using homebrew.
After performing these steps on multiple machines, I’ve found it best to install and test using the Arduino IDE before going forward with the installation instructions below. This will reduce the errors to something more manageable and having the Arduino IDE is handy for its Serial Monitor as well it provides an easy method to which port the Uno is connected.
Where I setup the Standard C toolchain for the ATmega328P for Linux, with specific emphasis on the Raspberry Pi.
Note: If you have a GUI interface to your Linux PC, by all means, install the Arduino Legacy IDE (1.8.19). In the steps regarding the Raspberry Pi, the interface will be the terminal and can’t use the Arduino IDE GUI. After performing these steps on multiple machines, I’ve found it best to install and test using the Arduino IDE before going forward with the installation instructions below. This will reduce the errors to something more manageable and having the Arduino IDE is handy for its Serial Monitor as well it provides an easy method to which port the Uno is connected.
Updated: Where I describe the optional steps to setup the Standard C toolchain for the ATmega328P on Windows, Linux, or macOS using a command line-based approach.
In my efforts to continue to refine how to develop Standard C code for the AVR family of microcontrollers, I’ve determined using a Raspberry Pi along with VS Code can provide the optimal experience.
The Raspberry Pi OS is a reliable and steady operating system on which one can build the latest GCC tools for developing code for any microcontrollers in the AVR family. This includes the latest in the DA, Tiny or DD families.
Where I use an example project from avr-gcc to better understand how to program the ATmega328.
In the previous entry, I wrote a C equivilent to the Arduino analogWrite(). The entry demonstrates the fundamental method of getting the ATmega328 to perform, is to program the registers. From here on, we’ll continue to expand on this approach.
Where I take the next step in developing PWM code in C for the ATmega328. This time, I create a new analogWrite() in C.
In the previous entry, I demonstrated how you could program the ATmega328 to provide a fast PWM signal on pins 5 and 6. In this entry, I’ll take the example a bit further by adjusting for all 6 pins which can provide a PWM signal. (Those marked by a “~” on the Arduino UNO.) I’ll also continue to refine the table which documents how to program the 6 pins.
Where I take the next step in developing code in C for the ATmega328. This time, I review the PWM functionality of the ATmega328.
Pulse-width modulation (PWM) is a useful technique for controlling DC motor speeds, LED intensity and creating analog waveforms. The idea is to modulate (or change) the width of a digital signal (a pulse) to deliver a varying amount of voltage. The change is called the “duty cycle”, it will range from 0-100%, and the high the number, the greater the voltage delivered. PWM is valuable as it allows you to use less power to keep motors running or make LEDs bright. If the concept remains foreign to you, I recommend you read the noted sources above before going forward.
Where I use a detailed analysis of the ATmega328P datasheet to develop C code using the C toolchain. Yes, another look at the blink program!
You’ve installed the tool chain, you’ve tested it and added automation. This means you are now ready to begin the process of learning how to program an embedded microcontroller! You might have thought, that was what you were doing with the Arduino. Not quite, you were programming a specific embedded microcontroller board with a specific programming framework.
Where I begin the process of developing in Standard C (and only C) on the Arduino Uno (also known as the ATmega328P).
This series is designed to help someone who has been using the Arduino framework, however, desires to use only the C Language. It covers adding the toolchain to your system of choice, executing the toolchain on examples and (possibly) advancing the ability to debug using a hardware debugging tool. Or stated more formally:
Where I explain the issues which impact developing C/C++ code on the RP2040.
There are three fundamental steps one must take to fully develop C/C++ code on the RP2040. Both the Raspberry Pi “Getting Started with Pico” known as the Guide from here on and this blog utilize this approach:
For each of the platforms, there is a level of complexity to accomplish each step. Its important to understand that the tools that exist to accomplish cross-compiling and linking C/C++ for an embedded microcontroller are designed for Linux. Therefore, the closer a system “looks like Linux”, the easier it is to follow the three steps. This isn’t a problem. It is simply something to understand and account for. Specifically, the level of difficulty of the three steps in each operating system is:
Where I begin to develop code in C on the RP2040 in the Windows environment.
If you haven’t read it, please read Read This First… before you continue.
As I have said before, I do not like to use VS Code, nor do I believe that it is a good tool for students beginning to learn how to develop embedded C. My approach will be to follow that of Shawn Hymel’s without the VSCode part as well as what has already been published via the Guide. In the place of VS Code, we will use Notepad++.