I2C Quick Reference

Occasionally you might find a reason to read or write directly to/from an I2C sensor. In the case of the Modern Robotics color sensor, for example, you might need to perform a calibration or change the sample rate. Use this as a quick reference for I2C default addresses, registers, and command codes.

Modern Robotics Sensors

All of the following information can be found on the Modern Robotics pages for each sensor, as well as various data sheets which they have made available.

Color Sensor

Default Address: 0x3C

Registers:

  • 0x00: Firmware Version
  • 0x01: Manufacturer Code
  • 0x02: Sensor ID Code
  • 0x03: Command (write here)
  • 0x04: Color Number
  • 0x05: Red Value
  • 0x06: Green Value
  • 0x07: Blue Value
  • 0x08: White Value
  • 0x09: Color Index Number
  • 0x0A: Red Index
  • 0x0B: Green Index
  • 0x0C: Blue Index
  • 0x0E / 0x0F: Raw Red Reading (least / most significant byte)
  • 0x10 / 0x11: Raw Green Reading (lsb / msb)
  • 0x12 / 0x13: Raw Blue Reading (lsb / msb)
  • 0x14 / 0x15: Raw White Reading (lsb / msb)
  • 0x16 / 0x17: Normalized Red Reading (lsb / msb)
  • 0x18 / 0x19: Normalized Green Reading (lsb / msb)
  • 0x1A / 0x1B: Normalized Blue Reading (lsb / msb)
  • 0x1C / 0x1D: Normalized White Reading (lsb / msb)

Commands:

  • 0x00: Set Active Mode (turn the LED on)
  • 0x01: Set Passive Mode (turn the LED off)
  • 0x35: Set Sample Rate to 50Hz
  • 0x36: Set Sample Rate to 60Hz
  • 0x42: Perform Black Level Calibration
  • 0x43: Perform White Level Calibration

 

Compass & Acceleration Sensor (see more)

Default Address: 0x24

Registers:

  • 0x00: Firmware Version
  • 0x01: Manufacturer Code
  • 0x02: Sensor ID Code
  • 0x03: Command (write here)
  • 0x04 / 0x05: Heading (least/most significant byte)
  • 0x06 / 0x07: Accelerometer X Value (lsb / msb)
  • 0x08 / 0x09: Accelerometer Y Value (lsb / msb)
  • 0x0A / 0x0B: Accelerometer Z Value (lsb / msb)
  • 0x0C / 0x0D: Magnetometer X Value (lsb / msb)
  • 0x0E / 0x0F: Magnetometer Y Value (lsb / msb)
  • 0x10 / 0x11: Magnetometer Z Value (lsb / msb)
  • 0x12 / 0x13: Accelerometer X Offset (lsb / msb)
  • 0x14 / 0x15: Accelerometer Y Offset (lsb / msb)
  • 0x016 / 0x17: Accelerometer Z Offset (lsb / msb)
  • 0x18 / 0x19: Magnetometer X Offset (lsb / msb)
  • 0x1A / 0x1B: Magnetometer Y Offset (lsb / msb)
  • 0x1C / 0x1D: Magnetometer Z Offset (lsb / msb)
  • 0x1E / 0x1F: Magnetometer Tilt Coefficient (fsb / lsb)
  • 0x20 / 0x21: Accelerometer Scale Coefficient (fsb / lsb)
  • 0x22 / 0x23: Magnetometer X Scale Coefficient (fsb / lsb)
  • 0x24 / 0x25: Magnetometer Y Scale Coefficient (fsb / lsb)

Commands:

  • 0x00: Set Normal Measurement Mode
  • 0x43: Set Hard Iron Calibration Mode
  • 0x44: Measure “Tilted Down” Accelerometer Value
  • 0x47: Set Accelerometer Sensitivity / Gain Adjustment
  • 0x55: Measure “Tilted Up” Accelerometer Value
  • 0x57: Write Memory (you probably don’t need to do this)
  • 0x58: Set Accelerometer X Axis Null
  • 0x59: Set Accelerometer Y Axis Null
  • 0x5A: Set Accelerometer Z Axis Null

 

Integrating Gyro

Default Address: 0x20

