Jump to content

Arduino/CloverDisplayLtd

From Wikiversity

Liquid Crystal Display (LCD) Inspection/Research

[edit | edit source]
LCD taken from Panasonic fax machine

This LCD panel was taken out of a Panasonic fax machine. Ten wires are connected to the ten pins on the board of the LCD. Searching the web for specifications using the information printed on the board (Clover Display Ltd. M235 v4.1) was unsuccessful being unable to find the specific model. Fortunately, there is a tutorial on hacking a LCD to the Arduino in the example libraries of the arduino.exe under 'Liquid Crystal'. "LCDs have a parallel interface, meaning that the microcontroller has to manipulate several interface pins at once to control the display. The interface consists of the following pins:"

  • Register select (RS) pin - controls where in the LCD's memory that data is written to. ie. Data register - holds what goes on the screen, or an instruction register - where the LCD controller looks for instructions on what to do next.
  • Read/Write (R/W) pin - selects reading or writing mode
  • Enable pin - allows writing to the registers
  • 8 Data pins (D0-D7) - have states (high or low) that are the bits that are written to a register when writing is enabled, or values that are readable when reading is enabled.
  • Display Contrast pin (Vo) - controls contrariety or variance
  • Power Supply pins (+5V and GND) - powers/energizes the LCD
  • LED Backlight (Bklt+ and Bklt-) - Turn on and off glowing background

Problem Statement

[edit | edit source]

"The LiquidCrystal library allows you to control LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface." This Clover LCD only has ten pins, so will it be compatible with this Arduino library example? Luckily, only ten of the sixteen pins are used in the arduino tutorial.

Decision List

[edit | edit source]

If the same configuration of wires shown in the Arduino tutorial successfully displays the message, then I will be able to identify the pins.

  • Display, "Hello, World!" on the LCD
  • Identify the pins on the LCD board

Materials List

[edit | edit source]
  • Arduino Board
  • LCD Screen
  • 10kΩ Potentiometer
  • soldering iron
  • hook-up wire
  • breadboard

Software List

[edit | edit source]
  • Arduino 1.0 with the Liquid Crystal library

Next Steps

[edit | edit source]
Used the wrong potentiometer. Grabbed a 2kΩ instead of 10kΩ

Wiring

  1. Solder wires to the pins of the LCD (more colors makes the process easier)
  2. With the pins above the LCD screen connect pins 1 and 5 (from left to right) to an outer terminal (right) on the 10kΩ potentiometer
  3. Connect pin 2 to the other outer terminal (left) on the potentiometer and pin 3 to the middle terminal of the potentiometer
  4. Connect a wire from the 5V pin of the Arduino to the left terminal of the potentiometer which should be connected to pin 2 of the LCD, then connect a wire from a GND pin on the Arduino to the right terminal of the potentiometer which should be connected to pins 1 and 5 of the LCD
  5. Connect pins 4, 6, 7, 8, 9, and 10 of the LCD to Digital pins 12, 11 ,5, 4, 3, and 2 on the Arduino respectively

Run it

  • Finally, open the example library in the arduino.exe (File\Examples\LiquidCrystal\HelloWorld) and upload it! Note: the potentiometer adjusts the contrast, and needed to be turned mostly to the left (counterclockwise).

video

Pin ID

[edit | edit source]
  • Register select (RS) pin - pin 4
  • Read/Write (R/W) pin - pin 5
  • Enable pin - pin 6
  • Data Pins (D2-D5) - pins 7, 8, 9, and 10
  • Display Contrast pin (Vo) - pin 3
  • Power Supply pins (+5V and GND) - pin 2 and pin 1 respectively
  • LED Backlight (Bklt+ and Bklt-) - n/a
[edit | edit source]

This program will print out strings in 2 lines in LCD module HD44780 16x02 by setting the coordinator:

#include <Arduino.h>
#include <LiquidCrystal.h>

#define RS 8
#define EN 7
#define D4 6
#define D5 5
#define D6 4
#define D7 3

#define ROWS    16
#define COLUMS  2

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

void setup() {
  lcd.begin(ROWS, COLUMS);
  lcd.print("Hello, World !");
  lcd.setCursor(0, 1); // 0: column 1; 1: row 2
  lcd.print("8/1/2016");
}

void loop() {}

Text scrolling for big string when its size is bigger than 16 characters

[edit | edit source]
#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal.h>

//LCD define
#define RS 8
#define EN 7
#define D4 6
#define D5 5
#define D6 4
#define D7 12

