Arduino Hardware Basics

Summary

A discussion of common terminology of hardware used in embedded systems.

Embedded Hardware Basics

Embedded hardware is a small computational unit called a microprocessor that interacts with external electronics using pins on the chip.

Microprocessors

A CPU (Central Processing Unit) is the hardware that executes software. That software is composed of a series of "opcodes" (operation codes) each of which performs a single, very limited, operation. For example, the opcode JMP, jumps from the current location to the location named after the opcode.

A microprocessor typically is just a CPU. A microcontroller contains a CPU, some memory (RAM) and timers, registers and possibly other facilities. For example, the ATMega328P used by Arduinos contains a CPU with 124 opcodes, has 32K of Flash Memory, 1024B EEPROM, and 2K bytes of SRAM, 23 general purpose I/O lines, 32 working registers, 3 timers/counters, and other facilities.

see https://www.microchip.com/en-us/product/atmega328p about the hardware.

And see https://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf for the full instruction set.

GPIO pins

A microprocessor can execute code without interacting with the outside world. But, in general, that is not very useful to us. We need the code to interact with external electronics in some useful way for that particular project.

The opcodes have internal registers where each binary digit in that register corresponds to one of the pins on the microcontroller chip. Change the register bit from 1 to 0 or vice versa will change the state of that pin.

Those pins are called "GPIO" (General Purpose Input Output) pins to indicate they are not as signed to a specific function like UART, ISP, I2C or Reset, etc.

The other pins are dedicated for the functions as specified in the Pinout diagram. For example, for the ATmega328P pinout, see https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf

In many projects these GPIO pins are used to turn on or off some external entity like an LED, or toggle a motor's supply to make it run or turn off.

Registers

To make the use of GPIOs more convenient they are clustered into groups called registers. For example an 8-bit register can have 8 GPIO pins associated with it.

Register bits can have other uses. They can be ways to tell the microcontroller to behave in a particular way.

What is digital vs analog pin?

Some GPIO pins are digital. The can only be in two states High or Low (equivalent terminology is on or off, 1 or 0).

But pins are analog. They can accept or provide a voltage that ranges from 0V to the microprocessor's supply voltage, typically, 3.3V or 5V.

For an output analog pin, the software puts a binary integer value in a register and the microcontroller converts that into a voltage and sets associated pin at that voltage. That internal component is called a "DAC" (Digital to Analog Converter).

For an input analog pin, the microcontroller reads the voltage at that pin and converts that into a binary integer which is then available in a register for use by the software. That internal component is called an "ADC" (Analog to Digital Converter).

For example the ATmega328P has an ADC which can convert to a 10-bit number or an 8-bit number. There are 6 analog pins that can be read and converted into an integer. But it does not have a DAC, that facility must be provided by external hardware.

What is a Serial Port? UART? baud rate?

A single GPIO pin is very useful, but the ability to communicate with the microcontroller with a faster, more complex facility is very useful.

One of these is "UART" (Universal Asynchronous Receiver/Transmitter). It can be used to communicate, for example, with your PC. Older PCs had dedicated ports for these called "Serial Ports". Modern PCs have USB available. To be able to communicate using serial port communication, the low level UART protocol is converted into the USB protocol and vice versa. That way the microcontroller software can receive/transmit data using serial/UART and the PC software can receive/transmit data using USB.

One fundamental criteria for communication is how fast is it going to be done at? That is called the "baud rate". Baud is the number of times a signal changes state per second. So a baud rate of 1, means 1 bit changes per second. Typical UART baud rates much faster e.g. 115200, while USB 3.0 can achieve 10 Gbps (gigabytes per second)

- John Arrizza