The DFRobot LCD4884 LCD Shield

Learn how to use the DFRobot LCD4884 Arduino LCD shield.

Updated 19/03/2013

This needs to be updated for use with Arduino IDE v1.0.1 and greater… however we no longer have a shield to test it. Stay tuned via twitter to find out when this is updated.

This article is my response to a request on how to use the LCD4884 LCD shield from DFRobot in China. It is a simple way of displaying text and the odd graphic, as well as another way to accept user input. Here is the shield in question:

image

From a hardware perspective the LCD has a resolution of 84 by 48 pixels, with a blue back light. It can easily display six rows of fourteen alphanumeric characters, or two rows of six very large characters. Furthermore, it can display bitmap images that are appropriately sized. At the top-left of the shield digital pins eight to thirteen have been expanded with matching Vcc and GND pins, and at the bottom right the same has been done with analogue pins one through to five. Therefore if using this shield, you will lose digital pins two through to seven and analogue zero.

Along the bottom-left of the shield are solder pads for some other I/O options, however I couldn’t find any documentation on how these are used. Below the LCD is a small four-way joystick that also has an integral button. This is connected to analog pin zero via a resistor network. This joystick can be used for user input and also to create some nifty menu systems. To the right is a power-on LED which is really too bright, I would recommend sanding it a little to reduce the intensity, or just melting it off with a soldering iron.

The shield requires an Arduino library which can be downloaded from the shield’s wiki page. There is also a good demonstration sketch on the wiki, however some of our readers may find this to be somewhat complex. Therefore where possible I will break down and explain the functions in order to simplify use of the shield, then use them in a demonstration sketch.

Controlling the backlight is very easy, just use:

digitalWrite(7, HIGH/LOW)

to turn it on and off. Don’t forget to put

pinMode(7, OUTPUT) in void setup();.

Reading the joystick position is accomplished via analogRead(0);. It returns the following values as such:

  • Up – 505
  • Down – 0
  • Left – 740
  • Right – 330
  • pressed in – 144
  • Idle (no action) – 1023

By using analogRead(0) and if… statements you can read the joystick in a simple way. Don’t forget to allow for some tolerance in the readings. Attempts to press the button while forcing a direction did not return any different values. In the example sketch later on, you can see how this is implemented. Always remember to insert:

in void setup() to create an instance of the LCD, and

at the start of your sketch to enable the library.

Now to display text on the LCD. Here is an example of the standard font text:

charactersss

Using the standard font, we can position text using the following function:

The parameter x is for the x-coordinate of the first character – measured in pixels, not characters. However y is the coordinate in character lines (!). The screen can display six lines of fourteen characters. To display the larger font, for example:

largechar

use the following:

Unfortunately the library only supports the digits 0~9, +, – and decimal point. You can modify the file font_big.h in the library folder and create your own characters. Once again the x parameter is the number of pixels across to place the first character, and y is 0 for the top line and 3 for the bottom line. Notice that the characters in this font are proportional, however the maximum number of digits to plan for in one line would be six.

To clear the display, use:

By now you will be able to display text, control the backlight and read the joystick. The following demonstration sketch puts it all together so far:

Next is to create and display bitmap images. Images can be up to 84 x 48 pixels in size. There are no shades of grey in the images, just pixels on or off. To display a bitmap is a convoluted process but can be mastered. We need to convert a bitmap image into hexadecimal numbers which are then stored in a text file for inclusion into the sketch. To do so, follow these steps:

Create your monochrome image using an editor such as Gimp. Make sure your file name ends with .bmp. Such as:

gimpexample

Next, download the BMP2ASM program from this website. [Sorry, could only find a Windows version]. Open your .bmp file as created above, and you will see a whole bunch of hexadecimal numbers at the bottom of the window:

convexam

Turn on the check boxes labelled “Stretch”, “Use Prefix” and “Use suffix”. Then click “Convert”. Have a look in your folder and you will find a text file with an extension .asm. Open this file in a text editor such as Notepad. Remove all the instances of “dt”, as well as the top line with the file path and name. Finally, put commas at the end of each line.

You should now be left with a file of hexadecimal numbers. Encase these numbers in the form of an array as such:

encase

What we have done is places the hexadecimal numbers inside the

declaration. To make life simpler, ensure the filename (ending with .h) is the same as the variable name, as in this example it is called hellobmp(.h). And make sure you have saved this file in the same folder as the sketch that will use it. Finally, we include the hellobmp.h file in our example sketch to display the image:

Notice in the function lcd.LCD_draw_bmp_pixel the filename hellobmp is the same as in the #include declaration is the same as the hellobmp.h file we created. They all need to match. Furthermore, the four numerical parameters are the bitmap’s top-left x-y and bottom-right x-y coordinates on the LCD. So after all that, here is the result:

hellodone

So there you have it. If you have any questions about this LCD shield contact DF Studio, or ask a question in our Google Group.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

