Sniffing I2C Traffic from an Accelerometer using Bus Pirate

A guide to monitor and decode I2C communications between a microcontroller and an accelerometer sensor.

1. Experiment Overview

This experiment uses the Bus Pirate to intercept and decode data transmitted over an I2C bus between a microcontroller and an accelerometer (e.g., MPU6050 or ADXL345). Observing this data can help in understanding sensor outputs and debugging sensor communications.

2. Required Components

3. Circuit Setup

Connect the accelerometer to the microcontroller's I2C pins (usually labeled SDA and SCL), then connect the Bus Pirate as follows:

4. Configuring the Bus Pirate

Set up the Bus Pirate to sniff I2C communications by following these steps:

  1. Connect the Bus Pirate to your computer and open a serial terminal (e.g., Tera Term or PuTTY).
  2. Configure the connection settings for the Bus Pirate (usually 115200 baud rate, 8N1).
  3. Once connected, enter I2C mode by typing:

    [m] --> [4] for I2C
  4. Enable power supplies if needed (depending on sensor requirements).
  5. Activate the pull-up resistors if the circuit requires them (using the P command).
  6. Enter I2C sniffer mode by typing:
  7. [sn]
  8. The Bus Pirate will now begin capturing I2C communications on the bus, displaying addresses and data bytes as they are transmitted.

5. Observing and Decoding I2C Traffic

As the microcontroller communicates with the accelerometer, the Bus Pirate will display the following information:

For example, an output may look like:

[0x68 W][0x3B][0x68 R][0x1D 0x3E]

Here, 0x68 is the device address, followed by read/write commands and data bytes. You can interpret these bytes using the sensor's datasheet, which typically provides information on data register addresses and their meanings.

6. Interpreting Accelerometer Data

Many accelerometers store acceleration data in multiple registers. For instance, on the MPU6050:

With this knowledge, you can convert raw bytes to actual acceleration values based on the sensor's scale factor.

7. Tips for Troubleshooting