Embedded Programming
Group Assignment
Class Week 8
Setup
We decided to compare some architectures:
- Arduino UNO (ATmega328p);
- Arduino Leonardo (ATmega32u4);
- NodeMCU (ESP8266);
- ESP32 DEVKIT DOIT (ESP32);
Arduino UNO (ATmega328p)
Arduino Uno is a microcontroller board based on the ATmega328P (see here the datasheet). It has:
- CPU: ATmega32u4 (16MHz);
- 14 digital input/output pins (of which 6 can be used as PWM outputs); 6 analog inputs;
- 16 MHz quartz crystal,
- USB connection, power jack, ICSP header and reset button;
- Operating Voltage: 5V;
- Flash Memory: 32 KB (ATmega328P) of which 0.5 KB used by bootloader;
- SRAM: 2 KB (ATmega328P);
- EEPROM: 1 KB (ATmega328P).
Some special features of the board, according to the Arduino Official Website:
- Serial / UART: pins 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL serial chip;
- External interrupts: pins 2 and 3. These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value;
- PWM (pulse-width modulation): 3, 5, 6, 9, 10, and 11. Can provide 8-bit PWM output with the analogWrite() function;
- SPI (Serial Peripheral Interface): 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library;
- TWI (two-wire interface) / I²C: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library;
- AREF (analog reference): Reference voltage for the analog inputs.
Arduino Leonardo (ATmega32u4)
Arduino Leonardo is a microcontroller board based on the ATmega32u4 (datasheet. It has:
- CPU: ATmega32u4 (16MHz);
- 20 digital input/output pins (of which 7 can be used as PWM outputs and 12 as analog inputs);
- 16 MHz crystal oscillator;
- Micro USB connection, power jack, ICSP header and reset button;
- Operating Voltage: 5V;
- Flash Memory: 32 KB (ATmega32u4) of which 4 KB used by bootloader;
- SRAM: 2.5 KB (ATmega32u4);
- EEPROM: 1 KB (ATmega32u4).
Some special features of the board, according to the Arduino Official Website:
- Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data using theATmega32U4 hardware serial capability. Note that on the Leonardo, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class;
- TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library;
- External Interrupts: 3 (interrupt 0), 2 (interrupt 1), 0 (interrupt 2), 1 (interrupt 3) and 7 (interrupt 4). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value.
- PWM: 3, 5, 6, 9, 10, 11, and 13. Provide 8-bit PWM output with the analogWrite() function;
- SPI: on the ICSP header. These pins support SPI communication using the SPI library.
NodeMCU (ESP8266)
The NodeMCU board (v1.0) is based on the ESP8266 WiFi chip.
- CPU: ESP8266 12E (80MHz or 160MHz);
- Flash Memory: 128kBytes;
- Storage: 4 MBytes;
- micro USB port for power, programming and debugging;
- buttons for reset and flash;
- 10 GPIOs D0-D10, PWM functionality.
Special Features:
- IIC and SPI communication, 1-Wire and ADC A0;
- WiFi networking (can be used as access point and/or station, host a web server), connect to internet to fetch or upload data.
ESP32 DEVKIT DOIT (ESP32)
- CPU: ESP32 (Dual-Core 32-bit, 160 or 240MHz);
- ROM: 448 KB;
- SRAM: 520 KB;
- micro USB port for power, programming and debugging;
- buttons for reset and flash;
- 30 GPIOs.
Special Features:
- WiFi: 150.0 Mbps data rate with HT40;
- Bluetooth: BLE (Bluetooth Low Energy) and legacy Bluetooth;
- Low Power: ensures that you can still use ADC conversions, for example, during deep sleep;
- Peripheral Input/Output: peripheral interface with DMA that includes capacitive touch, ADCs (Analog-to-Digital Converter), DACs (Digital-to-Analog Converter), I²C (Inter-Integrated Circuit), UART (Universal Asynchronous Receiver/Transmitter), SPI (Serial Peripheral Interface), I²S (Integrated Interchip Sound), RMII (Reduced Media-Independent Interface) and PWM (Pulse-Width Modulation).
Comparison
They can all be programmed through the Arduino IDE and connected to the computer with an USP cable. Simple codes can be easily modified to run in all of this boards, more complex codes can be more specific, some examples can be:
- Arduino Leonardo: If you need a board that can simulate a Keyboard or a mouse;
- NodeMCU: If you need WiFi;
- ESP 32: If you need Bluetooth;
Performance-wise ESP32 should be the faster and most complete board of all, as it has a lot of features, better CPU and more memory. We found this comparison chart that took all of this CPUs into against each other on clock speed:
So the Arduino UNO and Leonardo runs at 16MHz, the ESP8266 at 80 or 160MHz and the ESP32 at 160 or 240MHz. We can see that with more power comes bigger energy consumption as the ESP32 presents picks around 150ma, ESP8266 on 70ma and the Arduinos around 25ma.
The costs also rise with the processing power:
- Arduino UNO (compatible): US$2.60
- Arduino Leonardo (compatible): US$3.60
- NodeMCU: US$4.40
- ESP32: US$5.00
Invidual Assignment
In this week assignment we programmed our PCBs, that we produced in the assignment Week 6 - Electronics Design.
Programming with Arduino
To get my PCB programmed I followed the steps this chapter: "ATtiny Embedded Programming with the Arduino IDE", which I found in this tutorial.
Before programming the microchip, we went back and studied the Data Sheet of the
AVR Microcontroller ATtiny44. The microchip provides an 8K byte of In-System Reprogrammable Flash memory for program storage. This is not a lot, so I had to consider this before installing the needed Libraries and programs to the microchip.
Libraries and Bootloading
In the next step I had to connect the pins, considering the different numberings between an Arduino and my ATtiny44.
After this the PCB was ready to be programmed doing something.
Blink Tests
I tested the PCB, using the Arduino sample from its library, and made up three blink test:
- Pin I/O 3: Green LED blinking:
- Pin I/O 2: Red LED blinking:
- Pin I/O 2 and 3: Green and red LED alternate blinking:
This circuit is a basic constellation, which is also known as Charlieplexing.
Conclusion
The blink tests were successful, the only difficulties I had, were to understand the theoretical part regarding data sheet and libraries. An interessting experience was also, that see what changes, when you modify the circuits of the tutorial, in my case left out the button and added a second LED into it.
Assignment accomplished...