23 Responses to “The DFRobot LCD4884 LCD Shield”

  1. Alastair says:

    Thanks John.

    Should this read blue frontlight — as opposed to blue backlight — I can see the LEDs! Perhaps that’s normal and they’re usually shrouded my front panels but it doesn’t have that characteristic ‘backlight’ look in the images.

    • John Boxall says:

      This particular LCD was originally meant for mobile phones, there would be a plastic bezel around the screen covering the LEDs shielding them from view. So I still call them a backlight.
      john

  2. Kenshiro says:

    Hi John,

    Thanks to take time to make this article !!!

    I try to use it, and I always have the error message like in this post : http://arduino.cc/forum/index.php?topic=52719.0

    it seems that the ardunio software don’t see the librairies..

    Do you have an idea of how fix that ?

    The error msg :

    dfr48841.cpp:1:21: error: LCD4884.h: No such file or directory
    dfr48841.cpp: In function ‘void setup()’:
    dfr48841:5: error: ‘lcd’ was not declared in this scope
    dfr48841.cpp: In function ‘void loop()’:
    dfr48841:20: error: ‘lcd’ was not declared in this scope
    dfr48841:20: error: ‘MENU_NORMAL’ was not declared in this scope
    dfr48841:24: error: ‘lcd’ was not declared in this scope
    dfr48841:26: error: ‘MENU_NORMAL’ was not declared in this scope

    thanks

  3. Kenshiro says:

    Hi John,

    I found the solution.

    On your computer (mac for me) you have a folder name “Arduino” in Document.

    This folder is create during installation of arduino software.

    1-Create your new project in arduino software et save it in this folder.

    2- In the “Arduino” folder, create a new folder called : libraries

    3- Download the library from DBRobot http://www.dfrobot.com/wiki/index.php?title=LCD4884_Shield_Fro_Arduino_(SKU:DFR0092)

    4- Unzip the file. When it’s done you have a folder name LCD4884

    Put the LCD4884 folder in the folder librairies you create in step 2

    And it’s good !

  4. shirokuade says:

    hai, i tried your code, and code in wiki, but i just got my lcd blink turn blue and turn off, but no text’s appear, what’s wrong?
    i put it on arduino uno, i tried basic code
    like :
    lcd.LCD_write_string(2,2,”abc”, MENU_NORMAL); // ignore MENU_NORMAL for now

    but no text’s appear.

    is it problem with LCD? is it broken?

    thanks

    • John Boxall says:

      Yes, sounds like you have a faulty board. Just double-check the connection between the LCD itself and the shield, on mine it was a bit loose and caused a problem sometimes. Otherwise take it back to retailer.
      john

  5. deskplus says:

    // Arduino Uno Rev. 3
    // In libraries LCD4884.cpp and LCD4884.h replace “WProgram.h” with “Arduino.h”

    //#include “WProgram.h”
    #include “Arduino.h” // In place of “WProgram.h”

  6. dakota says:

    hi i tried your code and i keep getting errors like “lcd”was not decleared in scope.
    what does this mean? im fairly new to arduino and ive been reading up on it but for some reseaon i cant get it working?

  7. dakota says:

    nvm i didnt read comment #2

  8. John says:

    I just purchased one of these shields (from SainSmart), and was frustrated when I found that it didn’t come with any documentation, just some example code. I like to know what I’m working with.

    I did some digging and found that it’s a Nokia display with a Philips LCD controller. There is some useful technical data on this part available here (including datasheets):

    http://serdisplib.sourceforge.net/ser/pcd8544.html

    And, yes, shame on the vendors for not supplying anything other than a module. The row of unloaded pads down the side of the LCD shield bring out the LCD controller’s signal and power lines. The LCD module on the unit I bought wasn’t even solder mounted to the PCB, so I simply lifted it up and peeked underneath.

    Excellent blog, BTW.

  9. zamaddog says:

    Hi,
    Very interesting site you have! Enjoying it a lot. Do you know by any chance who is making this LCD module? I would love to use it on an instrumentation project.
    Regards,
    Teuns

  10. Sean Coston says:

    I just bought two of these and neither displayed with adequate contrast or reliability at first. The LCD module on one of the boards actually was loose – not snapped down as the metal locking tabs would not catch and hold on to the board. That was easy to fix with a little manipulation of the tabs. I guess one could solder the LCD to the board as well.

    So as I said, neither LCD displayed well at first. What I found through trial and error was that the black rubberized carbon conducting pad between the LCD and the boardwas the problem. These must get covered with some sort of very thin layer of oil or residue during their manufacture. My solution was to separate the LCD from the board by manipulating the locking tabs from behind. Then lift out the black rubberized carbon conducting strip. Lightly treat the contact surfaces with some isopropyl alcohol and a q-tip and very lightly “rough-up” the contact surfaces (I just used my finger nail). I then just replaced the conducting pad and re-installed the LCD.
    Voila! both the LCD boards work great and display with excellent contrast and no fading.

    I tried all the suggestions about changing the contrast setting in the initialization of the board (other blogs on the same board) and nothing worked. I was ready to give up on the LCD until I tried these steps. Now very happy with these little boards as they provide easy pin access for sensor implementation.

    BTW – excellent blog.

    Sean

  11. Rasoul says:

    Thanks for your tutorial. I would like to know if it is possible to read the value of a pixel (individually or in a group of pixels)? Indeed, I would like to AND, OR and XOR pixels of the lcd screen with some values. Is there any way to read the current status of the pixels?

    • John Boxall says:

      The only way to track the pixels would be to “map” them in an array, and then use that array as part of a function to control the LCD.
      Then your sketch could poll and update the array when required as it would be a mirror of what is displayed on the LCD.

  12. Rob says:

    very noob question:

    I am trying to get this lcd to output temp in fahrenheit. My code is on the following link.

    http://pastie.org/8658974

    I am pretty sure my c coding is just off, but it is displaying

    “+-40F” but the f is in the middle of the “40″. I can figure out the spacing by playing with it, but i just cant get it to display the temp right.

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: