Skip to content

Commit

Permalink
version 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Jan 11, 2021
1 parent 24be381 commit a597d69
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 53 deletions.
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ Overview
7. Custom characters and bitmap supported
8. No graphics buffer to reduce memory footprint but
basic graphics patterns can be created using custom characters, pixels, block patterns , lines.
9. Hardware or software SPI interface.

* Author: Gavin Lyons
* Arduino IDE: 1.8.10
* Functions: Detailed information on the functions can be found in comments in the library .h header file and a concise list of them in keywords.txt and they are 5 example files.
* Functions: Detailed information on the functions can be found in comments in the library .h header file and a concise list of them in keywords.txt and they are 6 example files.
* Memory usage data results can be found in the extras folder. MemoryTestResults.md.

* Tested on following MCUs (The file testedMCU_pinouts.txt shows pins used in testing)
* Tested on following MCUs (The file testedMCU_pinouts.txt in extras folder, shows pins used in testing)

1. Arduino UNO & NANO v3
2. ESP8266
Expand All @@ -45,9 +46,9 @@ Output Screenshots, From left to right top to bottom.

1. Custom characters + fill patterns
2. Font 7 "Large"
3. Half screen bitmap + Font 7 "large"
3. Half screen bitmap
4. Font 9 "Mega"
5. Output showing first 6 (X by 8) fonts, #1-6, one font in each row block:
5. First 6 fonts (byte high), num 1-6, one font in each row block
6. Font 8 "Huge"

