No description
| lib | ||
| src | ||
| .clang-format | ||
| .gitignore | ||
| .gitmodules | ||
| avrsim.py | ||
| avrsim_i2c.py | ||
| CLAUDE.md | ||
| GEMINI.md | ||
| platformio.ini | ||
| README.md | ||
SoftI2CPeripheral — Arduino Playground
Simulation test environment for the SoftI2CPeripheral library.
Two ATmega2560 firmware images (I2C controller + peripheral) run simultaneously inside pysimulavr, connected by simulated I2C and UART wires. This validates the library against a real software I2C master (SoftWire) without any hardware.
Prerequisites
- PlatformIO (to build the firmware)
- pysimulavr (
pip install pysimulavror build from source)
Build & run
pio run # build both environments
python avrsim_i2c.py # run simulation (Ctrl+C to stop)
Common options:
python avrsim_i2c.py -n 5 # stop after 5 real-time seconds
python avrsim_i2c.py -i # log every I2C SCL/SDA transition to stderr
python avrsim_i2c.py -i -n 0.3 2>&1 | head -80 # quick debug snapshot
Controller UART → stdout prefixed [CTRL]
Peripheral UART → stderr prefixed [PERI]
Simulation wiring
Both devices are ATmega2560 running at 16 MHz. The simulated pins are connected
via pysimulavr Net objects with explicit weak pull-ups.
| Signal | Arduino pin | AVR port | simulavr key |
|---|---|---|---|
| SCL | 21 | PD0 | "D0" |
| SDA | 20 | PD1 | "D1" |
| UART TX | 1 | PE1 | "E1" |
Project layout
src/controller/main.cpp — I2C master using SoftWire
src/peripheral/main.cpp — I2C peripheral using SoftI2CPeripheral
lib/SoftI2CPeripheral/ — library submodule
avrsim_i2c.py — dual-device simulation harness
platformio.ini — two PlatformIO environments