yt_link
insta_link
fb_link
twitter_link

NOKIA 5110 LCD
page 1/1


NOKIA 5110 LCD example with Arduino

Help me by sharing this post



This is a very short example. How to wire up an NOKIA 5110 LCD to an Arduino and show text, numbers and unique logos. To create the logos I've used the image2LCD software to create the bytes for a 240 by 240 pixels image. You will need a bmp picture first. Make the connections as in this tutorial, download the library and uplaod the example code.

First, you need an NOKIA 5110 LCD like this one on this link. This display needsthe SPI pins from the Arduino.

Nokia 5110 LCD Arduino example







PART 1 - Schematic


Ok, make the SPI connections as below between the LCD and te Arduino pins. Supply 5V and connect GND as well. To turn ON the backlight you ahve to connect GND to the light pin. Next, go below and downlaod the library and see the example code. Upload the code and test the LCD.


scheamtic Arduino 16x2 LCD




PART 2 - Example code 1


First of all, you need the Adafruit_GFX library and Adafruit_PCD8544 in order to work. For that, go below and downlaod those libraries. They will be a in two .zip files. Open Arduino IDE and go to sketch, include library, add .zip library and select the downlaoded files one by one. Now the libraries are installed. You could downlaod the example code or just copy/paste it from below.

Download Adafruit_GFX library:
Download Adafruit_PCD8544 library:

Download the example code 1:



/*
 * NOKIA 5110 LCD example
 * Schematic: https://www.electronoobs.com/eng_arduino_tut53_sch1.php
 * Tutorial:  https://www.electronoobs.com/eng_arduino_tut53.php
*/

#include <SPI.h>
#include <Adafruit_GFX.h>         //Downlaod it here : https://www.electronoobs.com/eng_arduino_Adafruit_GFX.php
#include <Adafruit_PCD8544.h>     //Download it here: https://www.electronoobs.com/eng_arduino_Adafruit_PCD8544.php

// 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



static const unsigned char PROGMEM EN_logo [] = {
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, 
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, 
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,  
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, 
B00000000, B00000000, B00000000, B01111111, B11111100, B01111100, B00111000, B00000000,  
B00000000, B00000000, B00000000, B01111111, B11111100, B01111100, B00111000, B00000000, 
B00000000, B00000000, B00000000, B01110000, B00000000, B01111100, B00111000, B00000000,  
B00000000, B00000000, B00000000, B01110000, B00000000, B01110011, B00111000, B00000000,  

B00000000, B00000000, B00000000, B01110000, B00000000, B01110011, B00111000, B00000000, 
B00000000, B00000000, B00000000, B01110000, B00000000, B01110011, B00111000, B00000000, 
B00000000, B00000000, B00000000, B01110000, B00000000, B01110011, B00111000, B00000000,  
B00000000, B00000000, B00000000, B01111111, B11000000, B01110000, B11111000, B00000000,  
B00000000, B00000000, B00000000, B01111111, B11000000, B01110000, B11111000, B00000000,  
B00000000, B00000000, B00000000, B01110000, B00000000, B01110000, B00111000, B00000000, 
B00000000, B00000000, B00000000, B01110000, B00000000, B01110000, B00111000, B00000000, 
B00000000, B00000000, B00000000, B01110000, B00000000, B01110000, B00111000, B00000000, 

B00000000, B00000000, B00000000, B01110000, B00000000, B01110000, B00111000, B00000000,  
B00000000, B00000000, B00000000, B01110000, B00000000, B01110000, B00111000, B00000000, 
B00000000, B00000000, B00000000, B01110000, B00000000, B01110000, B00111000, B00000000,  
B00000000, B00000000, B00000000, B01111111, B11111100, B01110000, B00111000, B00000000,  
B00000000, B00000000, B00000000, B01111111, B11111100, B01110000, B00111000, B00000000,  
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, 
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, 
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000
};


