Elektronik Atölyem

Basics of digital communication

14 minutes · Advanced

Simulations and quizzes aren't read aloud; pause when you reach them and try them out.

How does a temperature sensor pass the value it measured, a display the text it will show, or a GPS module its position to an Arduino? They all speak the same language: bits. In this course you'll learn, bit by bit, the three protocols most modules use: UART, I2C and SPI.

Bits, bytes and number systems

A digital line only knows two states: 1 (high voltage) and 0 (low voltage). A single 1 or 0 is called a bit, and a group of 8 bits a byte. A byte represents a number from 0 to 255. Engineers usually write bytes in hexadecimal (hex), because each hex digit corresponds to exactly 4 bits: 0xA5 = 1010 0101.

Click the bits to toggle between 0 and 1.

1286432168421
Decimal
65
Hexadecimal
0x41
Binary
0b01000001
ASCII character
'A'

Letters are numbers too: in the ASCII table 'A' = 65, 'a' = 97, '0' = 48. When you send text to the serial monitor, these numbers are what's actually sent.

Parallel and serial

Parallel

8 bits are sent at the same time over 8 separate wires. It's fast but needs lots of wires and pins. Old printers and character LCDs work this way.

Serial

The bits are sent one after another over a single wire. Few wires, few pins. Almost everything is serial today: USB, UART, I2C, SPI, Ethernet.

Synchronous and asynchronous

How will the receiver know when one bit on the line ends and the next begins? There are two ways:

  • Asynchronous: there's no separate clock line. Both sides agree on the speed in advance (baud). UART works this way.
  • Synchronous: there's a separate clock line. The sender produces a clock pulse for each bit. The receiver reads the data line when the pulse arrives. I2C and SPI work this way. No speed agreement is needed.

Logic levels: 5 V and 3.3 V

The Arduino Uno runs at 5 V: a 1 means about 5 V. The ESP32, Raspberry Pi and most modern sensors run at 3.3 V.

Don't send a 5 V signal to a 3.3 V device

Connecting a 5 V output directly to a 3.3 V input can damage that device, either over time or instantly. For one-way signals use a voltage divider (remember the Electricity Basics course: 1 kΩ + 2 kΩ); for two-way lines (I2C) use a level shifter module. The other direction is usually fine: the Uno usually reads a 3.3 V output as a 1.

Common ground

"1" and "0" are voltages measured relative to ground. If the grounds of two communicating devices aren't connected, the voltages have no common reference and the communication won't work. Every connection must have a GND wire in addition to the data wires.

Test yourself

1. What is 0x1F in decimal?

2. How many bits make a byte?

3. Which uses a separate clock line?

4. What should be done to connect a 5 V Arduino output to a 3.3 V sensor input?

This was the free first lesson of the course

The remaining 8 lessons of UART, I2C and SPI, with their simulations and quizzes, unlock when you buy the course.

See the full course →
Join for free to save your progress.Join