• 注册
  • 查看作者
  • 如何用Arduino查询LCD1602液晶屏 I2C的初始地址是0x3f还是0x27?

    经过本人测试有效,特地写出教程供广大爱好者阅读。

    第一步:.连线arduino和LCD1602显示器

    如何用Arduino查询LCD1602液晶屏 I2C的初始地址是0x3f还是0x27? 如何用Arduino查询LCD1602液晶屏 I2C的初始地址是0x3f还是0x27?

     
    LCD1602—–arduino uno

    GND ———— GND

    VCC ———— 5V

    SDA ———— A4

    SCL ———— A5

     

    第二部,上传程序

    #include <Wire.h>

    void setup()

    {

    Wire.begin();

    Serial.begin(9600);

    Serial.println(” I2C 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 “);

    else

    Serial.println(“done “);

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

    }

    第三部,打开串口监视

    如何用Arduino查询LCD1602液晶屏 I2C的初始地址是0x3f还是0x27?

    通过上面我们已经可以看到扫描的结果了。

     

    创建日期:2018.05.06

    更新日期:2022.02.19

  • 0
  • 1
  • 0
  • 272
  • 请登录之后再进行评论

    登录
  • 动态
  • 单栏布局 侧栏位置: