Pages

Nokia 3310 LCD Library with basic graphics functions

After buying one of the Nokia 3310 LCD with joystick shields from Nuelectronics.com I wanted the library to do more in the way of graphical functions. After re-writing the library, cleaning it up and renaming all the functions I now have a library that can do what I want it to do.

The library includes functions for:

  1. Text display
  2. Large digits
  3. Plot single pixel
  4. Draw line between two points
  5. Draw a rectangle given two opposite corners
  6. Draw a filled rectangle
  7. Draw circle
  8. Display a bitmap from flash memory
  9. Clear an area of the screen

Update 1

The library has been updated by John Crouchley to inherit the Print class to produce an easier method of printing strings, numbers and general text formatting. Other changes include:

  • Allow for multiple SPI devices
  • Move get_key into the class
  • Fix bug in writeChar
  • Additional bounds checking

Update 2

I have now made some further updates to the library, the changes are:

  • Created new big font. This is much neater looking than original.
  • Updated 5×7 font as % was one row too low.
  • Updated example to include print functions and degree symbol

Update 3

This is a minor update to enable the library to work with newer displays available from Nuelectronics. Previous library may may show a very dark display. The temperature coefficient and contrast values have been updated in the initialisation function.

Example Application

The example application is based on the original Nuelectronics example but displays the values from a real temperature/humidity sensor, the SHT11, using a modified library from http://www.practicalarduino.com/news/id/211. The modification is the addition of the readDewPoint function. The menu also includes a demo option which gives a run through the graphical functions by drawing circles, lines, rectangles, displaying a full screen bitmap and a simple animation using bitmaps.

Downloads:

  • nokia_3310_lcd.zip – Updated library with Johns changes, second and third update changes.
  • SHT1x.zip – Updated library for accessing temp/humidity sensor.

Demonstration video

Bookmark this post: bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

