ENع
←Boards tour
Lesson 02 · Getting started with a microcontroller

A tour of Arduino, ESP32 and STM32 boards

12 min10 steps5 questionsBeginner
About this lesson

You rarely program a bare chip: a development board puts a microcontroller on a small card with a USB socket, a USB helper chip, a regulator and pin headers. Meet three common boards, the Arduino Uno R3, the ESP32-DevKitC and the STM32F4DISCOVERY, compare their clocks, memory and pin voltages, then choose one for a worked example: a plant sensor that must report over Wi-Fi. Finally follow the firmware down the USB cable into each chip. The Hardware lesson “Microcontrollers: a whole computer on one chip” explains what is inside the chip, and the C++ basics lessons cover the language.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 2 · Interactive
01 / 10

A chip plus its helpers

A development board puts a microcontroller on a small card with helpers: a USB socket, a chip that speaks USB, a power regulator and rows of pins. Plug it into a laptop and you can program it with no other tools.

development board = microcontroller + helpers
  USB socket      power and data from the laptop
  USB helper chip turns USB into something the MCU understands
  regulator       steady supply voltage for the chip
  pin headers     where your wires go
one cable, no extra programmer needed
Loading figure…
or ← →
Read the lesson step by step
  1. A chip plus its helpers

    A development board puts a microcontroller on a small card with helpers: a USB socket, a chip that speaks USB, a power regulator and rows of pins. Plug it into a laptop and you can program it with no other tools.

    development board = microcontroller + helpers
      USB socket      power and data from the laptop
      USB helper chip turns USB into something the MCU understands
      regulator       steady supply voltage for the chip
      pin headers     where your wires go
    one cable, no extra programmer needed
  2. Arduino Uno R3: the classic

    The Uno R3 carries an ATmega328P: an 8-bit chip at 16 MHz with 32 KB of flash for the program and 2 KB of SRAM for variables. It has 14 digital pins and 6 analog inputs, all working at 5 volts.

    board   Arduino Uno R3
    MCU     ATmega328P, 8-bit AVR
    clock   16 MHz
    flash   32 KB     SRAM 2 KB
    pins    14 digital, 6 analog, 5 V logic
    radio   none
  3. ESP32: Wi-Fi built in

    The ESP32-DevKitC carries an ESP32: two 32-bit cores at up to 240 MHz and 520 KB of SRAM, with Wi-Fi and Bluetooth inside the chip. The program sits in a separate 4 MB flash chip under the module's metal lid.

    board   ESP32-DevKitC  (module ESP32-WROOM-32E)
    MCU     ESP32, 32-bit Xtensa LX6, 2 cores
    clock   up to 240 MHz
    flash   4 MB, a separate chip in the module
    SRAM    520 KB
    radio   Wi-Fi 802.11 b/g/n, Bluetooth 4.2 and LE
  4. STM32: speed and a debugger

    The STM32F4DISCOVERY carries an STM32F407: a 32-bit Arm Cortex-M4 at 168 MHz with 1 MB of flash and 192 KB of SRAM. A second chip, the ST-LINK, is a debugger: it can pause your running code and show its values.

    board     STM32F4DISCOVERY
    MCU       STM32F407, 32-bit Arm Cortex-M4
    clock     168 MHz
    flash     1 MB     SRAM 192 KB (+4 KB backup)
    debugger  ST-LINK/V2 on the board
    radio     none
  5. Side by side

    Put the numbers together. Clocks: 16, 240 and 168 MHz. SRAM for variables: 2, 520 and 192 KB, so the ESP32 holds 260 times as much as the Uno. Bigger is not always better: a small job runs fine on a small chip.

              clock     flash    SRAM
    Uno R3    16 MHz    32 KB    2 KB
    ESP32     240 MHz   4 MB     520 KB
    STM32     168 MHz   1 MB     192 KB
    
    SRAM  520 / 2 = 260 times
  6. 5 volts or 3.3 volts

    A HIGH pin on the Uno is 5 volts. The ESP32 and STM32 boards run on 3.3 volts or less. An ESP32 pin takes at most 3.6 volts, so lower a 5 V signal first: a later lesson on level shifting shows how.

    Uno R3   HIGH = 5 V
    ESP32    HIGH = 3.3 V
    STM32    3.3 V or less (chip supply 1.8 to 3.6 V)
    ESP32 pin input max = supply + 0.3 V = 3.6 V
    so 5 V into an ESP32 pin is out of spec
  7. The job: a Wi-Fi plant sensor

    Our worked example: a plant-pot sensor that reads soil moisture and sends it over Wi-Fi. Test each board against that one hard need. The Uno and this STM32 have no radio. The ESP32 has Wi-Fi on the chip.

    job:   plant sensor
    read:  1 analog pin
    send:  over Wi-Fi
    power: USB, 5 V
    
    hard need: Wi-Fi
      Uno R3  no radio
      ESP32   yes, on the chip
      STM32   no radio
  8. Pick the ESP32

    The ESP32 wins: Wi-Fi is built in, it has analog inputs for the sensor, and the Arduino IDE can program it with Espressif's Arduino core. The other boards would need an extra Wi-Fi board wired on.

    chosen   ESP32-DevKitC
      Wi-Fi on the chip
      analog inputs for the sensor
      Arduino core for ESP32 (by Espressif)
      520 KB SRAM: room for the Wi-Fi code
    others   would need an add-on Wi-Fi board
  9. Getting code onto the ESP32

    The laptop compiles the sketch into a firmware image and sends it down the USB cable. The bridge chip turns USB into serial and resets the ESP32 into download mode. A bootloader in the chip's ROM writes the image into flash.

    laptop       sketch -> firmware image
    USB cable    image to the bridge chip
    bridge       USB -> serial, up to 3 Mbps
                 holds GPIO0 low during reset: download mode
    ROM loader   built into the ESP32, writes flash
    reset        the new firmware starts
  10. Each board has its own route

    On the Uno, the ATmega16U2 passes the image to a 512-byte bootloader kept in the ATmega328P's own flash. On the STM32 board, the ST-LINK writes flash directly through the chip's debug port, called SWD. The next lesson follows compile, link and flash.

    Uno     USB -> ATmega16U2 -> serial 115200 baud
            -> bootloader (512 bytes of flash) -> flash
    ESP32   USB -> bridge -> ROM bootloader -> flash
    STM32   USB -> ST-LINK/V2 -> SWD -> flash
            no bootloader needed; it can also debug

Quiz Unlocks after the last step.