9. Embedded programming¶
In this week’s group assignment, we are comparing several popular choices of microcontrollers. Our goal is not to make an exhaustive list, but rather give a landscape of the current era in embedded programming.
Here is a table comparing several numerical values, gathered from https://www.microchip.com and https://www.espressif.com/ :
|name||company||year||type||GPIO||ADC||prog. mem.||data mem.||RAM||f_CPU (max)|
Note that the data memory can be either implemented in EEPROM (ATtiny1614 and ATmega328p) or flash (others). As a rule of thumb, the processor frequency multiplied by the number of bits per instruction gives an idea of the computing power offered by the chip.
It is interesting to note that a 32 bit processor could effectively affect the values of 32 pins in a single instruction, as they use 32 bit ports internally.
Atmel Corporation was acquired by Microchip in 2016, putting Microchip in a situation where they can provide cheap 8-bit families, as well as their more advanced 32-bit options.
We will now compare in more details the chips selected in our work.
The ATtiny1614 is a minimalist 8-bit microcontroller embedding a remarkable set of features for its size. Here is a pinout of the ATtiny1614:
Varied input voltages are supported, including 3.3V and 5V. The number of digital pins is reasonable for most projects, and on top of that, several communication ports are available such as serial, SPI and I2C. An example board based on an ATtiny1614 was presented by Quentin during the electronics design week:
A guide on how to use the Arduino IDE with the ATtiny1614 is available here.
This device is programmed through the UPDI protocol, which is a procotol acting as a serial port on a single bi-directional wire. There is a reserved UPDI pin on the ATtiny, that will trigger a reset whenever the voltage is set to 0V.
To program a UPDI target, it is necessary to have a host PC with a serial to USB converter. To communicate with the ATtiny during flashing, we use the pyupdi Python package.
The SAMD11C14 is a 32-bit microcontroller that includes a USB port. This feature makes the SAMD11C14 a great all-in one device, able to perform both low-level I/O tasks and higher level communications with a host PC. It can even be programmed as a computer keyboard or mouse.
Here is a listing of the pins, (from Shawn Hymel):
This chip also features a higher clock speed of 48 MHz, which is useful for faster data transfer over the USB.
You can find an example use-case of the SAMD11C14 in Quentin’s UDPI programmer:
The SAMD11C14 can only be programmed through the JTAG protocol. This uses a total of 4 pins, not including the power supply:
- CLK: clock, using for synchronization of the data transfer.
- DIO: bi-directional data cable.
- RES: reset, forces the SAMD to enable flashing.
A specific JTAG programmer is needed for this; we use the Particle Debugger. However, if a bootloader is installed on the SAMD, there are other ways to flash the chip. For instance, the Arduino bootloader enables compatibility with the AVR ISP programmer of the Arduino IDE.
The ESP32 is a recent 32-bit microcontroller with advanced features: WiFi, bluetooth and up to 240 MHz clock with 500kb RAM. Their manufacturer, Espressif, is a relatively new actor in the embedded electronics world.
The exact pinout will depend on the PCB used. Here is a pinout with one of the most basic kit available, the ESP32 DEVKIT (from https://randomnerdtutorials.com/esp32-pinout-reference-gpios/):
High-level peripherals are available for the ESP32. In Quentin’s final project, you can can see a use-case of the OV2640 camera module.
In Robin’s project, an ESP32 is used as a bluetooth controller for the pump of a fountain.
To learn how to program the ESP32 with the Arduino IDE, you can follow this guide.
The ESP32 features two methods for flashing:
- Serial port 0: it is necessary to poll the pin D0 to 0V to enable this.
- Over the Air (OTA): if enabled, the ESP32 will open a web socket when connected to the WiFi. The OTA service handles the transfer and flashing of the ESP32.
You can see an example of OTA programming in Quentin’s final project.