English
English
简体中文
日本語
I2C / Protocol reference
PDF

Unit AIN4-20mA I2C Communication Protocol


1. Basic Information

Item Description
Product Unit AIN4-20mA
SKU U162
Bus I2C, slave mode
Default I2C Address (7-bit) 0x55
Register Address Width 8 bit
Register Data Width 8 bit; multi-byte fields consist of consecutive registers
Multi-byte Endianness Little-endian; the lowest address stores the least significant byte
Protocol Version V1
Original Release Date 2023-01-30

1.1 Access Permissions

Permission Description
R Read-only
R/W Read/write
Reserved Reserved; do not access

1.2 General Access Flow

Register Write

The host sends a 1-byte starting register address followed by one or more data bytes:

START + SlaveAddr(W) + RegAddr + Data0 [+ Data1 ...] + STOP

For a 16-bit field, start at its low-byte address and write 2 consecutive bytes.

Register Read

The host first writes the 1-byte starting register address and then reads the required data:

START + SlaveAddr(W) + RegAddr + RESTART + SlaveAddr(R) + Data0 [+ Data1 ...] + STOP

For a 16-bit field, start at its low-byte address and read 2 consecutive bytes.

1.3 Data Types and Endianness

  • UINT8: 8-bit unsigned integer.
  • UINT16: Combine as Byte0 | (Byte1 << 8).
  • The raw ADC value uses the lower 12 bits of the UINT16 value.
  • Current and calibration reference values are expressed in 0.01 mA:
Current (mA) = Register Value / 100

2. Register/Command Overview

Address/Range Name Length Access Default Retained After Power-Off Summary Details
0x00 ~ 0x01 ADC Raw Value 2 R Runtime No Raw 12-bit ADC sample 4.1
0x20 ~ 0x21 Current Value 2 R Runtime No Measured current in 0.01 mA 4.2
0x30 ~ 0x31 Reference Current 2 R/W Not specified Not specified Calibration reference current in 0.01 mA 4.3
0xFE Firmware Version 1 R Firmware-defined Firmware-defined Firmware version number 4.4
0xFF I2C Address 1 R/W 0x55 Not specified Current I2C slave address 4.5

3. Address Conventions

3.1 Address Regions

Address/Range Region Description
0x00 ~ 0x01 ADC Measurement Raw ADC sample
0x20 ~ 0x21 Current Measurement Converted current value
0x30 ~ 0x31 Current Calibration Calibration reference current
0xFE ~ 0xFF Fixed System Addresses Firmware version and I2C address

3.2 Fixed Addresses

Address Name Description
0xFE Firmware Version Reads the current firmware version number
0xFF I2C Address Reads or changes the current I2C slave address

3.3 Reserved Addresses

All addresses not listed in Section 2 are undefined in protocol V1 and must be treated as Reserved. The host must not read or write these addresses or rely on their returned values or write behavior.


4. Register Details

4.1 ADC Raw Value

Address/Range Length Access Description
0x00 ~ 0x01 2 byte R Raw 12-bit ADC sample
Address Parameter Type Description
0x00 ADC1-L UINT8 Low byte of the raw ADC value
0x01 ADC1-H UINT8 High byte of the raw ADC value; use the lower 12 bits of the combined result

Read 2 consecutive bytes starting at 0x00, then combine them as follows:

adc_raw = (ADC1-L | (ADC1-H << 8)) & 0x0FFF

4.2 Current Value

Address/Range Length Access Description
0x20 ~ 0x21 2 byte R Current measurement
Address Parameter Type Description
0x20 Current1-L UINT8 Low byte of the current value
0x21 Current1-H UINT8 High byte of the current value

Read 2 consecutive bytes starting at 0x20, then convert them as follows:

current_raw = Current1-L | (Current1-H << 8)
current_mA = current_raw / 100.0

For example, if the returned data is E8 03:

current_raw = 0x03E8 = 1000
current_mA = 1000 / 100.0 = 10.00 mA

4.3 Reference Current

Address/Range Length Access Description
0x30 ~ 0x31 2 byte R/W Calibration reference current
Address Parameter Type Description
0x30 Ref Current-L UINT8 Low byte of the calibration reference current
0x31 Ref Current-H UINT8 High byte of the calibration reference current

Calibration procedure:

  1. Apply a known current using a standard signal source.
  2. Multiply the current by 100 to obtain a UINT16 calibration value.
  3. Starting at 0x30, write the low byte followed by the high byte.
  4. Wait at least 500 ms after writing before reading the measurement.

For 10.00 mA:

Calibration Value = 10.00 × 100 = 1000 = 0x03E8
Data written to 0x30 ~ 0x31 = E8 03

4.4 Firmware Version

Address Length Access Description
0xFE 1 byte R Current firmware version number

Read register 0xFE to obtain the 1-byte firmware version number.

4.5 I2C Address

Address Length Access Description
0xFF 1 byte R/W Current 7-bit I2C address
  • Read 0xFF to obtain the current I2C address.
  • Write a 1-byte new address to 0xFF to change the device address.
  • After the address is changed successfully, subsequent host transactions must use the new address.

5. Arduino Driver Mapping

Protocol Function Arduino Driver Method
Read raw ADC value getADC12BitsValue(0)
Read current value getCurrentValue(0)
Write calibration current setCalCurrent(0, value)
Read firmware version getFirmwareVersion()
Read I2C address getI2CAddress()
Change I2C address setI2CAddress(addr)

6. Version History

Document Version Protocol Version Date Description
V1.0 V1 2023-01-30 Initial release of the I2C register protocol
V1.1 V1 2026-08-05 Restructured using the M5Stack Atom Driver I2C Control Protocol template; added the general access flow, register overview, address conventions, and register details without changing the protocol