![ font pic 1 ](https://github.com/gavinlyonsrepo/NOKIA5110_TEXT/blob/master/extras/image/NOKIA_FONT1.jpg)
Expand All @@ -72,11 +73,7 @@ Features
The Nokia 5110 is a basic LCD screen for lots of applications.
It was originally intended to be used as a mobile phone screen.
It uses the PCD8544 controller, which is the same used in the Nokia 3310 LCD.
The PCD8544 is a low power CMOS LCD controller/driver, designed to drive a graphic display of 48 rows and 84 columns.
The PCD8544 interfaces to microcontrollers through a serial bus interface(SPI).
The library uses bit-banging software SPI rather than importing SPI libraries.
The library has 11 code files (NOKIA5110_TEXT.cpp NOKIA5110_TEXT.h and 9 font header files).
In addition the library has 5 examples files.
The PCD8544 is a low power CMOS LCD controller/driver, designed to drive a graphic display of 48 rows and 84 columns. The library has 11 code files (NOKIA5110_TEXT.cpp NOKIA5110_TEXT.h and 9 font header files). In addition there are 6 examples files.

The screen is 84 X 48 pixels. The X-Axis has 84 columns.
The Y_Axis(rows) the 48 pixels are divided into 6 row blocks.
Expand All @@ -92,16 +89,31 @@ Each block containing one byte of pixels. 6 * 8 = 48.
| Block 5 | 40-47 |

GPIO function on Arduino, 5 Nokia 5110 LCD lines SPI bus.
The example files use Pin D2-RST <.....> D6-CLK.
The example files use Pin D2-RST <.....> D6-CLK for UNO.

| Arduino | Nokia 5110 LCD |
| MCU | Nokia 5110 LCD |
| ------ | ------ |
| Digital GPIO | LCD_CLK Pin 5 clock in |
| Digital GPIO | LCD_DIN Pin 4 data in |
| Digital GPIO | LCD_DC Pin 3 data/command|
| Digital GPIO | LCD_CE Pin 2 chip enable |
| Digital GPIO | LCD_RST Pin 1 reset|

**SPI interface bus**

The PCD8544 interfaces to microcontrollers through a serial bus interface(SPI).
The library originally and by default used bit-banging software SPI.
As of Version 2.2 it can support hardware SPI as well.
Hardware SPI is much faster but two of the pins are fixed, is more difficult to port to new MCU's
and includes the arduino SPI library.
The file testedMCU_pinouts.txt show in extra folder shows pins used in testing of various MCU's
.

To switch to from the default software SPI to Hardware SPI, two steps are required:

1. In file NOKIA5110_TEXT.h , in SPI HARDWARE SECTION, comment in: define SPIHW_ON.
2. Use the constructor with 3 Parameters not 5. There is hardware SPI example file called NOKIA5110_HIW_HWSPI for UNO which shows this.

Pinout of a Nokia 5110 LCD.

![ pinout ](https://github.com/gavinlyonsrepo/NOKIA5110_TEXT/blob/master/extras/image/NOKIA_PINOUT.jpg)
Expand Down Expand Up @@ -138,5 +150,5 @@ Total characters = (Screen Width/Character width + padding) X (Screen height/Ch
| 5 | Wide | 8x8 | (84/8+2) * (48/8) = 48 | no lowercase letters |
| 6 | Tiny | 3x8 | (84/3+2) * (48/8) = 96 | ------ |
| 7 | Large | 12x16 | (84/12) * (48/16) = 21 | no lowercase letters |
| 8 | Huge | 16x24 | (84/16) * (48/24) = 10 | Numbers + : . only |
| 9 | Mega | 16x32 | (84/16) * (48/32) = 5 | Numbers + : . only |
| 8 | Huge | 16x24 | (84/16) * (48/24) = 10 | Numbers + : . only, use / for space |
| 9 | Mega | 16x32 | (84/16) * (48/32) = 5 | Numbers + : . only, use / for space |
2 changes: 1 addition & 1 deletion examples/NOKIA5110_BITMAP/NOKIA5110_BITMAP.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NOKIA5110_BITMAP.ino
// Test file for NOKIA5110_TEXT showing how to fill entire screen with a bitmap 84 * 48 = 504 bytes
// Test file for NOKIA5110_TEXT showing how to fill entire screen with a bitmap 84 * 48 = 504 bytes,software SPI
// URL: https://github.com/gavinlyonsrepo/NOKIA5110_TEXT

// Include the library
Expand Down
12 changes: 6 additions & 6 deletions examples/NOKIA5110_HELLOWORLD/NOKIA5110_HELLOWORLD.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// NOKIA5110_HELLOWORLD.ino
// Test file for NOKIA5110_TEXT showing use most basic use case "HELLO WORLD" at 0,0 with font number one
// Test file for NOKIA5110_TEXT showing use most basic use case "HELLO WORLD" at 0,0 with font number one, software SPI.(defaults) for arduino UNO
// URL: https://github.com/gavinlyonsrepo/NOKIA5110_TEXT

// Include the library
#include <NOKIA5110_TEXT.h>

// LCD Nokia 5110 pinout left to right
// RST / CE / DC / DIN / CLK / VCC /LIGHT / GND
#define RST 1
#define CE 2
#define DC 3
#define DIN 4
#define CLK 5
#define RST 2
#define CE 3
#define DC 4
#define DIN 5
#define CLK 6

// Create an LCD object
NOKIA5110_TEXT mylcd(RST, CE, DC, DIN, CLK);
Expand Down
42 changes: 42 additions & 0 deletions examples/NOKIA5110_HIW_HWSPI/NOKIA5110_HIW_HWSPI.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// NOKIA5110_HW_SPI.ino
// HARDWARE SPI
// Test file for NOKIA5110_TEXT showing use most basic use case "HELLO WORLD" at 0,0 with font number one using Hardware SPI on an arduino UNO.
// ***************NB NB NOTE **********************
// Software SPI is the orginal and default setup. For hardware SPI to work the library must be modified:
// In file NOKIA5110_TEXT.h , SPI HARDWARE SECTION , comment in #define SPIHW_ON, it is commented out by default
//****************************************************
// URL: https://github.com/gavinlyonsrepo/NOKIA5110_TEXT

// Include the library
#include <NOKIA5110_TEXT.h>

// LCD Nokia 5110 pinout left to right
// RST / CE / DC / DIN / CLK / VCC /LIGHT / GND
#define RST 2
#define CE 3
#define DC 4
//DIN hardware SPI (UNO 11) MOSI
//CLK hardware SPI (UNO 13) SCK

// Create an LCD object
NOKIA5110_TEXT mylcd(RST, CE, DC);

#define inverse false // set to true to invert display pixel color
#define contrast 0xB2 // default is 0xBF set in LCDinit, Try 0xB1 <-> 0xBF if your display is too dark
#define bias 0x13 // LCD bias mode 1:48: Try 0x12 or 0x13 or 0x14
#define FontNumber 1 // 1-9, 1 is default, Comment in defines at top of NOKIA5110_TEXT.h if using non default

void setup() {
delay(500);
mylcd.LCDInit(inverse, contrast, bias); // init the lCD
mylcd.LCDClear(0x00); // Clear whole screen
}

void loop() {
mylcd.LCDFont(FontNumber); // Set the font
mylcd.LCDgotoXY(0, 0); // (go to (X , Y) (0-84 columns, 0-5 blocks) top left corner
mylcd.LCDString("HELLO WORLD"); // print
mylcd.LCDgotoXY(0, 2);
mylcd.LCDString("HW SPI TEST"); // print
delay(1000);
}
8 changes: 4 additions & 4 deletions examples/NOKIA5110_TEXT_FONTS/NOKIA5110_TEXT_FONTS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Include the library.
#include <NOKIA5110_TEXT.h>

// LCD Nokia 5110 pinout left to right
// LCD Nokia 5110 pinout left to right , software SPI
// RST / CE / DC / DIN / CLK / VCC / LIGHT / GND

#define RST 2 // Reset pin
Expand Down Expand Up @@ -55,8 +55,8 @@ void setup() {
void loop() {
/*
TEST 1 font 1-6, X by 8 fonts
TEST 2 font 7, 16 by 12 font
TEST 3 font 8, 24 by 16 font
TEST 2 font 7, 12 by 16 font
TEST 3 font 8, 16 by 24 font
TEST 4 font 9, 16 by 32 font
*/

Expand Down Expand Up @@ -133,7 +133,7 @@ void Test3(void)
void Test4(void)
{
mylcd.LCDClear(0x00);
mylcd.LCDFont(9); // font 8 this font takes 4 blocks
mylcd.LCDFont(9); // font 9, this font takes 4 blocks
mylcd.LCDgotoXY(0, 1);
mylcd.LCDString("14.23");
delay(mydelay5);
Expand Down
2 changes: 1 addition & 1 deletion examples/NOKIA5110_TEXT_TEST/NOKIA5110_TEXT_TEST.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Example file name : NOKIA5110_TEXT_TEST.ino
// Description:
// Test file for NOKIA5110_TEXT showing use of font one, sleep mode and clear line/screen, pixel tests,
// Test file for NOKIA5110_TEXT showing use of font one, sleep mode and clear line/screen, pixel tests, Software SPI.
// Fill, Fill block, custom character, Fonts and Bitmap.
// URL: https://github.com/gavinlyonsrepo/NOKIA5110_TEXT

Expand Down
2 changes: 2 additions & 0 deletions extras/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
* Changed function header of "LCDCustomChar()" so it complies for ESP32
* Tested on new boards : ESP32, ESP8266 and STM32 "blue pill" , It Works!!

* Version 2.2.0 Jan 2021
* Hardware SPI option added.
48 changes: 43 additions & 5 deletions extras/testedMCU_pinouts.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
//Working pinouts used during testing
// Working pinouts used during testing software SPI

Arduino UNO
NOKIA5110_TEXT mylcd(2, 3, 4, 5, 6);

STM32 blue pill STM32F103C8T6 NOKIA5110_TEXT mylcd(PA0, PA1, PA2, PA3, PA4);
ESP32 NOKIA5110_TEXT mylcd(23, 22, 21, 19, 18) or NOKIA5110_TEXT mylcd(23, 32, 33, 19, 18);
ESP8266 NOKIA5110_TEXT mylcd(D2, D1, D6, D7, D5);
ATtiny85 NOKIA5110_TEXT mylcd(PB0, PB1, PB2, PB3, PB4);
STM32 blue pill STM32F103C8T6
NOKIA5110_TEXT mylcd(PA0, PA1, PA2, PA3, PA4);

ESP32
NOKIA5110_TEXT mylcd(23, 22, 21, 19, 18) or NOKIA5110_TEXT mylcd(23, 32, 33, 19, 18);

ESP8266
NOKIA5110_TEXT mylcd(D2, D1, D6, D7, D5);

ATtiny85
NOKIA5110_TEXT mylcd(PB0, PB1, PB2, PB3, PB4);


//******************************************************

// Working pinouts used during testing hardware SPI

Arduino UNO
#define RST 2
#define CE 3
#define DC 4
//DIN hardware SPI (UNO 11) MOSI
//CLK hardware SPI (UNO 13) SCK
NOKIA5110_TEXT mylcd(RST, CE, DC);

ESP8266
// SCK = D5 HSCLK
// SDA = D7 HMosi
NOKIA5110_TEXT mylcd(D2, D1, D6);

ESP32
// SCK = V_SPI_CLK D18
// SDA = V_SPI_D D23
NOKIA5110_TEXT mylcd(4, 27, 15);

STM32 blue pill STM32F103C8T6
// SCK = PA5 SCK1 SCK
// SDA = PA7 MOSI1 SDA
NOKIA5110_TEXT mylcd(PA0, PA1, PA2);
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=NOKIA5110_TEXT
version=2.1.0
version=2.2.0
author=Gavin Lyons <[email protected]>
maintainer=Gavin Lyons <[email protected]>
sentence=NOKIA5110_TEXT is a light-weight library to display ASCII text on Nokia 5110 LCD PCD8544 controller.
paragraph=It displays ASCII Text and is designed for low memory footprint. 96 characters can be displayed with smallest font, Sleep mode included. 9 optional fonts of various sizes, Inverse mode, contrast and bias control. Custom character and bitmap display, Basic Graphics.
paragraph=It displays ASCII Text and is designed for low memory footprint. 96 characters can be displayed with smallest font. Five characters can be displayed with largest font. Sleep mode included. 9 optional fonts of various sizes and styles, Inverse mode, contrast and bias control. Custom characters and bitmap display, Basic Graphics. Hardware or Software SPI.
category=Display
url=https://github.com/gavinlyonsrepo/NOKIA5110_TEXT
architectures=*
77 changes: 62 additions & 15 deletions src/NOKIA5110_TEXT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include "NOKIA5110_TEXT.h"


NOKIA5110_TEXT::NOKIA5110_TEXT(uint8_t LCD_RST, uint8_t LCD_CE, uint8_t LCD_DC, uint8_t LCD_DIN, uint8_t LCD_CLK) {
// Software SPI
NOKIA5110_TEXT::NOKIA5110_TEXT(uint8_t LCD_RST, uint8_t LCD_CE, uint8_t LCD_DC, int8_t LCD_DIN, int8_t LCD_CLK) {

_LCD_RST = LCD_RST;
_LCD_CE = LCD_CE;
Expand All @@ -23,22 +23,56 @@ NOKIA5110_TEXT::NOKIA5110_TEXT(uint8_t LCD_RST, uint8_t LCD_CE, uint8_t LCD_DC,

}

// Hardware SPI
NOKIA5110_TEXT::NOKIA5110_TEXT(uint8_t LCD_RST, uint8_t LCD_CE, uint8_t LCD_DC) {

_LCD_RST = LCD_RST;
_LCD_CE = LCD_CE;
_LCD_DC = LCD_DC;
_LCD_DIN = -1; // -1 for din specify using hardware SPI
_LCD_CLK = -1; // -1 for sclk specify using hardware SPI

}

void NOKIA5110_TEXT::LCDInit(bool Inverse, uint8_t Contrast,uint8_t Bias) {

pinMode(_LCD_RST,OUTPUT);
pinMode(_LCD_CE,OUTPUT);
pinMode(_LCD_DC,OUTPUT);
pinMode(_LCD_DIN,OUTPUT);
pinMode(_LCD_CLK,OUTPUT);
_inverse = Inverse;
_bias = Bias;
_contrast = Contrast;
//Configure control pins

if (isHardwareSPI())
{
#ifdef SPIHW_ON
SPI.begin();
//There is a pre-defined macro SPI_HAS_TRANSACTION in SPI library for checking whether the firmware //of the Arduino board supports SPI.beginTransaction().
#ifdef SPI_HAS_TRANSACTION
{
//SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.beginTransaction(SPISettings(SPI_FREQ, MSBFIRST, SPI_MODE0));
}
#else
{
//STM32 blue pill uses this
SPI.setClockDivider(SPI_CLOCK_DIV8); // 72/8 = 9Mhz
}
#endif
#endif
}else
{
// Set software SPI specific pin outputs.
pinMode(_LCD_DIN, OUTPUT);
pinMode(_LCD_CLK, OUTPUT);
_LCD_DIN_SetLow;
_LCD_CLK_SetLow;

}
pinMode(_LCD_RST,OUTPUT);
pinMode(_LCD_CE,OUTPUT);
pinMode(_LCD_DC,OUTPUT);
_LCD_DC_SetLow;
//Reset the LCD to a known state
_LCD_RST_SetLow;
delay(LCD_RESET_DELAY);
_LCD_RST_SetHigh;
LCDWrite(LCD_COMMAND, LCD_COMMAND_MODE); //Tell LCD that extended commands follow
LCDWrite(LCD_COMMAND, _contrast); //Set LCD Vop (Contrast): Try 0xB1 or 0xBF if your display is too dark
Expand Down Expand Up @@ -88,15 +122,23 @@ void NOKIA5110_TEXT::LCDWrite(unsigned char data_or_command, unsigned char data)
//Tell the LCD that we are writing either to data or a command
//Send the data
_LCD_CE_SetLow;
for(i=0;i<8;i++)
if (isHardwareSPI())
{
_LCD_DIN_SetLow;
if(d&0x80)_LCD_DIN_SetHigh; // b1000000 Mask with 0 & all zeros out.
_LCD_CLK_SetHigh;
d<<=1;
_LCD_CLK_SetLow;
#ifdef SPIHW_ON
(void)SPI.transfer(data); // Hardware SPI
#endif
}else
{
for(i=0;i<8;i++)
{
_LCD_DIN_SetLow;
if(d&0x80)_LCD_DIN_SetHigh; // b1000000 Mask with 0 & all zeros out.
_LCD_CLK_SetHigh;
d<<=1;
_LCD_CLK_SetLow;
}
}
_LCD_CE_SetHigh;
_LCD_CE_SetHigh;
}

void NOKIA5110_TEXT::LCDCharacter(char character)
Expand Down Expand Up @@ -357,5 +399,10 @@ void NOKIA5110_TEXT::LCDdraw_fonts_8TO9(char character)
}

bool NOKIA5110_TEXT::LCDIsSleeping() { return _sleep;}

bool NOKIA5110_TEXT::isHardwareSPI()
{
return (_LCD_DIN == -1 && _LCD_CLK == -1);
}

/* =========== EOF ===========*/
Loading

0 comments on commit a597d69

Please sign in to comment.