static const unsigned char PROGMEM  LOGO[] =
{ 
/* 0X00,0X01,0X40,0X00,0X40,0X00, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0F,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X3F,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,
0X01,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFE,0X00,0X00,0X00,0X00,0X00,
0X03,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,
0X0F,0XFF,0XFF,0X80,0X00,0X00,0X00,0X00,0X0F,0XFF,0XFF,0XC0,0X00,0X00,0X00,0X00,
0X1F,0XFF,0XFF,0XC0,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X1F,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,0X3F,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X3F,0XFF,0XFF,0XF0,0X00,0X00,0X00,0X00,0X7F,0XFF,0XFF,0XF0,0X00,0X00,0X00,0X00,
0X7F,0XFF,0XF8,0X70,0X00,0X00,0X00,0X00,0X60,0XFF,0XC0,0X70,0X00,0X00,0X00,0X00,
0X60,0X00,0X00,0X70,0X00,0X00,0X00,0X00,0X60,0X00,0X00,0X70,0X00,0X02,0X00,0X00,
0X40,0X00,0X00,0X33,0XDF,0XCF,0XF0,0X00,0X40,0X00,0X00,0X33,0XAF,0XFB,0XF8,0X00,
0X40,0X00,0X00,0X33,0XEF,0XFB,0XF8,0X1C,0X40,0X01,0X00,0X33,0XEF,0XFB,0XFC,0X1F,
0X80,0X00,0X00,0X33,0XDF,0XFF,0XFC,0X0F,0X80,0X00,0X00,0X1B,0XF0,0X07,0XFC,0X1F,
0XBF,0X00,0XFE,0X0B,0XF0,0X07,0XFE,0X3F,0X82,0X41,0X70,0X1B,0XFF,0XF7,0XFE,0X3F,
0X83,0X41,0X70,0X0B,0X7F,0XF7,0XDD,0X3E,0X87,0X40,0XA0,0X03,0X7F,0XF7,0XDF,0X3E,
0X80,0X00,0X00,0X0B,0XFF,0XF7,0XCF,0X3E,0X80,0X00,0X00,0X0B,0XFF,0X77,0XCE,0X9E,
0X00,0X00,0X00,0X2B,0X70,0X03,0X84,0X1E,0X40,0X00,0X00,0X32,0XF0,0X07,0XC0,0XBE,
0X00,0X00,0X00,0X70,0XF0,0X0C,0XC6,0XFE,0X20,0X00,0X00,0X42,0X5F,0XFF,0XC3,0XFE,
0X20,0X00,0X00,0X43,0X3F,0XFF,0X83,0XFC,0X20,0X00,0X00,0X41,0X7F,0XFF,0X83,0XFC,
0X20,0X04,0X00,0X43,0XFF,0XFF,0X83,0XFC,0X10,0X00,0X00,0X42,0XFF,0XF0,0X81,0XFC,
0X10,0X00,0X00,0X80,0X00,0X00,0X01,0XFC,0X00,0X3F,0X00,0X80,0X00,0X00,0X00,0X7C,
0X08,0X40,0X00,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X00,
0X04,0X00,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X08,0X40,0X00,0X00,0X00,0X00,
0X03,0X00,0X10,0XC0,0X00,0X00,0X00,0X00,0X01,0X00,0X23,0X80,0X00,0X00,0X00,0X00,
0X00,0X80,0X5F,0X00,0X00,0X00,0X00,0X00,0X00,0X7F,0XEB,0X40,0X00,0X00,0X00,0X00,
0X00,0X01,0X8F,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X9F,0X40,0X00,0X00,0X00,0X00,
0X00,0X00,0XEE,0XA0,0X00,0X00,0X00,0X00,0X00,0X00,0X9F,0X60,0X00,0X00,0X00,0X00,
0X00,0X00,0XEF,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X77,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X40,0X00,0X00,0X00,0X00,0X00,0X00,0X67,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X0D,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};

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(100); 
  display.clearDisplay();   // clears the screen and buffer
}


void loop() {
  
  display.drawBitmap(4  , 0, EN_logo, 64, 24, 1);
  display.setCursor(8,25);
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.println("ELECTRONOOBS"); 
  display.display();
  delay(3000);  
  
  display.clearDisplay();
  display.display();
  
  display.drawBitmap(0  , 0, LOGO, 64, 64, 1);
  display.display();
  delay(3000);
  display.clearDisplay();  


  display.setCursor(0, 0);
  // Write something on the specific row
  display.println("Example text");
  display.println("0, 1, 2 ...!?");
  display.setTextSize(2);
  display.println("HELLO");
  display.display();
  delay(3000);
  display.clearDisplay();  
}




PART 3 - Full demo example


You will still need the Adafruit_GFX library and Adafruit_PCD8544 in order to work. For that, go below and downlaod those libraries. They will be a in two .zip files. Open Arduino IDE and go to sketch, include library, add .zip library and select the downlaoded files one by one. Now the libraries are installed. You could downlaod the example code or just copy/paste it from below.

Download Adafruit_GFX library:
Download Adafruit_PCD8544 library:

Download full demo example code:



/*
 * NOKIA 5110 LCD example
 * Schematic: https://www.electronoobs.com/eng_arduino_tut53_sch1.php
 * Tutorial:  https://www.electronoobs.com/eng_arduino_tut53.php
*/

#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

static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ 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

  // draw a single pixel
  display.drawPixel(10, 10, BLACK);
  display.display();
  delay(2000);
  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);
}







Next tutorial →
More tutorials ←

Help me by sharing this post








ADVERTISERS
PCBWAY PCB Manufacturing

PCBWAY Christas PCB Manufacturing

Advanced PCB Manufacturing
Advanced PCB Manufacturing

AFFILATE

Gearbest SG - 700 Satellite Navigation Foldable RC Drone Quadcopter - WHITE 720P WIFI FPV CAMERA
SG - 700 Satellite Navigation Foldable RC Drone Quadcopter - WHITE 720P WIFI FPV CAMERA only $46.99

Gearbest Xiaomi AMAZFIT Heart Rate Smartwatch - BLACK INTERNATIONAL VERSION
Xiaomi AMAZFIT Heart Rate Smartwatch - BLACK INTERNATIONAL VERSION only $89.99

Gearbest FeiLun FT011 2.4GHz Brushless RC Racing Boat - BLACK AND WHITE AND RED
FeiLun FT011 2.4GHz Brushless RC Racing Boat - BLACK AND WHITE AND RED only $96.99