这篇文档介绍如何在Ubuntu下使用I2C。
连线
I2C ASensor SCL
<-> I2C_SCK_A (PIN 22)
Sensor SDA
<-> I2C_SDA_A (PIN 23)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C BSensor SCL
<-> I2C_SCK_B (PIN 25)
Sensor SDA
<-> I2C_SDA_B (PIN 26)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C ASensor SCL
<-> I2C_SCK_A (PIN 22)
Sensor SDA
<-> I2C_SDA_A (PIN 23)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C BSensor SCL
<-> I2C_SCK_B (PIN 25)
Sensor SDA
<-> I2C_SDA_B (PIN 26)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C 3Sensor SCL
<-> I2C0_SCK (PIN 22)
Sensor SDA
<-> I2C0_SDA (PIN 23)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C 4Sensor SCL
<-> I2C1_SCK (PIN 25)
Sensor SDA
<-> I2C1_SDA (PIN 26)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C ASensor SCL
<-> I2CA_SCK (PIN 25)
Sensor SDA
<-> I2CA_SDA (PIN 26)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
I2C FSensor SCL
<-> I2CF_SCK (PIN 22)
Sensor SDA
<-> I2CF_SDA (PIN 23)
Sensor GND
<-> GND
Sensor VCC
<-> 5V or 3.3V
//取决于传感器供电
检测设备
检索设备在I2C A
:
1 | sudo i2cdetect -y -r 1 |
检索设备在I2C B
:
1 | sudo i2cdetect -y -r 2 |
检索设备在I2C A
:
1 | sudo i2cdetect -y -r 1 |
检索设备在I2C B
:
1 | sudo i2cdetect -y -r 2 |
检索设备在I2C 3
:
1 | sudo i2cdetect -y -r 3 |
检索设备在I2C 4
:
1 | sudo i2cdetect -y -r 4 |
检索设备在I2C A
:
1 | sudo i2cdetect -r -y 0 |
检索设备在I2C F
:
1 | sudo i2cdetect -r -y 5 |
如果连线正确并且所接传感器是正常的那么你会看到所接设备的地址,如:0x1d
,0x18
and 0x51
。
从设备读取寄存器值
从挂载在I2C A
上设备地址为0x1d
的设备读取寄存器0x0d
的值。
1 | sudo i2cget -f -y 1 0x1d 0x0d |
更多用法请参考I2C工具帮助信息。