Arduino basics


Martin McBride, 2020-07-04
Tags arduino basics
Categories hardware arduino

"Arduino is an open-source electronics platform based on easy-to-use hardware and software"

Arduino official website

The Arduino is a great platform for experimenting with computer based electronics. An Arduino is a low cost microcontroller based boards, that can be programmed in a C style language, using a free programming environment that runs on a PC, Mac or Linux system.

After downloading the program via a USB link, the Arduino can be disconnected from the PC and run as a stand alone system.

Arduino boards have a large number of I/O pins that can be used for digital or analogue input and output. These can be used to connect to a large variety of sensors, displays and actuators for building projects that interact with the real world.

There are a whole family of Arduino boards, with different capabilities. The Arduino UNO is the most commonly used.

Hardware

Arduino boards are based on the ATmega series of microcontroller chips.

ATmega chips are low cost microprocessors with on chip memory and IO capabilities. Since everything is built in to the chip, very little additional hardware is required to create a working computer system. The Arduino UNO board holds a crystal oscillator to provide the system clock, a power regulator to provide the 5V the chip needs, and some serial interface circuitry to allow it to be programmed over a USB connector.

The chip contains three types of memory - flash memory that holds the program code, sram that provides the working memory to store program variables etc, and eeprom which is non-volatile and can be used to store values that need if the board is powered off.

Programming

The Arduino comes with a free, open source IDE that allows you to program the board. Arduino programs are called sketches, but the used language that is very similar to C.

The IDE compiles the sketch to machine code that can run on the Arduino.

The Arduino board comes pre-programmed with a bootloader, that has already been stored in the flash memory of the ATmega chip. After compiling a sketch you can download it to the Arduino. To do this, the IDE communicates with the bootloader to send the code to the Arduino over the USB cable. The program is stored in the flash memory, which is non-volatile (similar to a memory stick), so the program will still be there even if you switch the Arduino off than back on again.

Once you have downloaded your program, you can disconnect the Arduino from the PC and use it as a stand alone device.

Variants

There are several variants of the Arduino, the main ones being:

  • UNO - the default, basic Arduino.
  • Mega - this uses a different ATMega chip, which has more memeory and more IO pins. The board is also a little larger (and more expensive).
  • Leonardo - similar to the UNO, the main difference being that it supports USB (the UNO has a USB connector but it only uses serial communications so it can't emulate a USB device).
  • Nano - similar to the UNO but in a much smaller package, making it suitable to embed in very small devices.

There are many other less commonly used variants, including a few with more powerful processors, or with built in features like Wifi or Bluetooth.

I/O

All Arduinos have a set of IO pins. There are 4 modes:

  • Digital input - an input that can accept a true/false value. For example it can be wired to a switch, so the Arduino can tell if the switch is open or closed.
  • Digital output - an output that can be either on or off. For example it can be used to light and LED inidcator.
  • Analogue input - an input that can sense a varying voltage. That can be used with various sensors, for example temperature sensors. For the UNO the input has a 10 bit resolution and can read 15k samples per second.
  • Analogue output - an output that can create a varying voltage. The output uses pulse width modulation.

Processing capabilities

Most Arduino boards use 8 bit microcontrollers clocked at 16MHz.

The UNO has 32KB of flash memory, 2KB of RAM and 1KB of EEPROM, other variants have a little more. The amount of memory cannot be increased - unlike a typical CPU, a microcontroller chip can't access external memory.

Clearly an Arduino doesn't compare with, for example, a Raspberry Pi in terms of computing power. But that is because they are very different things. A Pi is a general purpose Linux computer that can be used as a desktop PC, that just happens to be built quite cheaply on a small board.

A microcontroller is very cheap (a clone UNO is a tenth of the price of a Pi), consumes very little power (a Nano can run for a long time on batteries), and is very easy to program down to the bare metal. For example, you can set up an interrupt on an Arduino that will happens immediately one of the input pins is set. You could do some processing (checking some other inputs, doing a simple calculation, and setting some outputs in response) and the whole thing would be done within a few microseconds of the interrupt pin being set. And it would only take a few lines of simple code.

The equivalent thing on a Pi might take many milliseconds, or even seconds, because Linux might be busy doing something else at the time. You could speed it up by writing a driver, but that really is quite specialised and difficult coding and even that would not be as fast as the Arduino.

Shields

A shield (similar to a Raspberry Pi hat) is an extra board that plugs in on top of an Arduino to give extra capabilties. Common hats are aviable to add USB, Wifi, SD card interface, relay or motor control, etc.

Power

Most Arduinos can be powered via their USB port.

The UNO, Mega and Leonardo boards also have a power jack, and can be powered by a 7V to 12V (such as a mains adapter or battery). The smaller boards don't include a power jack but most can still be powered by a 7-12V source.

Copyright (c) Axlesoft Ltd 2020