Skip to content

baghayi/Nokia_5110

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A little bit of a history:

Nokia 5110 LCD was meant to be used in one of my projects yet to fail. Not having thoroughly read its datasheet, started looking for drivers and libraries to get it up and running as quickly as I could, but failed dramatically.

Target Platforms

Currently, it is written to be used with Arduino platform.

How to use it, then?

First, you need to copy or clone this library into your Arduino's libraries folder so that you can address it in your Arduino programs.

To do that, you can either download and move this library into libraries folder, or if you have Git installed in your computer then you can go to libraries folder and clone this library into libraries folder (which is a way of downloading).

In order to download this library, there is a Download button in this page, somewhere :), by clicking on it you can download the library, then unzip and finally move it to libraries folder.

To clone it, you open a terminal or console window in the libraries folder then type git clone REPO_URL (replace REPO_URL, with repository's link which is located in this page somewhere), then hit enter and after it is completly downloaded, you are good to go.

Then, you need to include this library in your program in order to use it. To achieve this, add this piece of code in top of your program: #include "Nokia_5110.h"

Now, its time to instantiate Nokia_5110 class to have access to its APIs. Which is also a way of telling the driver which pins of LCD is associated with I/O pins of Micro-controller. How do we do that? easy:

In setup function of your program, or outside of it, create a variable to hold Nokia_5110 class' object:

Nokia_5110 lcd = Nokia_5110(RST, CE, DC, DIN, CLK);

in this case variable is called lcd. And as you can see, Nokia_5110's constructor needs 5 parameters.

  • RST is for lcd's reset pin.
  • CE is for lcd's chip enable pin.
  • DC is for lcd's Command/Data pin.
  • DIN is for lcd's data in pin.
  • CLK is for lcd's clock pin.

You need to pass the constructor, digital pin numbers of arduino to which LCD pins are connected.

At this point, if everything goes as planned, you should be able to access this driver's APIs (meaning, being able to call its methods, functions) in you program.

So, let me list and explain each and every API availabe in your program by this driver (Nokia_5110.h).

Public APIs

  • void setContrast(unsigned short value);

    This method allows us to change LCD's contrast.

    It accepts a value between 0 and 127 (0 >= value <= 127) as its parameter.

    By default, in the driver, contrast value is set to 60. If it is not satisfactory, you can easily change it using setContrast method.

  • void setTemperatureCoefficient(unsigned short value);

    This method allows us to set temperature coefficient. As stated in the datashee, in lower temperatures, LCD's controlling voltage needs to be increased to make it work properly. Which is what this method is for. (Please refere to PCD8544 driver's datasheet for more information on this topic.)

    This method accepts a value between 0 and 3 (0 >= value <= 3) as its parameter.

  • void print(value);

  • void print(value, format);

  • void println(value);

  • void println(value, format);

    These methods lets us display information on the LCD. It prints data that is passed to its parameter on the LCD.

    At the moment, English upper and lower characters are supported. Numbers and some other characters are supported as well. For the list of supported characters please refer to the src/Font.h file.

    Note: In case of unknown characters, question mark (?) will be displayed, instead.

    println method works exactly like print method, only with the exception of jumping to the next line after printing the last character.

    Since this driver uses built-in Print class, which is what provided by the Arduino, they work exactly like print and println methods in Serial and LiquidCrystal libraries.

    They can accept different data types, such as string, char, integers and etc.

    For more information on these methods parameters, check out this link: https://www.arduino.cc/en/Serial/Print

  • void clear();

    Clears the display and then moves the cursor to the first row and column.

  • void clear(position inRow, position fromColumn, position toColumn);

    This method is for when you only want to clear a portion of the LCD.

    First parameter, inRow accepts a value between 0 and 5 as an indication of the row number. Second parameter, fromColumn is the beginning of a portion you want to start clearing from. And the third parameter, toColumn is the end of the column, you want to be cleared. So, from the start to the end of the specified column, in the specified row, will be cleared.

    Second and third parameter accepts a value between 0 to 83.

    Note that, third parameter, toColumn, is included in the clearing process, and that column's data will be removed as well.

    Note: After clearing process is done, cursor will be moved to the fromColumn column. So that you would not need to manually set the cursor after clearing, if all you want is to clear and print some other data in the place of the previous one.

  • void setCursor(position x, position y);

    This method is for specifying cursor position. Like when you want to write some characters on the middle of the screen, you can use this method to jump to the middle of the screen, by passing it the exact location, and then you can start printing characters right there.

    first parameter, x, accepts a value between 0 and 83 (column). and second parameter, y, accepts a value between 0 and 5 (row).

  • void setDisplayMode(display_mode mode);

    As stated in the datasheet, LCD has four different display modes. One is for normal mode. One for blank display. One for turning all display's segments on. And the last one is inverse video.

    This method as its parameter expects a hex value. But it is not nice, is it? :D. For ease of use, driver has four constants defined with respective display mode hex values as their values. So you only need to pass those constant as parameter value instead of hex values.

    Defined constants for display mode are as follows:

Display_Mode::BLANK is for a blank display.

Display_Mode::NORMAL is normal mode, which by default is set by the driver.

Display_Mode::ALL_SEGMENTS_ON for turning all segments (pixels) on.

Display_Mode::INVERSE_VIDEO In normal mode, you have black text in a white background. This mode is the inverse of normal mode (white text in a black background).

  • void setBiasSystem(mux_rate rate);

    This method is for system biasing. For setting the view angle. By default by the driver it is set to Mux_Rate::FORTY, but you can change it any time you want. Not to mention that by changing it, you may also need to change the contrast value of the display.

    Like setDisplayMode you need to pass a hex value as its parameter, but for ease of use, for all of available biasing hex values, constant values is defined. List of constants are as follows:

Mux_Rate::HUNDRED

Mux_Rate::EIGHTY

Mux_Rate::SIXTY_FIVE

Mux_Rate::FORTY_EIGHT

Mux_Rate::FORTY

Mux_Rate::TWENTY_FOUR

Mux_Rate::EIGHTEEN

Mux_Rate::TEN

For more information on this topic, please refer to datasheet.

About the development of this driver

There are things I would love to add to this driver, but until I need them in my projects I might not work on them, so appologies in advance :D .

Some of the thins are:

  • adding comma (,) to the font file. Which I had forgotten to do so when developing this driver.

  • returning current cursor position after printing, from the print and println methods. So if you need to move a bit further in a row (meaning moving cursor in the X position) and then print new characters, you wouldn't have to guess what column to set the cursor. You could easily add some random (:D) number to the current cursor position to avoid printing on the already printed charcters. and probably a new method for separately requesting cursor position without the need of calling print methods.

  • Supporting right to left languages.

  • Bigger font sizes.

  • And then, living happily ever after.