22 comments to Nokia 3310 LCD Library with basic graphics functions

  • kibos

    Nice work, thanks for sharing ! For info : if you want to stack this Nokia 3310 LCD Display shield on the etherShield from nuelectronics, you just have to change the digital pin PB2 on this shield to digital pin PD2 or PD3, and tweak a bit your library (change pin assignment and reinit SPI before sending each command to the LCD).

  • Administrator

    Hi,

    Thanks for the comments, I’ve been thinking about this but not yet had a need to run both the ethernet and LCD shields together.

    This has now been done, not by me but by John Crouchley, see updates above.
    Cheers

    Andy

  • Mike

    Hi Andy,

    I created this small font (the digits are 3×5 pixels) for use within your library. I have not added it to the library yet as I haven’t received my screen. If you feel like adding it you can, otherwise I will post back with a new LCD_write_string_small/LCD_write_char_small (possibly with a modified LCD_write_byte)

    // 3 x 5 font
    // NO pixel space at left or bottom
    // index = ASCII - 32
    #include

    unsigned char font3_5[][2] PROGMEM =
    {
    { 0x00, 0x00 }, //
    { 0x24, 0x82 }, // !
    { 0x5a, 0x00 }, // "
    { 0x7f, 0xff }, // #
    { 0x2e, 0xba }, // $
    { 0x42, 0xa1 }, // %
    { 0x7a, 0xb7 }, // , // '
    { 0x14, 0x91 }, // (
    { 0x44, 0x94 }, // )
    { 0x55, 0x40 }, // *
    { 0x25, 0xd2 }, // +
    { 0x00, 0x14 }, // ,
    { 0x01, 0xc0 }, // -
    { 0x00, 0x02 }, // .
    { 0x14, 0x94 }, // /
    { 0x7b, 0x6f }, // 0
    { 0x2c, 0x92 }, // 1
    { 0x62, 0xa7 }, // 2
    { 0x73, 0xcf }, // 3
    { 0x5b, 0xc9 }, // 4
    { 0x78, 0x8e }, // 5
    { 0x79, 0xef }, // 6
    { 0x72, 0x52 }, // 7
    { 0x7b, 0xef }, // 8
    { 0x7b, 0xcf }, // 9
    { 0x04, 0x10 }, // :
    { 0x04, 0x14 }, // ;
    { 0x15, 0x11 }, //
    { 0x72, 0x82 }, // ?
    { 0x7f, 0xaf }, // @
    { 0x2b, 0xed }, // A
    { 0x6b, 0xae }, // B
    { 0x79, 0x27 }, // C
    { 0x6b, 0x6e }, // D
    { 0x79, 0xa7 }, // E
    { 0x79, 0xa4 }, // F
    { 0x79, 0x6f }, // G
    { 0x5b, 0xed }, // H
    { 0x74, 0x97 }, // I
    { 0x72, 0x6f }, // J
    { 0x5b, 0xad }, // K
    { 0x49, 0x27 }, // L
    { 0x5f, 0x6d }, // M
    { 0x7b, 0x6d }, // N
    { 0x7b, 0x6f }, // O
    { 0x7b, 0xe4 }, // P
    { 0x7b, 0xc9 }, // Q
    { 0x6b, 0xad }, // R
    { 0x79, 0xcf }, // S
    { 0x74, 0x92 }, // T
    { 0x5b, 0x6f }, // U
    { 0x5b, 0x6a }, // V
    { 0x5b, 0x7f }, // W
    { 0x5a, 0xad }, // X
    { 0x5a, 0x92 }, // Y
    { 0x7d, 0x67 }, // Z
    { 0x34, 0x93 }, // [
    { 0x44, 0x91 }, // \
    { 0x64, 0x96 }, // ]
    { 0x2a, 0x00 }, // ^
    { 0x00, 0x07 }, // _
    { 0x22, 0x00 }, // `
    { 0x2b, 0xed }, // a
    { 0x6b, 0xae }, // b
    { 0x79, 0x27 }, // c
    { 0x6b, 0x6e }, // d
    { 0x79, 0xa7 }, // e
    { 0x79, 0xa4 }, // f
    { 0x79, 0x6f }, // g
    { 0x5b, 0xed }, // h
    { 0x74, 0x97 }, // i
    { 0x72, 0x6f }, // j
    { 0x5b, 0xad }, // k
    { 0x49, 0x27 }, // l
    { 0x5f, 0x6d }, // m
    { 0x7b, 0x6d }, // n
    { 0x7b, 0x6f }, // o
    { 0x7b, 0xe4 }, // p
    { 0x7b, 0xc9 }, // q
    { 0x6b, 0xad }, // r
    { 0x79, 0xcf }, // s
    { 0x74, 0x92 }, // t
    { 0x5b, 0x6f }, // u
    { 0x5b, 0x6a }, // v
    { 0x5b, 0x7f }, // w
    { 0x5a, 0xad }, // x
    { 0x5a, 0x92 }, // y
    { 0x7d, 0x67 }, // z
    { 0x15, 0x91 }, // {
    { 0x24, 0x92 }, // |
    { 0x44, 0xd4 }, // }
    { 0x07, 0x80 } // ~
    };

  • Stigern

    This libary doesn’t work with the LCD Shield 2.0 which I just recieved from nuelectronics.

    The demo file makes the screen go totally black, but if I hold it at a certain angle, I can see the menu and such.

  • Stigern

    And how do you create a bitmap? Are there generators for such?

  • Administrator

    Hi,

    There is a minor update to the library to fix this issue. I’ll upload it later. I dont have the v2.0 display so cant tell if it works other than experience from another user who fixed the issue.

    Regards

    Andrew

  • [...] a case of writing some code to track the number of laps and the times of each lap. I’ve used Andy’s arduino Nokia LCD library to handle drawing to the [...]

  • [...] another spare pin. Andrew has updated the library based upon my changes, you can download it from here. Comments [...]

  • rec

    hi, i want to use Your nokia 3110 library, but I have a problem and i can’t figure out, it’s possible to change back light pin to PB4?
    thanks
    rec

  • Administrator

    Hi,

    It is possible to change the backlight pin by cutting the track on the board and wiring the BL pint to another. Taking it from the holes along the edge, the one labelled BL controls the backlight.

    Thanks

    Andy

  • rec

    Hi, thanks for your answer, but i don’t have problem with the wiring. It’s more like software problem. The library use portB in SPI mode, (PB4-MISO), and in this mode, PB4 have 3 state. When put back-light ON, it’s OK, the problem is when I turn it off, nothing happens…..
    any suggestions?
    thanks
    rec

  • GnobarEl

    Can I use this library with a standart nokia LCD?

    I just connect my LCD to arduino, I’m able to run simple code, but not this library, how can I use it?

    I used a schematic like this:
    http://www.amontec.com/lcd_nokia_3310.shtml
    and
    http://www.techdesign.be/projects/datasheet/nokia_3310_LCD.jpg

    PinOUT
    int LCD_DC_PIN = 2; // PB0 4 Data Command
    int LCD_CE_PIN = 3; // PB2 5 /CS active int SPI_MOSI_PIN = 4; // PB3 3 Serial line
    int LCD_RST_PIN = 5; // PB4 8 /RES RESET
    int SPI_CLK_PIN = 6; // PB5 2 CLOCK

    Any idea how to use your library?

    Thanks!

  • Shrimp67

    Hello Andy,
    I tried downloading the files and upload the 3310 demo to my arduino, and I cannot make it work:
    First I get a message about “SHT1x sht1x(dataPin, clockPin);” (row 12) – “SHT1x does not name a type”
    I tried to delete the row out of curiosity, then I get:
    ” lcd.init();
    lcd.clear();
    (rows 99-100)
    “‘class Nokia_3310_lcd’ has no member named init”, and
    “‘class Nokia_3310_lcd’ has no member named clear”

    What am I doing wrong? My planned application is detailed in the following link:
    http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287083302/0

    I appreciate your help.

  • Hi,

    you may have deleted too much or removed a closing } accidentally. Try going to the original example again, remove the include file for the sht1x and the references to it. I sometimes get this when doing changes, the arduino compiler is not very helpful with its error messages when you miss a } character or include too many.

    Hope this helps

    Andy

  • jdobry

    Hello,
    it not contain anything about license. Can I use it in another GPL project? (http://openhr20.svn.sourceforge.net/)

  • Hi,

    I’m trying to release them all under GPL, but this may not be fully compliant in that I’ve not put all the headers and copies of the license in with the source. The other problem is that some of the base code used comes from a number of sources and the licenses for these may not be clear.

    This is still an area to clean up, but hope this helps.

    thanks

    Andy

  • DE8MSH

    Hi Andy,

    like the idea of the 3×5 Font. But howto do a WriteMiniChar? I tried:

    void Nokia_3310_lcd::writeMiniChar(unsigned char ch, char mode) {
    unsigned char j;

    #ifdef USE_GRAPHIC
    if (cursor_col > LCDCOLMAX – 4) cursor_col = LCDCOLMAX – 4; // ensure space is available for the character
    if (cursor_row > LCDROWMAX – 1) cursor_row = LCDROWMAX – 1; // ensure space is available for the character
    lcd_buffer[cursor_row][cursor_col] = 0x00;
    for(j=0; j<5; j++) {
    lcd_buffer[cursor_row][cursor_col + j] = pgm_read_byte(&(miniFont [(ch-32)*3 + j] ));
    }

    lcd_buffer[cursor_row][cursor_col + 4] = 0x00;

    for(j=0; j= LCDCOLMAX)
    {
    cursor_col=0;
    cursor_row++;
    if (cursor_row >= LCDROWMAX) cursor_row=0;
    }
    }
    #else
    for(j=0; j<5; j++) {
    if( mode == MENU_NORMAL )
    writeData( pgm_read_byte(&(miniFont [(ch-32)*5 + j] )) );
    else
    writeData( pgm_read_byte(&(miniFont [(ch-32)*5 + j] )) ^ 0xff );
    }
    writeData( (mode == MENU_NORMAL) ? 0x00 : 0xff );
    #endif
    }

    It doesn't work… Help us, please :)

  • JMin

    Hi Andy,

    Great job with the 3310. I am looking to get a series of menu and sub menu’s going and am fairly stumped after completing the second layer!
    Currently having a list of 3 items which I can select then as soon as one is selected it prints a void statement. Here I need it to be able to scroll through like the first screen on you video.

    I am hoping you many be able to give some guidance regarding this. Many thanks for taking the time to look through my message.

    Best regards,
    Jon

  • [...] I decided to display the time on the Nokia 3310 LCD shield I had. I had to modify Andrew Lindsay's Nokia 3110 LCD library a little bit to add the : and / characters to the font_big charset. I've passed these changes [...]

  • Fin

    Hi all,
    I have been looking at lcd and this code for the last few hours. I understand the page of pacman has a matrix of hexidecimal numbers that represent an image. I am trying to work out exactly how those numbers make the image. The screen size is 84 x 48 but the matrix is 8 x 16. i thought maybe each hexidecimal number represent a byte of 8 pixels such as 0X01 would light up the last bit only. Im not sure any one got any links or something that could help i would really like to understand this.
    Cheers

  • zahiri

    hello there
    I am trying to connect the nokia 3310 with my burglar alarm at office, so that this nokia 3310 to call on my mobile phone if there is any emergence.
    Can I have any idea what to do.
    Sorry, I ma not good in English

  • AlexMac

    Hi Andy,
    Liked the Library working great until I upgraded to Arduino 1.0.1
    grabed the latest from Github
    now very confused
    just some of the errors
    nokia_3310_demo:70: error: ‘Nokia_3310_lcd’ does not name a type
    nokia_3310_demo.cpp: In function ‘void setup()':
    nokia_3310_demo:98: error: ‘lcd’ was not declared in this scope
    nokia_3310_demo.cpp: In function ‘void loop()':