Nokia 5110 PCD8544 with nodeMCU ESP8266 using Lua and u8g2

What we want to achieve

Use a display with PCD8544 CMOS LCD controller/driver - e.g. Nokia 5110 LED Display - with a nodeMCU ESP8266 compatible development board and Lua.

Requirements

  • nodeMCU ESP8266 compatible development board (see here)
  • Display with PCD8544 controller - e.g. Nokia 5110 - (see here)
  • nodeMCU firmware with the following modules included: gpio, i2c, spi, u8g2, uart
    • u8g2 configuration - ensure you include your fonts. For the example here we will need the 6x10_tf and 5x8_tf font
For simplicity, you can download a suitable firmware here.
The firmware was created using the online service nodemcu-build.com

    Restrictions

    • This tip is focused on Lua and ESP8266
    •  The pin connections are guaranteed to work with our Nokia 5110 displays. Other similar displays might have a different pin layout and you will need to adapt to your specific module.
    • The tip uses SPI, hence there might be conflicts if you are using other SPI modules.

    How to

    The u8g2 module only supports the PCD8544 controller via SPI. This means we will have to use the HMOSI and HSCLK GPIOs on the development board. For the connections, you are welcome to change the pin layout to suit your project needs. 

    Wiring

       PCD8544/LED ESP8266
      Pin 1 - RST D0/GPIO16
      Pin 2 - CE (CS) D8/GPIO15 - pull down with 10k resistor to GND
      Pin 3 - DC D4/GPIO2
      Pin 4 - DIN D7/HMOSI (fixed - you can't use a different pin)
      Pin 5 - CLK D5/HSCLK (fixed - you can't use a different pin)
      Pin 6 - VCC 3.3V - either from Development board or other sources
      Pin 7 - BL Not used in this example
      Pin 8 - GND GND - either from Development board or another source

       

      Code 

      --[[
      	Nokia 5110 LED with PCD8544
      	8 November 2018 
      	Author: dante@serveronthemove.com.au
      	Hardware:
      		nodeMCU ESP8266(EX) Devkit V3
      		8 pin Nokia 5110 84x48 display w PCD8544
      
      	Wiring:
      		LED			->	NodeMCU 8266
      		1 - RST		->	D0/GPIO16
      		2 - CE (CS)	->	D8/GPIO15 - pull down with 10K to GND
      		3 - DC		->	D4/GPIO2
      		4 - DIN		->	D7/HMOSI
      		5 - CLK		->	D5/HSCLK
      		6 - VCC		->	3.3V
      		7 - BL		->	Not used in this example
      		8 - GND		->	GND
      
      	nodeMCU Firmware Build
      		built against the master branch and includes the following modules: file, gpio, i2c, net, node, spi, tmr, u8g2, uart, wifi, tls
      		u8g2 - SPI - pcd8544_84x48 module
      		u8g2 - fonts: 6x10_tf, 5x8)tf
      --]]
      
      -- Variables 
      PIN_CS  = 8 -- GPIO15, pull-down 10k to GND
      PIN_DC  = 4 -- GPIO2
      PIN_RES = 0 -- GPIO16
      M_BUS 	= 1
      
      -- Initialise module
      spi.setup(M_BUS, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
      --gpio.mode(cs, gpio.INPUT, gpio.PULLUP)
      disp = u8g2.pcd8544_84x48(M_BUS, PIN_CS, PIN_DC, PIN_RES)
      
      disp:setFontRefHeightExtendedText()
      disp:setContrast(125)
      disp:setFontPosTop()
      
      -- start
      disp:clearBuffer() -- start with clean buffer
      disp:setFont(u8g2.font_6x10_tf) -- set 6x10 font
      disp:drawStr(1, 1, "Nokia 5110")
      disp:drawStr(1, 9, "(PCD8544) test")
      disp:drawStr(2, 17, "for nodeMCU")
      disp:drawStr(2, 25, "by")
      disp:setFont(u8g2.font_5x8_tf) -- switch to smaller font
      disp:drawStr(1, 33, "ServerOnTheMove")
      disp:drawStr(48, 39, ".com.au")
      disp:sendBuffer() -- sent buffer to display
      
      -- and done
      

      Leave a Reply

      All blog comments are checked prior to publishing