Search Code

Bí ọ̀nà Láti Ṣeto Àwọn Adirẹsi I²C àti Lílo Ẹ̀rọ Ìṣàwárí I²C fún LCD1602 àti LCD2004

Bí ọ̀nà Láti Ṣeto Àwọn Adirẹsi I²C àti Lílo Ẹ̀rọ Ìṣàwárí I²C fún LCD1602 àti LCD2004

Nínú ẹ̀kọ́ yìí, a óò ṣàwárí bí a ṣe ń ṣètò àdírẹ́sì I²C àti bí a ṣe ń lo ọ̀pá ìwọ̀n I²C fún àwọn àfihàn LCD1602 àti LCD2004. Òye ìbánisọ̀rọ̀ I²C ṣe pàtàkì fún ìsopọ̀ àwọn modulu LCD wọ̀nyí pẹ̀lú àwọn iṣẹ́ Arduino rẹ, tí ó ń jẹ́ kí ìgbékalẹ̀ data àti ìṣàkóso ṣiṣẹ́ dáradára. Ní ìparí ìtọ́sọ́nà yìí, ìwọ yóò ní agbára láti mọ àdírẹ́sì I²C ti àwọn LCD rẹ ní pípé àti láti rí i pé wọ́n ń ṣiṣẹ́ lọ́nà tí ó tọ́.

LCD1602-I2C display module with 4 wires

A óò lo sẹ́nsọ̀ BMP-180 gẹ́gẹ́ bí ara iṣẹ́ yìí, èyí tí ó ń ṣiṣẹ́ pẹ̀lú ìbánisọ̀rọ̀ I²C. Sẹ́nsọ̀ náà ń pèsè àwọn ìwọ̀n ìgbóná àti ìkùnnà, èyí tí a lè fi hàn lórí LCD1602 tàbí LCD2004. Ẹ̀kọ́ yìí yóò ní àwọn ìtọ́sọ́nà ìsopọ̀, àwọn ìpín kóòdù, àti àṣefihàn àwọn àbájáde tí a retí. Fún òye tí ó jinlẹ̀ sí i nípa ìwòran, rí i pé o wo fídíò tí ó jọmọ́ (nínú fídíò ní 00:00).

Ohun èlò Tí A Ṣàlàyé

Àwọn èròjà pàtàkì fún iṣẹ́ yìí ní sẹ́nsọ̀ BMP-180, àfihàn LCD1602 tàbí LCD2004, àti bọ́ọ̀dù Arduino kan. BMP-180 jẹ́ sẹ́nsọ̀ ìkùnnà onínọ́ńbà tí ó ń bánisọ̀rọ̀ nípasẹ̀ ìlànà I²C, tí ó nílò àwọn ìlà data méjì péré: SDA (ìlà data) àti SCL (ìlà aago). Àwọn àfihàn LCD náà jẹ́ I²C tí ó bá mu, àti pé a lè ṣàkóso wọ́n ní rọrùn nípa lílo ìlànà ìbánisọ̀rọ̀ kan náà, tí ó ń jẹ́ kí ìṣètò di mímọ́ àti tí ó gbéṣẹ́.

BMP-180 ń ṣiṣẹ́ pẹ̀lú foltiage ìpèsè tí ó wà láàrin 1.8V àti 3.6V, èyí tí ó túmọ̀ sí pé a lè fi agbára fún un nípasẹ̀ olùṣàkóso foltiage bí o bá ń lo orísun foltiage tí ó ga. Àwọn àfihàn LCD, ní ọwọ́ kejì, ń ṣiṣẹ́ ní 5V ní pàtàkì, tí ó jẹ́ kí ìsopọ̀ pẹ̀lú bọ́ọ̀dù Arduino rọrùn láìsí àwọn èròjà àfikún.

Àwọn Àlàyé Datasheet

Olùṣelọ́pọ̀ Bosch
Nọ́ńbà apá BMP-180
Foltiage Logic/IO 1.8 - 3.6 V
Foltiage ìpèsè 1.8 - 3.6 V
Ìwọ̀n àbájáde (fún ikanni) 3.6 µA
Ìwọ̀n tí ó ga jùlọ (fún ikanni) 1 mA
Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWM N/A
Àwọn ìpele ìbèèrè logic N/A
Ìrẹwẹ̀sì foltiage / RDS(on) / ìkún N/A
Àwọn ìwọ̀n ìgbóná -40 sí +85 °C
Àpótí 3.6 x 3.8 mm
Àwọn àkíyèsí / àwọn oríṣi Sẹ́nsọ̀ ìgbóná àti ìkùnnà

 

  • Rí i pé foltiage ìpèsè tọ́: 1.8V sí 3.6V fún BMP-180.
  • Lo àwọn resistor ìfà sókè lórí àwọn ìlà SDA àti SCL fún ìbánisọ̀rọ̀ I²C tí ó dúró ṣinṣin.
  • Jẹ́ kí àwọn okun kúrú láti yẹra fún ìbàjẹ́ àmì.
  • Ṣàyẹ̀wò àdírẹ́sì I²C tí ó tọ́ nígbà ìwọ̀n.
  • Ṣàkíyèsí ìwọ̀n ìgbóná: -40 sí +85 °C fún BMP-180.

Àwọn Ìtọ́sọ́nà Ìsopọ̀

Arduino wirng for LCD1602 with I2C
Arduino wirng for LCD1602 with I2C