#define ROW_SIZE    16
#define COLUMN_SIZE  2

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
void displayString(char *string);

void setup()
{
  lcd.begin(ROW_SIZE, COLUMN_SIZE);
}

void loop()
{
  displayString("Smart IoT device");
  delay(1000);
}

void displayString(char *string){
  //Avoid changing the same string every time calling the function
  char newString[100];
  strcpy(newString, string);
  
  int newStringSize = strlen(newString);
  int oversize = strlen(newString) - COLUMN_SIZE;
  lcd.clear();

  /*
    If size of string char is smaller than COLUMN_SIZE, print out then
    return, don't scroll text
  */
  if (oversize < 0) {
    lcd.setCursor(0,0);
    lcd.print(string);
    return;
  }  

  //For initial text scrolling of the first 16 character
  for (int i = 0; i < strlen(string); i++){
    lcd.setCursor(COLUMN_SIZE -1 -i, 0);
    lcd.print(string);
    delay(250);
  }

  //For displaying the oversize characters
  while (oversize > 0){
    int i = 0;

    //This way to form a new string takes time if the string is big
    while(i <= newStringSize){
      newString[i] = newString[i+1];
      i++;
    }
    
    newStringSize -= 1;

    oversize = newStringSize - COLUMN_SIZE;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(newString);
    delay(250);
  }
}

LCD module HD44780 with PCF8574 IO expander

[edit | edit source]

As using the raw LCD module HD44780 takes many pins from the Arduino, the PCF8574 IO expander connected to HD44780 to form a LCD module will take only 4 pins of the Arduino: SCL, SDA, VCC and GND. Those are I2C pins. The LCD module HD44780 with PCF8574 IO expander can also be called as the LCD I2C module.

Connections:

Arduino LCD I2C module
A4 (SDA) SDA
A5 (SCL) SCL
GND GND
3.3V/5V VCC (depend on module)

We will use 3rd library fdebrabander/Arduino-LiquidCrystal-I2C-library to communicate between the Arduino and the LCD module via the I2C pins.

[edit | edit source]
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define COLUMN_SIZE     16
#define ROW_SIZE        2
#define LCD_I2C_ADDRESS 0x3E

LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, COLUMN_SIZE, ROW_SIZE); // 0x3F is the address of the LCD

void setup()
{
  // initialize the LCD
  lcd.begin();

  // Turn on the blacklight and print a message.
  lcd.backlight();
  lcd.setCursor(1,0);
  lcd.print("Row 1: Hello, World!");
  lcd.setCursor(3,1);
  lcd.print("Row 3");

}

void loop(){}

LCD 16x02 with address 0x3E might need 3.3V instead of 5V.

LiquidCrystal_I2C lcd(0x3E, 16, 02);

Text scrolling for the big string as its size might be bigger than 16 characters

[edit | edit source]
#include <Arduino.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define COLUMN_SIZE     16
#define ROW_SIZE        2
#define LCD_I2C_ADDRESS 0x3E

LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, COLUMN_SIZE, ROW_SIZE); // 0x3F is the address of the LCD

void displayString(char *string);

void setup()
{
  Serial.begin(9600);
  lcd.begin();

  // Turn on the blacklight and print a message.
  lcd.backlight();
}

void loop(){
  //Display the string 3 times
  displayString("This is a very long string");
  displayString("This is a very long string");
  displayString("This is a very long string");
}

void displayString(char *string){
  //Avoid changing the same string every time calling the function
  char newString[100];
  strcpy(newString, string);
  
  int newStringSize = strlen(newString);
  int oversize = strlen(newString) - COLUMN_SIZE;
  lcd.clear();

  /*
    If size of string char is smaller than COLUMN_SIZE, print out then
    return, don't scroll text
  */
  if (oversize < 0) {
    lcd.setCursor(0,0);
    lcd.print(string);
    return;
  }  

  //For initial text scrolling of the first 16 character
  for (int i = 0; i < strlen(string); i++){
    lcd.setCursor(COLUMN_SIZE -1 -i, 0);
    lcd.print(string);
    delay(250);
  }

  //For displaying the oversize characters
  while (oversize > 0){
    int i = 0;

    //This way to form a new string takes time if the string is big
    while(i <= newStringSize){
      newString[i] = newString[i+1];
      i++;
    }
    
    newStringSize -= 1;

    oversize = newStringSize - COLUMN_SIZE;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(newString);
    delay(250);
  }
}

Note: The processing might be slow and result in the overflowed string display in line 2 if the string is big.