Senin, 19 September 2016

Tutorial & Sample Project Module LCD Nokia 5110 / 3310 for Arduino JILID 1


Informasi Umum

Module LCD Nokia 5110 adalah salah satu jenis LCD yang bisa kita gunakan sebagai media display data output oleh Arduino.Kelebihan LCD jenis ini adalah Harga yang murah dan penggunaan PIN yang lumayan sedikit (Serial SPI).


Secara resmi module ini di produksi oleh produsen Adafruit dan Sparkfun Electronics
Berikut adalah Spesifikasi dari Module ini :

•Single chip LCD controller/driver
•48 row, 84 column outputs
•Display data RAM 48×84 bits
•On-chip:
– Generation of LCD supply voltage (external supplyalso possible)
– Generation of intermediate LCD bias voltages
– Oscillator requires no external components (externalclock also possible).
•ExternalRES (reset) input pin
•Serial interface maximum 4.0 Mbits/s
•CMOS compatible inputs
•Mux rate: 48
•Logic supply voltage range VDDto VSS: 2.7 to 3.3 V
•Display supply voltage range VLCDto VSS
– 6.0 to 8.5 V with LCD voltage internally generated(voltage generator enabled)
– 6.0 to 9.0 V with LCD voltage externally supplied(voltage generator switched-off).
•Low power consumption, suitable for battery operatedsystems
•Temperature compensation of VLCD
•Temperature range:−25 to +70°C.


Adafruit datasheets download disini.

Sparkfun datasheets download disini.


Dari data diatas kita dapat melihat bahwa LCD ini adalah jenis monochrom dengan jumlah pixel 84x48 dot dengan area writeable pixel 30x20mm.

LCD ini menggunakan VCC 2.7 sampai 3.3V untuk controllernya (saya sarankan menggunakan pin 3.3V untuk penggunaan dengan Arduino) dan untuk lampu backlightnya (BL) saya sarankan menggunakan VCC 5V (pin 5V) pada Arduino


Pin Interface

Secara umum baik yang produksi Adafruit (board biru) maupun punya Sparkfun (board merah) module ini mempunyai 8pin interface dengan urutan sebagai berikut :

-RST --> Reset
-CE / CS --> Chip Select
-DC --> Data / Command Select
-Din --> Data in
-Clk / Sck --> Clock
-Vcc --> + Power Supply 2.7-3.3V
-BL --> + Lampu Backlight 3.3-5V
-Gnd --> Common 0V untuk Controller dan Backlight

Urutan pin bisa saja berbeda pada breakoutboard module anda.


Library and Wiring to Arduino

Ada beberapa library yang bisa kita gunakan untuk control LCD ini dengan Arduino seperti Library Uglib namun kita akan menggunakan Standar Adafruit library untuk LCD ini,silahkan download librarynya pada link dibawah :

library LCD 5110 Adafruit download disini atau http://adafru.it/d7j

library pendukung Adafruit_GFX download disini atau http://adafru.it/cBB

Masukan kedua library diatas ke dalam folder libraries pada folder installer Arduino IDE di drive C.


standar wiring module lcd 5110 dengan Arduino (uno)
-RST --> D3
-CE / CS --> D4
-DC --> D5
-Din --> D6
-Clk / Sck --> D7
-Vcc --> pin 3.3V Arduino
-BL --> pin 5V Arduino
-Gnd --> pin GND Arduino

pada standar wiring diatas kita menggunakan pin D3,D4,D5,D6 dan D7 sebagai data interfacenya,namun apabila penggunaan tersebut tidak memungkinkan dalam sistem kita (pin tersebut dipakai oleh module lain) maka kita dapat memindahkanya ke pin lain (bahkan pin Analog in pun bisa kita gunakan) dan jangan lupa mengganti declare pin library pada 
sketch codingnya.


contoh standar wiring :

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
//-----------------------------------------------------------------------
// Wiring lcd5110 dengan Arduino
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
//------------------------------------------------------------------------
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);



contoh penggantian wiring :

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
//-----------------------------------------------------------------------
// Wiring lcd5110 dengan Arduino
// pin 13 - Serial clock out (SCLK)
// pin 12 - Serial data out (DIN)
// pin 11 - Data/Command select (D/C)
// pin 10 - LCD chip select (CS)
// pin 9 - LCD reset (RST)
//------------------------------------------------------------------------
Adafruit_PCD8544 display = Adafruit_PCD8544(13, 12, 11, 10, 9);


contoh penggantian wiring dengan Analog Pin :

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
//-----------------------------------------------------------------------
// Wiring lcd5110 dengan Arduino
// pin A5 - Serial clock out (SCLK)
// pin A4 - Serial data out (DIN)
// pin A3 - Data/Command select (D/C)
// pin A2 - LCD chip select (CS)
// pin A1 - LCD reset (RST)
//------------------------------------------------------------------------
Adafruit_PCD8544 display = Adafruit_PCD8544(A5, A4, A3, A2, A1);



Example Library test


Lakukan wiring Arduino dengan LCD 5110 module dengan standar wiring :
standar wiring module lcd 5110 dengan Arduino (uno)

