Software implemented i2c/twi sniffer for arduino using python to visualize intercepted data.
Using nano 328p:
- 50khz maximum speed, (100khz is common standard)
- 100-150 bytes per single transfer session.
See sample_data.html
for output examples.
Output for each session looks like
Hardware oscilloscopes and signal analyzers are too expensive.
- upload sketch to arduino board
- connect board ground pin to analyzed bus ground
- connect A2 pin to analyzed scl bus, A3 pin to sda bus
- open serial monitor using 57600 bitrate
- save serial monitor data into text file (like sample_data.txt)
- run
python2 convertToHtml.py sample_data.txt >sample_data.html
- open
sample_data.html
in browser
Data collected on signal line changes. So no consecutive equal states possible.
Sniffer itself is working in sessions mode.
- it gathers data from pins until buffer overflow or inactivity timeout
- no serial activity during this period
- it encodes and sends gathered data to serial port
- no sampling during this period
This allows to expect more predictable sampling rate and achieve bigger supported data rates.
Sniffer require so both pins must be on the same avr GPIO port, so only one sampling is performed for both pins (and it is more-or-less atomic). See datasheet or just bruteforce options to find acceptable pin pair. Or use pre-configured A2+A3.
convertToHtml.py
python2 converterstyle.css
common css file for generated htmlsvg/*
source files for css in-line backgrounds
You may use convertToHtml.py
as module to create your more nice data
converter or even implement direct serial connection with arduino,
If nothing broken, every data session is converted into html table with
- row with visualization of SDA signal levels
- row with visualization of SCL signal levels
- row with signal interpretation by I2C/TWI protocol (S - start, E - end)
sample_data.txt
and sample_data.txt
contain commented test
data gathered by me.
Only required for bus masters.
I'm using Raspberry Pi 2 and arduino nano 328p as i2c masters.
- edit
/boot/config.txt
- add
dtparam=i2c2_baudrate=50000
- reboot
- check
cat /sys/module/i2c_bcm2708/parameters/baudrate
minimal confirmed by me rate is 5000, default is 1000000.
- after
Wire.begin()
d Wire.setClock(50000);