본문 바로가기
ESP8266

esp8266 - i2c 주소 찾기 ( find i2c address)

by space father 2023. 1. 2.
반응형

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//==NodeMCU==START
#define D0 (16)
#define D1 (5//SCL
#define D2 (4//SDA
#define D3 (0)
#define D4 (2)
#define D5 (14)
#define D6 (12)
#define D7 (13)
#define D8 (15)
 
#define SD0 (7)
#define SD1 (8)
#define SD2 (9)
#define SD3 (10)
//==NodeMCU==END
 
#include <Wire.h>
 
void find_i2c_address()
{
  Serial.println ("I2C Scanning ......");  
 
  bool found_flag = false;
  Wire.begin(D2,D1); //SDA(D2), SCL(D1)
  for (int i = 1; i < 128; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
    {
      Serial.print ("I2C Address: 0x");
      Serial.println (i, HEX);
      found_flag = true;
    }
  }
  if(!found_flag)
    Serial.println ("can not found i2c address.");
 
  delay(1000);
}
 
void setup() {
  Serial.begin (115200);
  Serial.println();
  delay(3000);  
}//setup
 
void loop()
{
  find_i2c_address();
}
cs

 

 

Result

lcd: 16x2

I2C Scanning ......
I2C Address: 0x3F
I2C Scanning ......
I2C Address: 0x3F
I2C Scanning ......
I2C Address: 0x3F

 

lcd: 20x4

I2C Address: 0x27
I2C Scanning ......
I2C Address: 0x27
I2C Scanning ......
I2C Address: 0x27

'ESP8266' 카테고리의 다른 글

ESP8266 - lcd 20x4 with ntp  (0) 2023.01.02
esp8266 - lcd 16x2 and ntp  (0) 2023.01.02
esp8266 - led 깜빡이기 (blink)  (0) 2023.01.02
ESP8266-OLED(128x64) and NTP  (0) 2023.01.01
ESP8266 - OLED (128x32) and NTP  (0) 2022.12.30