🚚 Free delivery on orders over: €35 Croatia • €60 EU • $100 US

LCD I2C DEBUG

LCD I2C DEBUG-Uncategorized

INTRODUCTION

For those who have had problems with putting LCD with I2C adapter into operation, we will show a simple debug. We shall use the space in this tutorial to expand our knowledge of LCD library and all the posibilities it offers. Let’s start and see where it takes us..
Find I2C LCD library here.

I2C ADDRESS

I2C adapter will greatly help us to connect LCD to Dasduino. The problem arises when we have to set up the software settings. That part of the code looks like this:

// Pin settings the I2C adapter uses for LCD connection:
//                    addr,en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

Each controller has the same pinout. What most likely causes problems in your code is the addr part, i.e. I2C address. Luckily, there is a very simple solution – Wire library comes with Arduino IDE software and allows us to scan all I2C devices connected to Arduino which we communicate with i.e. their addresses. Here it is:

#include "Wire.h"
void setup() {
  Serial.begin (115200);
  Serial.println ("I2C tragač. Tražim ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Pronađena adresa: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1); 
      }
  }
  Serial.print ("Pronađen ");
  Serial.print (count, DEC);
  Serial.println (" uređaj(a).");
void loop() {}

Click on the Serial Monitor and here is the magic:

1 device with the 0x3F address is found, we change addr to 0x3F in the settings:

// Pin settings the I2C adapter uses for LCD connection:
//                    addr,en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

Actually, let’s immediately write something down on the LCD:

#include "Wire.h"
#include "LiquidCrystal_I2C.h"
// Pin settings the I2C adapter uses for LCD connection:
//                    addr,en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() 
{
  lcd.begin(20,4);  // we use lcd with 20 x 4
  lcd.backlight(); // turning the backlighting on 
  lcd.setCursor(0,0);    // we set the cursor to the first row and first column
  lcd.print("Bok Croduino!");  // and ofcourse, greeting message
 
}
void loop()  
{ }

 

CHANGING THE I2C ADDRESS

The first byte I2C is in charge of start and the address, i.e. 1 bit which is used for signaling start and 7 bits for the address. A total of 128 possible addresses. If, however, in some cases we have the same two addresses on Croduino, we will not be able to communicate with both devices, so we have to change one’s address. Some LCD I2C adapters have the possibility of changing addresses, check the picture:

By connecting these falls we will change the address of a device, according to the datasheet the addresses are (0- connected falls, 1 no contact):

The other way is by using I2C multiplexer, about which, on some other occasion.