Embedded programming
Week 4 - Documentation
About some microcontrollers' datasheet...
Arduino
Arduino Uno is a microcontroller board based on the microprocessor ATmega328P.
Tech Specs (Data taken from Arduino.cc)
Features:
(Data taken from Arduino Datasheet)
Memory
- AVR CPU at up to 16 MHz
- 32KB Flash
- 2KB SRAM
- 1KB EEPROM
Security
- Power on Reset (POR)
- Brown Out Detection (BOD)
Peripherals
- 2x 8-bit Timer/Counter with a dedicated period register and compare channels.
- 1x 16-bit Timer/Counter with a dedicated period register, input capture and compare channels.
- 1x USART with fractional baud rate generator and start-of-frame detection.
- 1x controller/peripheral Serial Peripheral Interface (SPI)
- 1x Dual mode controller/peripheral I2C
- 1x Analog Comparator (AC) with a scalable reference input
- Watchdog Timer with separate on-chip oscillator
- Six PWM channels
- Interrupt and wake-up on pin change
ATMega16U2 Processor
- 8-bit AVR® RISC-based microcontroller
Memory
- 16 KB ISP Flash
- 512B EEPROM
- 512B SRAM
- debugWIRE interface for on-chip debugging and programming
Power
- 2.7-5.5 volts
Arduino Pin Layout (Image taken from Arduino.cc)
Reference Documentation (Table taken from Arduino Datasheet)
ESP32 dev kit
ESP32 is a microcontroller that integrates a ESP32-WROOM-32 SMD microprocessor.
Tech Specs (Data taken from ESP32-tutorial)
Features:
(Data taken from ESP32 features)
- Type: Wifi + Bluetooth module
- Model: ESP32 38 Pines
- Supply Voltage (USB): 5V DC
- Input/Output Voltage: 3.3V DC
- 5μA power consumption in sleep mode
- Main CPU: 32-bit Tensilica Xtensa LX6
- Clock Frequency: up to 240Mhz
- Secondary processor: Allows you to do basic operations in ultra-low consumption mode.
- Wi-Fi: 802.11 b/g/n/e/i (802.11n @ 2.4 GHz up to 150 Mbit/s)
- Bluetooth: 4.2 BR/EDR BLE Dual control mode
- Memory: 448 KByte ROM, 520 KByte SRAM, 6 KByte SRAM in RTC and QSPI supports multiple flash/chip
- SRAM
- USB-Serial Chip: CP2102
- Antenna on PCB
- GPIO Digital Pins: 24 (Some pins as input only)
- Analog-to-Digital Converter: Two SAR-type 12-bit ADCs, support measurement on up to 18 channels, some pins support an amplifier with programmable gain.
- Security: IEEE 802.11, including WFA, WPA/WPA2, and WAPI
- Hardware accelerated cryptography: AES, SHA-2, RSA, Elliptic Curve Cryptography (ECC), Random Number Generator (RNG).
- Dimensions: 28x54.4mm
ESP32 Dev Kit - Pin Layout (Image taken from ESP32 Pins)
Thoughts on the microcontrollers
Arduino is the classic microcontroller, and I believe that the most famous one of them all. As most of electronic enthusiasts and engineers in the field, I began using Arduino as my main MCU. Arduino Uno is a simple and functional dev board. Nevertheless, Arduino Uno is now a little bit limited compared to other more recent microcontrollers. The ESP32 Dev kit is a prominent example of the newer and better microcontrollers in the market. In terms of pins the Arduino has 13 digital GPIOS and 6 analog pins, while the Esp32 has 32 digital GPIOS and 16 analog pins. The esp32 also has a Wi-Fi and Bluetooth module integrated, and if you consider that the esp32 is smaller than the Arduino uno it gives a clear example of which MCU has the advantage.
I think that the esp32 is better for project given all the characteristics shown in the previous sections, but I still use the Arduino for some things. I like Arduino because it's easier to connect to a breadboard and to analyze pin by pin for small and simple projects.
Embedded Programming
Arduino Uno - Blinking inbuilt LED
After connecting my Arduino to the computer, I open the Arduino IDE.
To “warm up” the Arduino I'm going to create a super difficult, out of my mind program, which will make a led blink every second… Just kidding about being mine and difficult jaja. I'll use one of the examples that the interface already gives me.
This is the program:
Make sure to select the microcontroller you are using:
Then just download the program, and you'll see your Arduino with its inbuilt led blinking.
**ESP32 on Arduino IDE**
If this is the first time you will use ESP32 on the Arduino IDE, you will have to add the support to this type of boards with the following steps:
ESP32 Uno - Blinking inbuilt LED
After connecting my ESP32 to the computer, I open the Arduino IDE and select the board I'm using.
Then I wrote the blinking led program:
Then just download the program, and you'll see your ESP32 with its inbuilt led blinking.
Here are the the two microcontrollers blinking:
Serial Communication
We are going to use both microcontrollers to with serial communication. Let's make them count to ten and show the counting in the computer screen!
Arduino
ESP32 (video speed x2)
Now, using serial communication both ways, we are going to ask the user for a number and the microcontroller will start from 1 to that number and show the counting in the computer screen!
Arduino
ESP32 (video speed x2)
If you noticed, Arduino takes about three seconds to compile and upload the program, but ESP32 takes about 20 seconds (normal speed) to do so!
Comparing other microcontrollers
For this week assignments I focused in comparing and analyzing the esp32 dev board and Arduino uno, but there are other microcontrollers worth knowing. Here are the links for my classmates' week assignments.
- Beto: Xiao RP2040 and ESP32
- Mar: Xiao RP2040 and ESP32
- Pablo: Xiao RP2040
- Mario: Xiao RP2040 and STM32F407
- Max: Xiao RP2040 and ESP32
You can download the counting-numbers program: