The Micro‐Controller CPU card - uraich/IoT4AQ GitHub Wiki
Introduction
In the past, micro-processors only contained the CPU (Central Processing Unit) and it had interfaces to external memory (non-volatile: ROM Read Only Memory and volatile RAM: Random Access Memory) and I/O (Input / Output) modules. Modern micro-controllers provide all this on a single chip.
CPUs only understand binary coded instructions and each CPU uses its own instruction set. Formally, programs were written in assembly language, which is a one to one translation between human readable code and the binary machine code. This implies that the programmer had to understand all the details of the processor and its instruction set and a program written for one machine would not run on the other. Writing an assembly language program can be a daunting task, knowing that a 3 US$ processor is described in a manual that easily exceeds 1000 pages. In order to facilitate the programming task, high level languages have been invented (we will use C/C++ for our project) which abstract the programming problem, giving the programmer a tool, in which he can (more) easily express the algorithm he wants to implement. In this case a compiler is needed to convert the high level program into assembly language for the target processor and finally into its binary machine code.
A Micro-Controller, that can be programmed by anybody
The development of the Arduino Ecosystem provided a major step in bringing the use of micro-controllers to the general public. It consists of two parts:
- The Arduino Uno CPU card, based on the Atmel AT328P processor, an 8 bit CPU, a USB to serial connection for programming and serial output as well as a standardized I/O connector, allowing to create piggy back interface cards, so-called Arduino shields.
- The Arduino SDK (Software Development Kit), an integrated development environment (IDE) featuring an editor (allowing you to write he source code and saving it onto a file on the PC), a compiler that can be started with a simple push of a button and an upload facility transferring the binary code, created by the SDK on the PC, to the micro-controller hardware.
The photo below shows the Arduino Uno CPU card.
As can be seen in the technical specifications below, the Arduino Uno has only an 8-bit CPU and does not have a network connection (more modern versions do have a WiFi interface). It runs at 16 MHz, which is relatively slow compared with other, more modern machines, and the amount of flash memory and RAM is pretty limited. On the other hand all important I/O interfaces:
- GPIO: general purpose digital I/O pins
- PWM: pins providing Pulse Width Modulation (we will see this later)
- ADC: Analogue to Digital Conversion
- I2C: an instrumentation bus used by many sensors and actuators
- SPI: a bus used by fast devices like displays are all available.
The typical cost of an Arduino Uno board is around 4 US$.
The ESP32
New, more powerful processors came onto the market and the Arduino SDK was adapted to these more modern micro-controllers. Nevertheless, the Arduino Uno is still widely used. As we said above, a different processor means a different instruction set, which implies a different compiler. The Arduino SDK can therefore be extended to accommodate this new compiler and a different upload facility. For the user of the Arduino SDK the way to compile (a simple button click) and upload the code stays the same, even though the underlying programs running in the background are different. For the IoT4AQ workshop we use the ESP32-DevKitC-32 which features an ESP32-WROOM processor, provided by the Chinese company Espressif.
As can be seen from the technical specifications below, the ESP32 is vastly more powerful than the Atmel AT328P used in the Arduino Uno. The board layout is different and Arduino shields will not fit on the ESP32-DevKitC-32. However it features a 32 bit dual core (two processors running in parallel) processor running at 240 MHz (to be compare to 16 MHz for the Arduino). In addition to the sensor and actuator interfaces it also provides a WiFi and BlueTooth interface, one of which is needed for IoT systems, giving access to the Internet.
The ESP32-DevKitC-32 provides two buttons, one of the to reset the CPU and the other one to put the ESP32 into flash programming mode. On most ESP32 boards a signal of the serial line is used to switch to programming mode and the button is not really needed for this purpose. Once a program is running normally the state of the button can be read on the GPIO 0 line.
Then there are two LEDS. One of them indicates power, while the other one is connected to GPIO 2 and can be user programmed. To terminate this chapter we give the pin out of the CPU which is needed to interface external devices to the board. We will see details of this later.