how to connect I2c LCD to arduino (library included)

in #utopian-io7 years ago (edited)

in this instructable i am going to share how to connect i2c LCD to arduino board i will include the code/sketch that i use for the uno.

HARDWARE

the parts that we will going to use are:

  • arduino uno board
  • male-female jumpers
  • i2c type lcd 
  • type B uno usb cable

I am going to set up the hardware first, so we are going to connect the lcd to the board using jumpers

the LCD GND to the GND on uno, the VCC to 5V, the SDA to the analog4, the SCL to the A5, look at the diagram, if you are using the non i2c breaker lcd then you have to use breadboard in this case the pins maybe diffrent.

and here is my set up.

connect it to your pc if the lcd lights up your wiring is correct..

SOFTWARE

lets go now for the software, first we have to download the arduino ide you can search  that out and download the software: https://www.arduino.cc/en/Main/Software  its very basic if you are going to start programming on arduino you shoud have the ide. 

1 download the i2c scanner on this link http://www.mediafire.com/file/f7oaa4et779yaaz/i2c_scanner.ino

2. 2. download the i2c library using my repository link here: https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library just click the >>clone/ download then download ZIp<<

after downloading the library open the arduino ide, -select->SKETCH>>INCLUDE LIBRARY>>>ADD .ZIP LIBRARY.

Locate the arduinoliquid zip file that you have downloaded. then select. and wait for the process.

once the library is already in the program now open the i2c scanner that we have recently downloaded, if your system cannot open the file >> just left click on the file>> open with>> then locate the arduino uno ide. the file ino is for arduino. after that the i2c scanner code will appear on the sketch. or you can copy this code for i2c scanner sketch:

// i2c_scanner
#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}

After that click COMPILE>>> THEN UPLOAD it to the uno board. once done click on the TOOLS>> SERIAL MONITOR.

the port com will appear and the scannned address of your module will state, so my address will be 0x27 before the ! sign.. we have different address of the module thats why we need to scan the module sometimes its depends on the unit of the lcd.

sketch code we have to set up the and find the i2c address of your module: here is the i2c address;

LiquidCrystal_I2C lcd(--ENTER MODULE ADDRESS HERE--, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);


I will going delete the --ENTER MODULE ADDRESS HERE--- and change it to the address of my module 0x27 so it will become:

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

we have the library included and the address of the module, so it time for the last sketch i will paste my sketch code here:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
lcd.begin(16, 2); 

}
void loop() 
{
lcd.print(" UTOPIAN.IO"); 
lcd.setCursor(0, 0);
delay(1500);
lcd.clear();
lcd.print("STEEMIT");
lcd.setCursor(0, 1);
delay(1500);
lcd.setCursor(6, 1);
lcd.print("FOLLOW ");
delay(1500);
lcd.clear();
lcd.print("@PAKGANERN");
lcd.setCursor(0, 1);
delay(1500);
lcd.print("FOR MORE");
delay(1500);
lcd.clear();
}

then Delete the 3rd line of my code with your address if you have the same address as mine you dont have to do it. once done we have to verify the sketch by compiling once done then upload it to the board.

DONE UPLOADING sketch

in case i do it reapedly beacause no text appears on the lcd, i ve already check the wirings and theres no problem with it.

If you have the same problem as mine GET A SCREW driver then adjust the calibration of the i2c breaker

and then tadahh the text that ive sketch is now reflecting on the lcd, you can change the character in my code with yours. by the way upload this sketch without adding the library will not work..

so thats it for now. thank you:) ()



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @pakganern I am @utopian-io. I have just upvoted you!

Achievements

  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

could somone help me?
for a project on school i need to use arduino industrial 101 horrible thing never get it.
my problem right now is that is doesnt have the A4 and A5 ports so i cant connect the screen to them. is there a way i can change the ports that are used in the library so that it wil work with for example A2 and A3

What type of ur lcd is this the i2c or the old one with 16 pins?

Wow bro ayos to ah! Ang cool! Turuan mo ko 😭

tinuruan lang din ako ng kapatid ko hahaha

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 67271.13
ETH 3515.41
USDT 1.00
SBD 2.70