- Name: NOKIA_5110_RPI
- Description:
- C++ Library for Nokia 5110 LCD, PCD8544 Driver. 84 x 48 pixels.
- Dynamic install-able Raspberry Pi C++ library.
- Invert colour, rotate, sleep, contrast bias control supported.
- 12 fonts.
- Graphics class included.
- Polymorphic print class included.
- Bitmaps supported.
- Hardware and Software SPI
- Dependency: bcm2835 Library
- Author: Gavin Lyons
- Port of my PIC library at github link.
The NOKIA_5110_RPI library has been amalgamated into my combined display library 'Display_Lib_RPI.' This new library is under active development and should work on any Linux based single board computer.
-
Install the dependency bcm2835 Library if not installed (at time of writing latest version is 1.71)
- The bcm2835 library provides SPI bus, delays and GPIO control.
- Install the C libraries of bcm2835, Installation instructions here
-
Download the NOKIA_5110_RPI library
- Open a Terminal in a folder where you want to download,build & test library
- Run following command to download from github.
curl -sL https://github.com/gavinlyonsrepo/NOKIA_5110_RPI/archive/1.4.tar.gz | tar xz
- Run "make" to run the makefile to install library, it will be installed to usr/lib and usr/include
cd NOKIA_5110_RPI-1.4
make
sudo make install
- Next step is to test LCD and installed library with the main.cpp test file. Wire up your LCD. Next enter the example folder and run the makefile in THAT folder, This second makefile builds the example file using the just installed library. and creates a test exe file in "example/bin". Note : make run uses sudo, bcm2835 library requires sudo.
cd example/
make
make run
- There are 7 examples files to try out. To decide which one the makefile builds simply edit "SRC" variable at top of the makefile in examples folder. in the "User SRC directory Option Section". Pick an example "SRC" directory path and ONE ONLY. Comment out the rest and repeat: make and run bin/test.
Filepath | File Function | SPI |
---|---|---|
src/HelloWorld | Basic use case | HW |
src/HelloWorld_SWSPI | Basic use case SW SPI | SW |
src/TextTests | Text & fonts | HW |
src/GraphicTests | Graphics | HW |
src/BitmapTests | Bitmaps | HW |
src/FunctionTests | Function testing | HW |
src/SpeedTest | Frame rate per second test | HW |
The Nokia 5110 is a basic graphic LCD screen for lots of applications. GPIO function on RPI, 5 Nokia 5110 LCD lines SPI bus. Use any GPIO user likes for Software SPI. For Hardware the user can use any GPIO for reset and data/command line
Example file set up ::
RPI pin(HW SPI) | RPI pin(SW SPI) | Nokia 5110 LCD |
---|---|---|
SPI_CLK | GPIO22 | LCD_CLK Pin 5 clock in |
SPI_MOSI | GPIO27 | LCD_DIN Pin 4 data in |
GPIO24 | GPIO24 | LCD_DC Pin 3 data/command |
SPI_CE0 or SPI_CE1 | GPIO 8 | LCD_CE Pin 2 chip enable |
GPIO25 | GPIO25 | LCD_RST Pin 1 reset |
Connect Nokia 5110 VCC(pin 6)to 3.3V. The user may have to adjust LCD contrast and bias settings, to the screen at hand for optimal display. A resistor or potentiometer can be connected between (Nokia LCD) GND(pin8) and LIGHT(pin7) to switch on /off backlight and adjust brightness.
1. Raspberry PI 3 model b
2. C++, g++ (Debian 12.2.0)
3. Raspbian , Debian 12 bookworm OS, , 64 bit.
4. kernel : aarch64 Linux 6.1.0-rpi7-rpi-v8
5. [bcm2835 Library 1.71 dependency](http://www.airspayce.com/mikem/bcm2835/).
Provides low level SPI bus, delays and GPIO control.
This library supports both Hardware SPI and software SPI. The constructor of the main class is overloaded. Which SPI is started depends on which constructor called by user. Hardware SPI uses bcm2835 library spi module. The SPI settings are in LCDSPIHWSettings function. If there are multiple SPI devices on Bus(with different settings) the user can call this method to refresh settings before a tranche of LCD commands. Default Speed is BCM2835_SPI_CLOCK_DIVIDER_64, 6.25MHz on RPI3. This can be adjusted in code or you can pass the divider value in the contructor as an argument. These values are defined by enum bcm2835SPIClockDivider. For full list see
User can also adjust which HW SPI chip enable pin they use(CE0 or CE1). in constructor arguments. This device uses bit order MSB First and SPI Mode 0.
Measured SPI speed results Version 1.3 are in the SpeedTest example file header comment block. The parameter LCDHardwareSPI is a GPIO uS delay that can be used to slow down or speed up Software SPI. By default it is set to 2uS. It may have to be adjusted depending on device/CPU used.
There are two makefiles
1. Makefile at root directory builds and installs library at a system level.
2. Makefile in example directory build example file to an executable.
Font data table:
num | enum name | Char size XbyY | ASCII range | Size bytes | Size Scale-able |
---|---|---|---|---|---|
1 | $_Default | 5x8 | 0-0x7F | 635 | Y |
2 | $_Thick | 7x8 | 0x20-0x5A, no lowercase letters | 406 | Y |
3 | $_SevenSeg | 4x8 | 0x20-0x7A | 360 | Y |
4 | $_Wide | 8x8 | 0x20-0x5A, no lowercase letters | 464 | Y |
5 | $_Tiny | 3x8 | 0x20-0x7E | 285 | Y |
6 | $_Homespun | 7x8 | 0x20-0x7E | 658 | Y |
7 | $_Bignum | 16x32 | 0x2D-0x3A ,0-10 - . / : | 896 | N |
8 | $_Mednum | 16x16 | 0x2D-0x3A ,0-10 - . / : | 448 | N |
9 | $_ArialRound | 16x24 | 0x20-0x7E | 4608 | N |
10 | $_ArialBold | 16x16 | 0x20-0x7E | 3072 | N |
11 | $_Mia | 8x16 | 0x20-0x7E | 1520 | N |
12 | $_Dedica | 6x12 | 0x20-0x7E | 1152 | N |
- $ = LCDFontType
- A print class is available to print out many data types.
- Fonts 1-6 are byte high(at text size 1) scale-able fonts, columns of padding added by SW.
- Font 7-8 are large numerical fonts and cannot be scaled(just one size).
- Fonts 9-12 large Alphanumeric fonts and cannot be scaled(just one size)
Font Methods:
Font num | Method | Notes |
---|---|---|
1-6 | drawChar | Y |
1-6 | drawText | Y |
7-12 | drawChar | N |
7-12 | drawText | N |
1-12 | Polymorphic print class which will print out many data types |
These methods return an enum( LCD_Return_Codes_e), non-zero in event of an error (see API doc). Such as wrong font chosen , ASCII character outside chosen fonts range, character out of screen bounds and invalid character array pointer object.
Two different bitmaps methods can be used.
num | Method name | data addressing | Notes |
---|---|---|---|
1 | drawBitmap() | vertical | Draws bitmaps to the buffer, Bitmap's height must be divisible by 8 |
2 | customChar() | vertical | Draws a custom character on screen 5by8, PIC legacy function |
The drawBitmap will return an error( enum( LCD_Return_Codes_e)) if : The Bitmap is completely off screen , Invalid Bitmap pointer object, bitmap bigger than screen , bitmap bigger/smaller than provided width and height co-ordinates ( This helps prevents buffer overflow if user enters wrong data.). The Bitmap's height must be divisible by 8. I.e for a full screen bitmap with width=84 and height=48. Bitmap excepted size = 84 * (48/8) = 504 bytes.
Bitmaps can be turned to data here at link See example file "BitmapTests" for more details.
Example output.