1while True:2 led.toggle()3 sleep_ms(500)4 print(btn.value())busFLASHCPUTIMERSRAMGPIOADCUART01pin 2pin 5TX+GNDGPIO REGISTERS · BIT = PIN76543210OUT––01–––––IN–––––01––bit 5 → LED · bit 2 ← buttonzzZ0.1 µA1
Lit trace: current is flowing (moving dashes)Glowing pill: a value travelling along the chip's internal busRegisters: one bit per pin; bit 5 drives the LED, bit 2 reads the buttonCode card: the highlighted line is the one runningA microcontroller is a whole small computer on one chip. Here the lid is off: the CPU core fetches the program from flash, keeps its variables in SRAM, and reaches the world through GPIO pins, a timer, an ADC and a UART. The MicroPython loop on the left toggles bit 5 of the GPIO output register, so the LED on pin 5 blinks while the timer counts 500 ms, and reads bit 2 of the input register, which falls to 0 when the button pulls pin 2 to ground. A lit trace with moving dashes means current is flowing; the glowing pill is a value moving along the chip's bus. When there is nothing to do, the chip sleeps and draws almost no current. Sizes, speeds and currents are the ATmega328P's (the Arduino Uno's chip) from the Microchip datasheet; the currents are measured at 1 MHz, 1.8 V and 25 °C, and grow with clock speed and supply voltage.

The chip

  1. A microcontroller is a whole small computer on one chip: a processor, memory for the program and its data, timers, and pins that reach the outside world. Boards like the Arduino Uno are built around one.

Memory

Running a program

Inputs and helpers

Power and real chips

In detail

;; step 1/11 · whole
Inside one package (ATmega328P, the Arduino Uno's chip):
  CPU core            runs the program
  flash   32 KB       the program (kept without power)
  SRAM    2 KB        variables while it runs
  EEPROM  1 KB        small settings that survive power-off
  timers  two 8-bit, one 16-bit
  23 I/O pins, a 10-bit ADC, USART, SPI and I2C serial ports
A laptop spreads these over many chips; a microcontroller has them all in one.

The figure is a generic microcontroller drawn as a teaching model: one chip with a CPU core, flash, SRAM, a timer, GPIO, an ADC and a UART, wired to an LED, a button and a dial. Real chips have more of each. Sizes, speeds and currents are the ATmega328P's (the Arduino Uno's chip) from the Microchip datasheet; the currents are measured at 1 MHz, 1.8 V and 25 °C, and grow with clock speed and supply voltage. The code card is MicroPython (machine.Pin and time.sleep_ms). It runs on larger chips such as the RP2040; on an Arduino Uno the same loop is usually written in C++.