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:
- Text display
- Large digits
- Plot single pixel
- Draw line between two points
- Draw a rectangle given two opposite corners
- Draw a filled rectangle
- Draw circle
- Display a bitmap from flash memory
- 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
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).
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
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 } // ~
};
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.
And how do you create a bitmap? Are there generators for such?
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 [...]
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
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
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
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!