-RST --> D3
-CE / CS --> D4
-DC --> D5
-Din --> D6
-Clk / Sck --> D7
-Vcc --> pin 3.3V Arduino
-BL --> pin 5V Arduino
-Gnd --> pin GND Arduino

Setelah memasukan library yang dibutuhkan Silahkan buka File Example melalui Arduino IDE

klik File --> Example --> PCD8544 Nokia LCD Library --> pcdtest


atau copy paste text dibawah ini kedalam Arduino IDE New File dan upload ke Arduino Board Anda :


#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer.  Be careful sharing these pins!

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

const byte belajarduino[] PROGMEM = {
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0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=
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

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

  display.begin();
  // init done

  // you can change the contrast around to adapt the display
  // for the best viewing!
  display.setContrast(50);

  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer

  display.drawBitmap(0,0, belajarduino, 88, 44, 1);
  display.display();
  delay (3000);
  display.clearDisplay();

  // draw many lines
  testdrawline();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw rectangles
  testdrawrect();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw multiple rectangles
  testfillrect();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw mulitple circles
  testdrawcircle();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw a circle, 10 pixel radius
  display.fillCircle(display.width()/2, display.height()/2, 10, BLACK);
  display.display();
  delay(2000);
  display.clearDisplay();

  testdrawroundrect();
  delay(2000);
  display.clearDisplay();

  testfillroundrect();
  delay(2000);
  display.clearDisplay();

  testdrawtriangle();
  delay(2000);
  display.clearDisplay();
   
  testfilltriangle();
  delay(2000);
  display.clearDisplay();

  // draw the first ~12 characters in the font
  testdrawchar();
  display.display();
  delay(2000);
  display.clearDisplay();

  // text display tests
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("Hello, world!");
  display.setTextColor(WHITE, BLACK); // 'inverted' text
  display.println(3.141592);
  display.setTextSize(2);
  display.setTextColor(BLACK);
  display.print("0x"); display.println(0xDEADBEEF, HEX);
  display.display();
  delay(2000);

  // rotation example
  display.clearDisplay();
  display.setRotation(1);  // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further.
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("Rotation");
  display.setTextSize(2);
  display.println("Example!");
  display.display();
  delay(2000);

  // revert back to no rotation
  display.setRotation(0);

  // miniature bitmap display
  display.clearDisplay();
  display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  display.display();

  // invert the display
  display.invertDisplay(true);
  delay(1000); 
  display.invertDisplay(false);
  delay(1000); 

  // draw a bitmap icon and 'animate' movement
  testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT);
}


void loop() {
  
}


void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];
  randomSeed(666);     // whatever seed
 
  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = random(display.width());
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = random(5) + 1;
    
    Serial.print("x: ");
    Serial.print(icons[f][XPOS], DEC);
    Serial.print(" y: ");
    Serial.print(icons[f][YPOS], DEC);
    Serial.print(" dy: ");
    Serial.println(icons[f][DELTAY], DEC);
  }

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
    }
    display.display();
    delay(200);
    
    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, WHITE);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > display.height()) {
 icons[f][XPOS] = random(display.width());
 icons[f][YPOS] = 0;
 icons[f][DELTAY] = random(5) + 1;
      }
    }
   }
}


void testdrawchar(void) {
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);

  for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    //if ((i > 0) && (i % 14 == 0))
      //display.println();
  }    
  display.display();
}

void testdrawcircle(void) {
  for (int16_t i=0; i<display.height(); i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, BLACK);
    display.display();
  }
}

void testfillrect(void) {
  uint8_t color = 1;
  for (int16_t i=0; i<display.height()/2; i+=3) {
    // alternate colors
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
    display.display();
    color++;
  }
}

void testdrawtriangle(void) {
  for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, BLACK);
    display.display();
  }
}

void testfilltriangle(void) {
  uint8_t color = BLACK;
  for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
    display.fillTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}

void testdrawroundrect(void) {
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, BLACK);
    display.display();
  }
}

void testfillroundrect(void) {
  uint8_t color = BLACK;
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}
   
void testdrawrect(void) {
  for (int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, BLACK);
    display.display();
  }
}

void testdrawline() {  
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, BLACK);
    display.display();
  }
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, BLACK);
    display.display();
  }
  delay(250);
  
  display.clearDisplay();
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, BLACK);
    display.display();
  }
  for (int8_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, BLACK);
    display.display();
  }
  delay(250);
  
  display.clearDisplay();
  for (int16_t i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK);
    display.display();
  }
  for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK);
    display.display();
  }
  delay(250);

  display.clearDisplay();
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, BLACK);
    display.display();
  }
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK); 
    display.display();
  }
  delay(250);
}
 


1 komentar:

  1. Hey there! I've been following your weblog for some time now and finally got the bravery to go ahead and give you a shout out from Houston Tx! Just wanted to tell you keep up the excellent work! yahoo login mail

    BalasHapus

Copyright © 2014 Belajar Arduino | Designed With By Blogger Templates | Distributed By Gooyaabi Templates
Scroll To Top