Where I describe the struct, buttons[] and how to use it to debounce and check for button presses.
Describing buttons[] is slightly different than describing a function such as analogWrite() and digitalRead() as buttons[] is a struct. The goal of this entry is to provide sufficient instruction as to how to use buttons[]. If you wish to understand more as to how to debounce a button, please review the links mentioned at the end of this entry.
Where I describe the function - digitalRead().
The function digitalRead() is analogous to digitalWrite(), in the sense, it takes a pin number as a parameter and as compared to setting its value, it returns the pin’s value. The value will either be a HIGH, indicating the value of the pin was approximately 5V or it will be LOW, indicating the value is approximately 0V or GND.
Like digitalWrite(), it also requires using pinMode(), however there are two choices to use, INPUT or INPUT_PULLUP. For the most part, its best to use INPUT_PULLUP as it will have the least chance for error. What this means, is that when a pin is in INPUT_PULLUP, its value will always be HIGH unless it is specifically pulled low. For example, pressing a button connected to ground would pull the pin to GND or LOW. When using INPUT, you will need to ensure the device connected to the pin, will either be at 5V or GND.
Where I describe the function - pinMode().
The function, pinMode() is one of the most important and one of the most forgotten of all of the Arduino framework. It is important, as it sets the function of the pin in question. And when its forgotten, hours of debugging may occur before the programmer realizes “the program works, I forgot to setup the pin”.
The Arduino Reference: Digital Pins also has a good description as to how pins and pinMode() works.
Where I describe the function - digitalWrite().
The digitalWrite() function is a basic building block of using a microcontroller. The function will either raise the value of an output pin to 5V or it will lower it to GND (0V), and in doing so will provide current to drive an LED, a motor or any device which requires current.
The Arduino Reference: Digital Pins also has a good description as to how pins and pinMode() works.
Where I attempt to gather in one place, all of the errors found while building (compile/link/locate) and uploading code to the Uno.
Where I describe the functions for serial input/out - puts(), getchar() and printf().
The serial input/output capabilities of C are vastly superior to those in the Arduino framework. In order to communicate via the USB serial cable, you must run a serial monitor program such as the Arduino Serial Monitor, CoolTerm, or moserial. See this page for more details.
Currently available are:
buffersize
number of characters or until CR
has been entered. Returns the number of characters read.While the serial I/O capabilities are polling and not interrupt-based, I’ve found the baud rate can still be set quite high. This is of value when you are attempting to transmit a signficant amount of information such as in examples/pointers. I have successfully set the baud rate to the following speeds in env.make:
Where I describe the function - analogWrite().
While analogWrite can be an easy function to use, its not easy to initially understand. This stems from a couple of reasons, first, its mis-named in that the function is not doing anything from an analog perspective and second, it uses a concept called pulse-width modulation (PWM), which in itself is difficult to understand.
Lets start with explaining pulse-width modulation. Here is a video where a pulse is being modulated:
Where I describe how to use the Library functions in AVR_C.
This page describes where to find specific functions for programming an AVR microcontroller in Standard C using functions similar to the Arduino Language Reference. In this case, the AVR_C framework consists of:
The Standard C Library is provided by AVR Libc. This library is incredibly important as it provides the ability to develop code in Standard C for the AVR family of microcontrollers. It has all of the functionality you would expect if your were using the a Standard C book such as The C Programming Language Kernighan and Ritchie (available in PDF and paper copy). I recommend having a link to the online manual open while developing code.
Where I attempt to direct all of the questions, pertaining to Developing in C for the Arduino Uno.
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
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.
Where I describe the process of developing code for the Arduino Uno(AVR ATmega328P), specifically, the build process.
The middle three steps compile/link/locate are typically called the build process, which can simplify the five steps to three:
For a detailed and very worthwhile description of the three steps in Build, I highly recommend this page, Compiling, Link and Locating: Barr Group.
The image is a typical start-up build sequence, I need to cd three times, to get into the specific folder. Once there, I use make clean to ensure I have a clean start (source code and makefile only) then I execute a make flash.