Part 6 - The Arduino Uno Board
To make the prototyping process flow more smoothly, I will introduce the components, pins and interfaces on the Arduino Uno board first. Everything here also applies to the Nano except where noted.
The Arduino Uno is a microcontroller board based on the ATMega328p chip. It runs at 16Mhz and has 32k of SRAM (where your program and bootloader are stored), 2k of RAM (where temporary program variables are stored), and 1k of EEPROM (often used for storing seldom-changing values). It also has voltage regulators for 5v and 3.3v, a chip for the USB link to your computer, a few onboard LEDs, and a reset button.
The Uno has 20 GPIO (general purpose input/output) pins, as well as power and other pins. They are arranged in three major groups: Analog In A0-A5 (with extra pins A6-A7 on Nano), Digital 0-13, and Power (3v, 5v, Gnd, Reset). Remaining pins deal with reprogramming the on-board bootloader, but we won’t need those. Note that many pins can have multiple uses, as we will see shortly.
Analog Pins - A0-A5. These are used as analog inputs with a 10-bit analog-to-digital (A/D) converter. Each pin takes an input varying between 0 and 5 volts and converts it to an integer value between 0 and 1023. Once this conversion takes place, we can act on these integer values with program code.
What are they good for? Well, beside being able to input telephone-quality audio, they are useful for reading sensors that output variable voltage, such as a photodiode, an EMF detector, or a doppler radar. They can also be used (except for A6 and A7 on the Nano) as digital pins.
Digital Pins - marked as 0-13 on the Digital bank (I’ll call them D0-D13). When used as inputs, these pins accept a voltage of 0v or 5v. Internally (in your code) this input is represented by two possible values: Low or High. When used as outputs, they output only 0v or 5v - nothing in between. This 0v/5v (low/high, off/on) scheme is the lingua franca of all digital computers - the binary on/off switching that makes computers function. So, these pins are useful for communicating with other digital components, like displays, sensors, and SD cards. They are also used for reading switchs (which can only be on or off).
When used as outputs, digital pins can light individual LEDs or switch something on or off. But they also have another trick up their sleeve: pulse width modulation (PWM). Using PWM, you can fade an LED up or down, control the speed of a motor, or even output audio. How can this be done if a digital pin can only output 0v or 5v and nothing in between? The answer is speed. When a pin is switched from low to high and back very quickly, the output looks like a wave (specifically, a square wave). By changing the relative lengths of the on and off states (the pulse width), the output emulates a particular voltage, anywhere between 0v and 5v. Not all digital pins can do PWM - the ones that can are marked with a ‘~’.
Interfaces (aka Busses)
GPIO pins are used in groups to form the bus interfaces that components depend on to communicate:
Serial Peripheral Interface (SPI) - this is a relatively fast 5 wire bus used for serial communication. It may have one Master device (the Arduino) and one or more Slave devices. Our TFT display uses this bus - an SD reader is a typical second slave, but juggling multiple SPI slaves can be tricky and I won’t cover that. The faster, ‘hardware’ version of SPI requires specific pins (D11 and D13) to be used for two of the lines. We will use two additional digital pins for the bus, making sure to specify these in the code. We can avoid using the 5th line through a wiring trick and save ouselves a digital pin.
I2C (or IIC) - the I2C interface is a medium speed two-wire serial bus. It is much more flexible and user-friendly that the SPI bus, and many if not most commercial sensors use it. The I2C bus can have up to 128 devices, and each device is required to have a unique address (some devices come with a changable address, others don’t). The SDA line (pin A4) carries the data, and the SCL (pin A5) line transmits a clock signal to keep everything synchronized. Note that this deprives us of two analog inputs. Even using the Uno’s dedicated SDA/SCL connectors, we can’t avoid this, but so many sensors use I2C that it’s a worthwhile trade-off.
Serial Rx/Tx - pins D0 and D1 are used for bi-directional serial communication. This usually consists of strings of text commands or data, and the most frequent use is with a GPS or another Arduino. The same two pins are used by USB to program the Arduino and this presents a small problem: you can’t have any circuits attached to these pins while uploading (a small dpdt switch can solve this). People generally avoid using these pins for GPIO but it can be done.
There is a USB connector at the left edge of the board, and also a 2.1mm barrel connector for external power greater than 7v DC - battery or AC adapter. (Other power options will be discussed later.)
The Uno’s pins have header strips (aka sockets or female connectors) already soldered in place (the Nano usually does not). This makes prototyping easy using jumper wires to connect to a protoboard. There are also solder holes next to each header socket. While we’re on this subject, there are generally four ways to connect things to a microcontroller board:
- Jumper cables - easy on the Uno and others with pre-installed headers
- Wires - with solder (or sewing needle for Adafruit’s Flora system - I kid you not)
- Proprietary cable systems - for example, Qwiic by SparkFun (quick-connect I2C)
- Shields/Hats - pre-wired sensor boards that piggy-back onto microcontroller boards - unique to each platform/board
Our project uses mixture of jumpers and soldering for prototyping, and soldering for final construction, but as you see there are other options.
Ready To Go
Well, that’s the Uno in a nutshell. There are many other settings, features, and techniques that you can use to achieve more performance and flexibility, and of course there are more advanced Arduino boards with more memory, speed, and GPIO pins. But this is enough info for us to start our prototype.