LCD display for Arduino how hard can it be?

Yeah so i thought i would have a play with an LCD display.

How hard can it be I foolishly thought.

in my ignorance I assumed they were all pretty much the same and spoke the same language.

My problem came when I wanted to talk with it on the UNO.

All the libraries are different.

Not being a good programer I tend to womble a bit of code from here and there,

and go off and do the fun stuff of building it,

and eventually get it to do what I want.

This becomes a bit of problem when the sketches are

made for different hardware.

the one i got on ebay was

Blue Compatible IIC/I2C/TWI YwRobot Serial LCD 1602 16x2 Module for Arduino

 

and at £1.98 not bad for the money.

20160324_021724__2_.jpg

top

 

20160324_021804.jpg

 

bottom

 

20160324_022002.jpg

 

screen output

 

20160324_021914.jpg

 

side view

 

The first big stumbling block is the address of the LCD

this isnt obvious and luckilly i found this sketch : SKETCH 1

  // i2c_scanner

 // --------------------------------------
    // 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 know.
    // Version 2, Juni 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 address might not be seen properly.
    //
    
    #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("Unknow 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
    }

 

 

 

 

The Next problem I had was sorting out the Libraries.

What I found was its best to remove the Libraries that dont work for your hardware.

some of them have common names like wire.h.

After you have them installed properly it all starts to make a bit more sense.

Anyway here is the sketch for the LCD clock if its helpful.

 

SKETCH 2 LCD clock

 

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);









/**
 * Clock Variables
 */
unsigned long currentMillis, previousMillis, elapsedMillis;
int seconds, minutes, hours;



void setup()
{
  // set the current time
hours=2;
minutes=33;
seconds=0;
   
    lcd.begin( 16, 2 );
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home

  lcd.print("LCD clock");
  delay(1000); // wait a bit
     lcd.clear();// clear the screen

}

void loop()
{
    setClock();
   
     lcd.setCursor ( 0, 1);
     lcd.print("   hr  mn   sc ");
     lcd.setCursor ( 0, 0);
     lcd.print("  ");lcd.print(hours);lcd.print(" : ");lcd.print(minutes);lcd.print(" : ");lcd.print(seconds);lcd.print("  ");
delay(300); // wait a bit
}

void setClock()
{
    currentMillis = millis();
    elapsedMillis += currentMillis - previousMillis;

    if (elapsedMillis > 999){
        seconds++;
        elapsedMillis = elapsedMillis - 1000;
    }

    if (seconds == 60){
        minutes++;
        seconds = 0;
    }
    if (minutes == 60){
        hours++;
        minutes = 0;
    }
    if (hours == 24){
        hours = 0;
    }

    previousMillis = currentMillis;
}

 

Hope some of this is helpful to the next person scratching their head and wishing china sent instructions for the £1.99 you spend.

LCD Code

Welcome to the world of $2.00 hardware and free software. You have encountered my major complaint against typical Arduino code methodology. It is as if having a “library” is a blessed event. Just install my religion, pay the high priest, and you are done.

First, I don’t think you have an I2C LCD display. The number of pins indicates a “parallel” bus model. It can still get more confusing as the parallel bus can be 4 or 8 bits wide. That being said, I have also seen the parallel mode displays connected to I2C, SPI, & UART controllers to reduce the wires needed at the expense of longer access times.

Post the LCD model specifics and I’m sure we can help.