获取lcd i2c地址

include <Wire.h

void
setup
(
)

{

Wire
.begin
(
)
;

Serial
.begin
(
9600
)
;
Serial
.println
(
"\nI2C Scanner"
)
;
}

void
loop
(
)

{

byte
error, address;
int
nDevices;

Serial
.println
(
"Scanning..."
)
;

nDevices = 0
;
for
(
address = 1
; address < 127
; address++ )

{

// The i2c_scanner uses the return value of

// the Write.endTransmisstion to see if

// a device did acknowledge to the address.

Wire
.beginTransmission
(
address)
;
error = Wire
.endTransmission
(
)
;

if
(
error == 0
)

{

Serial
.print
(
"I2C device found at address 0x"
)
;
if
(
address<16
)

Serial
.print
(
"0"
)
;
Serial
.print
(
address,HEX)
;
Serial
.println
(
" !"
)
;

nDevices++;
}

else
if
(
error==4
)

{

Serial
.print
(
"Unknow error at address 0x"
)
;
if
(
address<16
)

Serial
.print
(
"0"
)
;
Serial
.println
(
address,HEX)
;
}

}

if
(
nDevices == 0
)

Serial
.println
(
"No I2C devices found\n"
)
;
else

Serial
.println
(
"done\n"
)
;

delay
(
5000
)
; // wait 5 seconds for next scan

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,951评论 0 0
  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    赵宇_阿特奇阅读 5,947评论 0 2
  • Week 1 Reading a schematic Using a breadboard Resistors...
    Vinchent阅读 3,290评论 0 1
  • 昨天在小路自然很奢侈了享受了一天的自然教育培训。在这个培训中,大家就自然教育为了什么做了一点点的讨论。 有个面向日...
    WEI_曹蕾阅读 1,586评论 4 1
  • 为爱憔悴,为你心碎,为自己流泪。 忘了撕心,忘了裂肺,忘了这一切。 步步停歇,抽抽咽咽,独自在伤悲。 冷冷一夜,北...
    三古月南阅读 682评论 0 1