Registers:

  • 0x00: Firmware Version
  • 0x01: Manufacturer Code
  • 0x02: Sensor ID Code
  • 0x03: Command (write here)
  • 0x04 / 0x05: Heading (least / most significant byte)
  • 0x06 / 0x07: Integrated Z Axis Value (lsb / msb)
  • 0x08 / 0x09: Raw X Axis Value (lsb / msb)
  • 0x0A / 0x0B: Raw Y Axis Value (lsb / msb)
  • 0x0C / 0x0D: Raw Z Axis Value (lsb / msb)
  • 0x0E / 0x0F: Z Axis Offset (lsb / msb)
  • 0x10 / 0x11: Z Axis Scale Coefficient (fsb / msb)

Commands:

  • oxoo: Set Normal Measurement Mode
  • 0x4E: Nullify Gyro Offset & Reset Z Axis Integrator
  • 0x52: Reset Z Axis Integrator
  • 0x57: Write Memory (you probably don’t need to do this)

 

Range Sensor

Default Address: 0x28

Registers:

  • 0x00: Firmware Version
  • 0x01: Manufacturer Code
  • 0x02: Sensor ID Code
  • 0x04: Ultrasonic Reading (linear, in cm)
  • 0x05: Optical Reading (exponential)

This sensor does not accept any commands.

 

IR Seeker Sensor (v3)

Default Address: 0x38

Registers:

  • 0x00: Firmware Version
  • 0x01: Manufacturer Code
  • 0x02: Sensor ID Code
  • 0x04: Direction (1200Hz)
  • 0x05: Strength (1200Hz)
  • 0x06: Direction (600Hz)
  • 0x07: Strength (600Hz)
  • 0x08 / 0x09: Raw Left Side Data, 1200Hz (lsb / msb)
  • 0x0A / 0x0B: Raw Right Side Data, 1200Hz (lsb / msb)
  • 0x0C / 0x0D: Raw Left Side Data, 600Hz (lsb / msb)
  • 0x0E / 0x0F: Raw Right Side Data, 600Hz (lsb / msb)

This sensor does not accept any commands.

 

Adafruit Sensors

All of the following information can be found on the Adafruit pages for each sensor.

RGB Color Sensor (PID: 1334)

Default Address: 0x29

Registers:

  • 0x12: Device ID
  • 0x13: Device Status
  • 0x14 / 0x15: Clear Reading (least / most significant byte)
  • 0x16 / 0x17: Red Reading (lsb / msb)
  • 0x18 / 0x19: Green Reading (lsb / msb)
  • 0x0A / 0x0B: Blue Reading (lsb / msb)

If you are interested in writing to this device, you should really look at the data sheet.

 

Absolute Orientation IMU – BNO055 (PID: 2472)

Default Address: 0x29

Registers:

  • 0x08 / 0x09: Accelerometer X Value (least / most significant byte)
  • 0x0A / 0x0B: Accelerometer Y Value (lsb / msb)
  • 0x0C / 0x0D: Accelerometer Z Value (lsb / msb)
  • 0x0E / 0x0F: Magnetometer X Value (lsb / msb)
  • 0x10 / 0x11: Magnetometer Y Value (lsb / msb)
  • 0x12 / 0x13: Magnetometer Z Value (lsb / msb)
  • 0x14 / 0x15: Gyroscope X Value (lsb / msb)
  • 0x16 / 0x17: Gyroscope Y Value (lsb / msb)
  • 0x18 / 0x19: Gyroscope Z Value (lsb / msb)
  • 0x1A / 0x1B: Heading (lsb / msb)
  • 0x1C / 0x1D: Roll (lsb / msb)
  • 0x1E / 0x1F: Pitch (lsb / msb)
  • 0x20 / 0x21: Quaternion W Value (lsb / msb)
  • 0x22 / 0x23: Quaternion X Value (lsb / msb)
  • 0x24 / 0x25: Quaternion Y Value (lsb / msb)
  • 0x26 / 0x27: Quaternion Z Value (lsb / msb)
  • 0x28 / 0x29: Linear X Acceleration (lsb / msb)
  • 0x2A / 0x2B: Linear Y Acceleration (lsb / msb)
  • 0x2C / 0x2D: Linear Z Acceleration (lsb / msb)
  • 0x2E / 0x2F: Gravity X Vector (lsb / msb)
  • 0x30 / 0x31: Gravity Y Vector (lsb / msb)
  • 0x32 / 0x33: Gravity Z Vector (lsb / msb)
  • 0x34: Temperature

If you are interested in writing to this device, you should really look at the data sheet.

AJ Foster

AJ is an FTA for the Tesla Robotics League in Orlando, FL. He enjoys teaching FTC-related stuff, helping teams at competitions, and making the things he learns accessible to everyone.