Giter Club home page Giter Club logo

arduino-i2c-sniffer's Introduction

arduino-i2c-sniffer

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

Example

Motivation

Hardware oscilloscopes and signal analyzers are too expensive.

Usage

1. collecting

  • 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

2. analyzing

  • 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

Description

Arduino sketch twi_sniff - data collector

Data collected on signal line changes. So no consecutive equal states possible.

Sniffer itself is working in sessions mode.

  1. it gathers data from pins until buffer overflow or inactivity timeout
    • no serial activity during this period
  2. 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.

Data visualization converter

  • convertToHtml.py python2 converter
  • style.css common css file for generated html
  • svg/* 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)

Examples

sample_data.txt and sample_data.txt contain commented test data gathered by me.

Limiting i2c speed

Only required for bus masters.

I'm using Raspberry Pi 2 and arduino nano 328p as i2c masters.

Raspberry Pi with raspbian (or derived)

  • 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.

Arduino using Wire library

  • after Wire.begin()d
  • Wire.setClock(50000);

arduino-i2c-sniffer's People

Contributors

alpacagh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.