Skip to main content
Engineering LibreTexts

18.1: Introduction

  • Page ID
    35882
  • Welcome to Bits & Pieces (catchy name, eh?). This sequence of chapters delves into a variety of aspects of programming the Atmel AVR ATmega 328P microcontroller via the Arduino Uno board and associated libraries. The focus is on IO (Input-Output) programming. Specifically, we’ll be looking at ways of coding the interface between the Uno and external circuitry. This is code-only; the hardware aspect is dealt with separately in lab. We will be exploring the IO code used to read to and write from digital and analog ports so that we can perform tasks such as reading the state of switches, lighting LEDs, reading continuously variable data such as force or temperature, timing or counting events, and controlling devices such as motors. The simplest way of performing these items is via the library functions that come with the Arduino system.1 Sometimes, though, these functions are not fast or efficient enough, or we need to use a non-Arduino platform. For those reasons, we’ll be diving down into the library functions themselves to see how they work. To the uninitiated, scouring through library source code can be a daunting task, so think of Bits & Pieces as a series of guided tours covering major parts of the library. Granted, it’s probably not as much fun as, say, a series of guided tours of tropical islands of the South Pacific, but you can only get so much for your tuition. And while there is little doubt that there might be interesting uses for embedded controllers on said islands, a field trip is right out.

    The first things we need to examine are some commonly used include files. Recall that include files (also known as header files, i.e., the ones that end in “.h”) are used to collect up function prototypes, references to global variables, structure definitions, and those wonderful (and sometimes confusing) #defines. Remember, the C language is fairly “skinny” and the functions that we call are either written by us or come from a library. Prototypes for the functions are found in the library’s header file. An interesting twist to this is that some so-called library functions aren’t functions at all. Instead, they are simply inline expansions via #defines. Many different libraries are available, so to make life even easier, systems often include a “master” include file that contains directives to reference other include files (boy, those professional programmers are constantly looking for ways to make every keystroke count).


    1. Complete details on the library and lots of other goodies including example code can be found at www.arduino.cc. The Reference page in particular will prove useful.
    • Was this article helpful?