Láti sopọ̀ sẹ́nsọ̀ BMP-180 àti àfihàn LCD sí Arduino rẹ, tẹ̀lé àwọn ìgbésẹ̀ wọ̀nyí:

Kọ́kọ́, sopọ̀ ẹ̀yin Vn ti BMP-180 sí ìjàde 5V lórí Arduino. Nígbà tí ó tẹ̀lé, sopọ̀ ẹ̀yin GND ti BMP-180 sí ilẹ̀ Arduino. Ẹ̀yin SDA ti BMP-180 yẹ kí ó sopọ̀ sí ẹ̀yin A4 ti Arduino, nígbà tí ẹ̀yin SCL sopọ̀ sí A5.

Fún LCD1602 tàbí LCD2004, sopọ̀ ẹ̀yin VCC sí 5V lórí Arduino àti ẹ̀yin GND sí ilẹ̀ pẹ̀lú. Ẹ̀yin SDA ti LCD yẹ kí ó sopọ̀ sí A4 (tí a pín pẹ̀lú BMP-180), àti ẹ̀yin SCL yẹ kí ó sopọ̀ sí A5.

Ìṣètò yìí ń jẹ́ kí àwọn ẹ̀rọ méjèèjì bánisọ̀rọ̀ lórí ọ̀nà I²C kan náà, tí ó ń rí i pé ìṣètò di mímọ́ àti tí ó gbéṣẹ́.

Àwọn Àpẹẹrẹ Kóòdù & Ìtọ́sọ́nà

Láti ṣe ìwọ̀n àwọn àdírẹ́sì I²C, a óò lo ìpín kóòdù kan tí ó rọrùn. Àpẹẹrẹ tí ó tẹ̀lé yìí ń bẹ̀rẹ̀ ìbánisọ̀rọ̀ I²C àti ń múra ìṣàkóso serial:


#include 

void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial); // Leonardo: dúró fún ìṣàkóso serial
  Serial.println("\nI2C Scanner");
}

Kóòdù yìí ń bẹ̀rẹ̀ ilé-ìkàwé Wire fún ìbánisọ̀rọ̀ I²C àti ń ṣètò ìṣàkóso serial fún ìjàde. Ó ṣe pàtàkì fún ṣíṣàtúnṣe àti rírí i pé àwọn ẹ̀rọ I²C ti mọ̀.

Ìgbésẹ̀ loop ń ṣe ìwọ̀n fún àwọn ẹ̀rọ lórí ọ̀nà I²C àti ń tẹ̀ àwọn àdírẹ́sì wọn jáde:


void loop() {
  byte error, address;
  int nDevices = 0;
  Serial.println("Scanning...");

  for(address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      Serial.println(address, HEX);
      nDevices++;
    }
  }
  if (nDevices == 0) Serial.println("No I2C devices found\n");
  delay(5000); // dúró fún ìṣẹ́jú àáyá 5 fún ìwọ̀n tí ó tẹ̀lé
}

Loop yìí ń ṣàyẹ̀wò àdírẹ́sì kọ̀ọ̀kan láti 1 sí 127, tí ó ń gbìyànjú láti bánisọ̀rọ̀ pẹ̀lú àwọn ẹ̀rọ tí ó wà níbẹ̀. Bí ẹ̀rọ kan bá jẹ́wọ́ ìbánisọ̀rọ̀, a óò tẹ àdírẹ́sì rẹ̀ sí ìṣàkóso serial. Èyí jẹ́ ìgbésẹ̀ pàtàkì nípa mímọ àdírẹ́sì I²C ti LCD rẹ tàbí àwọn ẹ̀rọ mìíràn tí a sopọ̀.

Àṣefihàn / Ohun Tí O Lè Retí

Nígbà tí a bá ń ṣe ìwọ̀n I²C, ìwọ yóò rí àwọn ifiranṣẹ́ nínú ìṣàkóso serial tí ó ń fi hàn bóyá àwọn ẹ̀rọ I²C kan wà. Bí ó bá ṣe àṣeyọrí, ìjàde yóò fi àwọn àdírẹ́sì ti àwọn ẹ̀rọ tí a sopọ̀ hàn, tí a kọ ní ọ̀nà hexadecimal (bí àpẹẹrẹ, "I2C device found at address 0x27"). Bí a kò bá rí àwọn ẹ̀rọ kankan, ìwọ yóò rí ifiranṣẹ́ tí ó bá mu.

Ó ṣe pàtàkì láti rí i pé gbogbo àwọn ìsopọ̀ dúró ṣinṣin àti pé a pèsè àwọn ìpele foltiage tí ó tọ́ láti yẹra fún àwọn ìṣòro nípa ìwárí ẹ̀rọ (nínú fídíò ní 05:30).

Aworan

Arduino wirng for LCD1602 with I2C
Arduino wirng for LCD1602 with I2C
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD2004_display-1
LCD2004_display-1
LCD2004_display-2
LCD2004_display-2
I2C_module
I2C_module
125-Arduino code for finding an I2C address
Ede: C++
// --------------------------------------
//http://playground.arduino.cc/Main/I2cScanner
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not known.
// Version 2, June 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26, 2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit addresses might not be seen properly.
// Watch Video explaining I2C address: https://www.youtube.com/watch?v=bqMMIbmYJS0
//
 
#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  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("Unknown 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
}

Ohun ti o le nilo

Orisun & itọkasi

Ko si awọn orisun sibẹsibẹ.

Fáìlìs📁

Awọn ile-ikawe Arduino (zip)

Fayile Fritzing