Console Printing & Bus Protocols (UART, I2C, SPI)

Before you can send data over Wi-Fi or Bluetooth, you need the basics: printing text so you (the human) can see what your program is doing, and wiring protocols so your board can talk to…

Connectivity16 blocksMicroPythonC++

Before you can send data over Wi-Fi or Bluetooth, you need the basics: printing text so you (the human) can see what your program is doing, and wiring protocols so your board can talk to other chips sitting right next to it on the same breadboard. This topic covers four of those basics: the serial console (your program's "voice"), UART (a simple 2-wire link between two devices), I2C (a shared 2-wire bus for many devices at once), and SPI (a faster 4-wire bus for one device at a time).


1. Real-World Uses

  • Console printing is the single most-used debugging tool in electronics — printing a sensor value or a status message to see what your code is actually doing, especially when something isn't working as expected.
  • UART connects two devices directly with just 2 wires (TX/RX) — used for GPS modules, Bluetooth-to-serial adapters (like the HC-05), and linking two microcontroller boards together.
  • I2C is the bus behind most of the sensors and displays already covered in this wiki (the OLED in 10.6, the LCD I2C backpack in 10.3, and more) — its superpower is that dozens of different devices can share the same 2 wires (SDA/SCL), each picked out by its own address.
  • SPI is the fastest of the wired protocols here, used when speed matters — TFT displays (10.5), SD cards (Chapter 8), and the MAX7219 LED matrix (10.4) all use it.
  • I2C Scan specifically is a classic troubleshooting tool — plug in a mystery sensor module and run a scan to find out exactly which address it's actually using, without digging through a datasheet.

2. Supported Blockly Blocks (13 Blocks)

Drawing the blocks…

3. Simulator Behavior

Unlike every other topic in this chapter, these blocks aren't stubbed out or inert — console printing and I2C genuinely work in the Circuit Simulator:

  • Console printing (all of Section 2's print blocks) shows up exactly where you'd expect: the real Serial Monitor panel, live while your program runs.
  • I2C is genuinely real — Scan, Write, and Read all talk to actual simulated I2C devices on the bus (the OLED, or any other I2C-based component with a matching simulated peripheral) through the same underlying bus-emulation system documented for the OLED in 10.6. If you scan the bus with an OLED wired at 0x3C, the scan genuinely reports 0x3C back — this isn't a canned answer. Writing/reading to an address with nothing simulated there returns 0/empty bytes, with a helpful one-time console warning ("no device stub at this address — check circuit wiring") rather than silently pretending it worked.
  • UART has no simulated peer to talk to — Setup/Write/Read all run without error and generate fully correct code, but since a project simulates one board at a time, there's nothing on the other end of the TX/RX wires to send a reply. UART Read Line will simply never receive anything in the simulator.
  • SPI Setup itself just initializes the bus with no error — whether SPI communication actually does anything depends entirely on which specific SPI device extension you pair it with (see 10.4/10.5 for MAX7219/TFT, which do have real simulated SPI peripherals).
Console Printing & Bus Protocols (UART, I2C, SPI) — OMS Parts