I2C Bus Scanner
Run the I2C Bus Scanner MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
Every chip on an Inter-Integrated Circuit (I2C) bus has an address. A chip never tells the Pico its address. The Pico has to ask.
An I2C scan asks every address from 0x08 to 0x77, one at a time. After each
address, the Pico listens for one clock pulse. A chip that owns the address pulls
the data wire (SDA) low. That is an acknowledge, or ACK. If nobody pulls the
wire low, the answer is a NACK. It means nobody lives at that address.
This MicroSim runs a scan in slow motion. The bus has three chips:
- an MPU-6050 (accelerometer and gyroscope) at
0x68 - an HMC5883L (compass) at
0x1E - an SSD1306 (OLED display) at
0x3C
You can watch the clock wire (SCL) and the data wire (SDA) for each address.
You can see the matching chip answer. You can watch the address map fill in.
When the scan ends, the console prints what i2c-scanner.py prints on a real Pico.
Learning objective: You will be able to explain how an I2C scan finds chips. The Pico asks each address, and only the chip that owns it answers with an ACK.
- Bloom's Taxonomy (2001): Understand - explain, demonstrate
- Interaction pattern: step-through (Start, Step, Reset) with a plug-and-unplug experiment
How to Use
- Press Step a few times. Watch the Pico box. It shows the address it is asking about, in hex and in decimal.
- Drag the Speed slider to 1 and press Start. Follow one address from START, through the seven address bits and the write bit, to the ACK slot.
- Check Pause at each ACK, press Start, and let the scan run. It stops each time a chip answers.
- Speed the scan up and let it finish. Compare the console with the colored cells in the address map.
- Uncheck a chip to unplug it. Press Scan again. Predict which address will disappear before the scan gets there.
What to Look For
- The Pico asks. Chips answer. Every chip box says "listening..." Only one says "ACK! That is me."
- Addresses are numbers.
0x1E,0x3Cand0x68are the same numbers as 30, 60 and 104. The console prints the decimal number too, like the book'si2c-scanner.pydoes. - The wires are shared. All three chips hear every address. That is why two chips on one bus cannot use the same address.
- Some addresses are skipped.
0x00to0x07and0x78to0x7Fare reserved. They are gray.
Embedding This MicroSim
You can add this MicroSim to any web page with this HTML:
1 2 3 4 | |
Lesson Plan
Grade Level
Ages 10-18. Part of Appendix A: The I2C Bus.
Duration
10-15 minutes
Prerequisites
- Chapter 8: Communication Protocols, the I2C section
- Hexadecimal numbers such as
0x68(the appendix explains them)
Activities
- Predict and step (4 min): Students guess if address
0x09gets an ACK. They press Step and read the status line. - Slow-motion ACK (4 min): At speed 1, students find the ACK slot in the waveform. They say who pulled the SDA wire low.
- Unplug experiment (5 min): Students uncheck one chip, predict the new scan, and run it.
- Connect to code (2 min): Students match each console line to the
i2c.scan()call ini2c-scanner.py.
Assessment
- The student explains why a chip does not announce its own address.
- The student reads a scan result such as
[30, 60, 104]and names the chips. - The student predicts the scan after a chip is unplugged.
References
- UM10204: I2C-bus specification and user manual, Rev. 7.0 - NXP, 2021
- MicroPython machine.I2C - describes
scan()and its 0x08 to 0x77 range - Appendix A: The I2C Bus - the full explanation that goes with this MicroSim
- Protocol Comparison Explorer - compares I2C, SPI and UART
- p5.js - the JavaScript library used to build this MicroSim