Testing / Displays / 02
I²C Detective
Create a reusable bus diagnostic that separates addressing failures from application failures.
All 3 stages compiled 2026-10-19 (historical) · hardware review required
What you'll build
Probe ordinary seven-bit addresses with the Wire framework library.
First result after hardware review: Serial lists responding addresses and a count every three seconds.
What you need
Check availability and exact module markings before starting.
Connections / current hardware gate
Before connecting power. No peripheral wiring map is supplied for this scanner. Verify the device supply and bus pull-ups before attaching a device; the program stops until electrical review is complete.
- Use the Mega target and confirm its SDA/SCL connections against the actual board.
- Check the peripheral supply, common ground and idle bus voltage before power. Add one compatible peripheral at a time, with power removed while changing wiring.
- An address response identifies a responder, not its chip or a working display.
Start building
- 1
Find responders
Probe ordinary seven-bit addresses with the Wire framework library.
- 2
Distinguish errors
Report non-NACK transmission failures separately.
- 3
Compare bus changes
Add one voltage-compatible device at a time and record differences.
Download complete PlatformIO project
Each stage has its exact environment, complete source and expected result. Editor and tools setup →
Troubleshooting
Nothing responds
Check power and common ground, then measure idle SDA/SCL against the device’s permitted logic rail. Verify Mega D20/D21 rather than transferring Uno A4/A5 wiring.
Many unexpected responses
Disconnect peripherals one by one. A held-low line, wiring error or faulty module can invalidate a scan; do not accept a crowded address list as successful discovery.
ESP32 adapter planned
Use the correct board-specific Wire pin setup and a 3.3 V-safe bus. A 5 V pull-up on a carrier can damage a 3.3 V host.
More detail
Foundations, safety and learning objectives
100 minutes · Editorial learning estimate excluding unresolved procurement/driver-port time
Three actual PlatformIO firmware environments; embedded compile and bench verification unestablished.
- Keep electrical review false until the exact wiring/power/logic checklist is completed.
- No power budget is inferred from successful compilation.
- Create a reusable bus diagnostic that separates addressing failures from application failures.
- SDA carries bidirectional serial data and SCL clocks transactions.
No earlier Displays project is required.
System diagram and electrical boundaries
Show the meaningful subsystem and signal/power boundary for I²C Detective. Conceptual system view; physical connections remain conditional.
- ELEGOO Mega 2560 R3 boardClub-owned
Signals and interfaces
No physical connection is specified for this boundary.
Power and common reference boundary
No physical connection is specified for this boundary.
Interfaces: GPIO · I2C
Electrical boundaries and interpretation
- Use conditional wiring records; null pin/voltage means unresolved, not permission to choose a value.
- Draw power and logic paths separately.
- Do not turn a reference signal label into a guessed connector position.
- Keep member, club and campus access labels distinct.
- Include explicit port gate for unresolved driver/identity.
- Access scopes: CLUB_OWNED.
- Firmware source is not bench evidence.
Full hardware facts and conditional wiring reference
Access describes the source of a requirement. Check availability, the exact revision and the complete power/driver/harness system before starting. Inventory quantities are expected purchase/BOM quantities, not live stock.
- ELEGOO Mega 2560 R3 boardClub-owned
product family verified · preflight required
No connection rows are authored for this selection. This does not establish safe wiring; use the current hardware gate and confirm the actual module before making connections.
All source files, supporting libraries and project download
Download complete project · workspaces/i2c-detective
Open the extracted folder containing platformio.ini and keep the complete supporting files.
workspaces/i2c-detective/src/main.cpp
#include <Arduino.h>
#include <Wire.h>
#include "board_profile.h"
bool ready=false;uint32_t lastScan=0;
void setup(){Serial.begin(115200);if(!kElectricalReviewComplete){Serial.println("Review bus voltage/pull-ups first.");return;}Wire.begin();ready=true;}
void loop(){if(!ready||uint32_t(millis()-lastScan)<3000)return;lastScan=millis();unsigned count=0;
for(uint8_t address=8;address<120;++address){Wire.beginTransmission(address);const uint8_t result=Wire.endTransmission();
if(result==0){Serial.print("ACK at 0x");if(address<16)Serial.print('0');Serial.println(address,HEX);++count;}
#if DISPLAY_STAGE >= 2
else if(result!=2){Serial.print("Bus error ");Serial.print(result);Serial.print(" at ");Serial.println(address,HEX);}
#endif
}Serial.print("Responding addresses: ");Serial.println(count);
#if DISPLAY_STAGE >= 3
Serial.println("Record before/after adding one verified peripheral; an ACK is not chip identification.");
#endif
}
Source integrity · SHA-256
132b64ed2033693f8e862d80b70d38b798193e834918e56967c004ee9d8aa73eRaw downloads and standalone ZIPs retain the canonical bytes and supporting files. Copy follows the selected Comments setting.
Original engineering guide
Original research wording is preserved. Use the stage-specific dated build evidence for later compile results; it does not establish physical behavior.
Create a reusable bus diagnostic that separates addressing failures from application failures.
Status: FIRMWARE_AUTHORED_UNVERIFIED. FIRMWARE_SOURCE_AUTHORED; embedded build UNVERIFIED; hardware NOT_TESTED. Three actual PlatformIO firmware environments; embedded compile and bench verification unestablished.
What you are building
SDA carries bidirectional serial data and SCL clocks transactions. Pull-up resistors define the idle high rail: the bus is not an ordinary push-pull pair. A seven-bit address is written in hex for compactness. 0x27 is decimal 39; 0x3C is decimal 60. The scanner avoids the reserved ends of the address range. An ACK says a device accepted the addressed transaction. It does not identify a chip, prove all commands work, or reveal two devices responding at the same address.
Before you start
Estimated learning time: 100 minutes, excluding unresolved hardware/port work. Required prerequisites: orientation only. See PLATFORMIO_ORIENTATION.md and the hardware identity/access records. Current main inventory IDs and expected quantities were compared read-only at a406480e1e13807983f1c03b8a531c2dcd310ddb; expected quantities are not live stock. Member and campus access remain separate from club ownership.
Hardware and conditional wiring
| Component ID | Access scope | Expected snapshot quantity | Preflight |
|---|---|---|---|
| club:elegoo-mega-2560-compatible-board | CLUB_OWNED | 3 | PREFLIGHT_REQUIRED |
Breadboard, appropriately rated jumpers/data cables and a computer are shared setup requirements. Review supply, signal levels and ground separately; power off before changing connections. Null pins/rails remain unresolved.
| From | To | Signal | Voltage / gate | Condition |
|---|
Software setup and dependencies
Open workspaces/i2c-detective in VS Code/PlatformIO. Configuration: workspaces/i2c-detective/platformio.ini. Platform: atmelavr@5.1.0. Board/framework: megaatmega2560 / arduino. Dependencies: no external lib_deps. Dependency resolution occurs during build; an include is not an installation. See LIBRARY_MATRIX.md and COMPILATION_AUDIT.md for exact verification limits. The default electrical-review flag remains false. Review the matching pins, power and logic before changing it; a build cannot complete that physical review.
Build it: checkpoint path
| Stage | Goal | Environment | Expected / gate |
|---|---|---|---|
| Find responders | Probe ordinary seven-bit addresses with the Wire framework library. | checkpoint1 | Serial lists responding addresses and a count every three seconds. |
| Distinguish errors | Report non-NACK transmission failures separately. | checkpoint2 | An absent address is different from a bus fault. |
| Compare bus changes | Add one voltage-compatible device at a time and record differences. | checkpoint3 | Before/after address sets identify which connection added a responder. |
Choose a stage deliberately. Project downloads include all authored environments; model-only project downloads include checkpoints1/2 and explicitly exclude the unfinished physical checkpoint. Stage3 for a port-gated project refuses download as finished firmware.
Understand it: software and physical model
Wire is supplied by the selected board framework, so there is no separate external lib_deps entry for it. beginTransmission queues the address and endTransmission attempts the transaction. Result zero is an ACK and result two is an address NACK in this use; other results are reported as failures requiring further investigation. The scanner runs periodically to avoid an uninterrupted flood of Serial messages. Its blocking sweep is appropriate as a standalone diagnostic, not a task to insert into an animation loop every frame.
First run the controller and terminal with nothing connected; an empty address set is a useful baseline. Then connect a verified peripheral while unpowered, restore power and compare. A pair of devices with the same address is not fixed by using different variable names. Options include a documented alternate address, a bus multiplexer, or another supported bus. The scan address is seven-bit; U8g2’s setI2CAddress API later takes that value shifted left by one. Distinguish the hardware address from an API’s representation.
Canonical code reading map
| Real file | Source landmarks (1-based) | Lines |
|---|---|---|
| workspaces/i2c-detective/include/board_profile.h | Supporting declarations / portable helpers | 5 |
| workspaces/i2c-detective/src/main.cpp | 5: void setup(){Serial.begin(115200);if(!kElectricalReviewComplete){Serial.println("Review bus voltage/; 6: void loop(){if(!ready//uint32_t(millis()-lastScan)<3000)return;lastScan=millis();unsigned count=0; | 16 |
| common-libs/DisplayCore/src/DisplayCore.h | 30: inline bool parsePacket(const char* text,Packet& result){; 40: bool accept(const Packet& p,uint32_t now){ | 60 |
Read initialization and failure guards first, then the selected DISPLAY_STAGE region and its supporting modules. Source hashes, owners and roles are in code-assets.json. Shared software tests establish portable invariants only. No model substitutes for a physical driver.
Troubleshooting with evidence
Nothing responds
Check power and common ground, then measure idle SDA/SCL against the device’s permitted logic rail. Verify Mega D20/D21 rather than transferring Uno A4/A5 wiring.
Many unexpected responses
Disconnect peripherals one by one. A held-low line, wiring error or faulty module can invalidate a scan; do not accept a crowded address list as successful discovery.
ESP32 adapter planned
Use the correct board-specific Wire pin setup and a 3.3 V-safe bus. A 5 V pull-up on a carrier can damage a 3.3 V host.
Experiments after the baseline
Write a before/after inventory of two individually verified devices.
Explain each hex result as both a decimal value and seven-bit address.
Detect an address collision by testing modules separately.
Challenge
Add a comparison mode that highlights newly appearing and disappearing addresses without assuming what chip produced them.
Verification and next work
No physical upload or bench observation occurred. Expected device results are targets. Native test output is recorded separately in validation/host-results.json. Current bounded build attempts are in validation/repair-compile-results.json; historical attempts remain under validation/history/. Embedded compile/link and hardware behavior remain unverified until actual evidence is recorded.
Source records: inventory-club-v3, inventory-member-v14, pio-deps, pio-mega, mega-doc, pio-ide. Verified repository destinations are recorded in repository-integration.json; only resolved IDs are exposed in relatedLabs/relatedLearnConcepts.
Build evidence and diagnostic references
Current compile attempts: not performed in this pass. Physical Upload and bench observation: not tested.
- Stage 1: successful compile recorded 2026-10-19; 4 warnings recorded. The supplied electrical-review flag is false.
- Stage 2: successful compile recorded 2026-10-19; 4 warnings recorded. The supplied electrical-review flag is false.
- Stage 3: successful compile recorded 2026-10-19; 4 warnings recorded. The supplied electrical-review flag is false.
Historical compile evidence is separate from the original guide's earlier unverified status and does not establish today's build or hardware behavior.
Technical sources and references
- PlatformIO Mega board
megaatmega2560, Arduino framework and target memory
- PlatformIO dependencies
Dependency installation occurs during package/build processing
- Arduino Mega hardware
Board pinout, voltage and ADC family
- Official PlatformIO IDE installation
Official VS Code extension includes Core and project environment tasks