Introduction

Arduino is a microcontroller abstraction platform with a number of royalty-free, inexpensive microcontroller board models, an easy-to-use C/C++ programming tool, and a large community of users of all ages. A microcontroller is well suited for time-critical and/or power-efficient control of motors, and for sensor fusion. Arduino boards are thus suitable for powering the state agent of a robot.

The typical Arduino board is based on an 8-bit Atmel AVR microcontroller because those are cheap and offer sufficient computing performance for most applications. There are also boards with faster, 32-bit processors based on AVR32 or ARM Cortex-M, like the Teensy.

According to Hernando Barragán, Arduino was developed based on the physical programming environment Wiring that he created.

Power supply considerations

Arduino boards are powered via the USB connection to your computer. In the final operation environment it is usually powered by applying power to the VIN (Vin) pin. The supply voltage should should be between 7 V and 12 V.

PWM

There are dedicated output pins for delivering square pulses with the desired frequency and the desired duty cycle. This is useful for controlling the amount of power that is delivered to slow-switching devices like LEDs and DC motors (via an intermediate power transistor stage). This technique is called pulse width modulation (PWM).

Communicating With Other Devices

I2C

You can use the Wire Library to communicate via the I2C protocol. Note that the Arduino can be slaved at a desired I2C address. This tutorial explains how to set up to Arduino controllers to communicate with each other, where one Arduino assumes the I2 master role and the other Arduino the slave role.

100 kHz is the default speed. 400 kHz is the maximum supported by the ATmega microcontroller on the Arduino board.

SPI

You can use the SPI Library to communicate with other chips via the SPI protocol but this library handles only the case in which the Arduino is the SPI master. To configure the Arduino as slave we need to use the low-level Atmel AVR instruction set

pinMode(MISO, OUTPUT);
pinMode(MOSI, INPUT);
pinMode(SCL, INPUT);
pinMode(SS, INPUT);
SPCR = (1 << SPE); // enable SPI as slave in mode 0, sending MSB first
SPI.attachInterrupt(); // implies SPCR = SPCR | (1<<SPIE)

where we install an interrupt handling function (a.k.a. interrupt service routine) for the interrupt type SPI_STC_vect

ISR(SPI_STC_vect)
{
  byte d = SPDR; // reading one byte from the data register
  // Do something with d. For example, append to a data array.
}

and where you need to implement your own messaging protocol on top of this basic byte-passing.

Here are two articles about programming SPI communication in AVR microcontrollers:

and documentation provided by Atmel for the ATmega328 plus an application note on SPI for AVR microcontrollers.

UART



Applications


Arduino IDE

USB Issue on Linux

If you see the error message can't open device "/dev/ttyUSB0": Permission denied in the Arduino IDE you need to add your user account to the same group that /dev/ttyUSB0 is a member of. To view the group membership of /dev/ttyUSB0 simply type

ls -l /dev/ttyUSB0

and note the group name. It's either dialout (e.g. on Ubuntu 16.04) or serial. Now add yourself to that group by typing

sudo usermod -aG <group name> <user name>

and check if you were successfully added by typing

groups <user name>

Finally, log out and log in again. This solution is also described on the Arduino website.

Teensy

Teensy is a family of boards from PJRC that are compatible with the Arduino IDE while using the ARM Cortex-M Kinetis processors from NXP (who bought the original manufacturer Freescale). These boards offer more computing power than the cheaper, 8-bit Atmel processors with AVR instruction set.


Debug data: