Ucglib is a graphics library developed at olikraus/ucglib with support for color TFT displays. The NodeMCU firmware supports a subset of these:
This integration is based on v1.3.3.
The HSPI module is used, so certain pins are fixed:
All other pins can be assigned to any available GPIO:
Also refer to the initialization sequence eg in GraphicsTest.lua:
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
The Lua bindings for this library closely follow ucglib’s object oriented C++ API. Based on the ucg class, you create an object for your display type.
ILI9341 via SPI:
cs = 8 -- GPIO15, pull-down 10k to GND
dc = 4 -- GPIO2
res = 0 -- GPIO16, RES is optional YMMV
disp = ucg.ili9341_18x240x320_hw_spi(cs, dc, res)
This object provides all of ucglib’s methods to control the display. Again, refer to GraphicsTest.lua to get an impression how this is achieved with Lua code. Visit the ucglib homepage for technical details.
o get access to the display constructors, add the desired entries to the display table in app/include/ucg_config.h:
#define UCG_DISPLAY_TABLE \
UCG_DISPLAY_TABLE_ENTRY(ili9341_18x240x320_hw_spi, ucg_dev_ili9341_18x240x320, ucg_ext_ili9341_18) \
UCG_DISPLAY_TABLE_ENTRY(st7735_18x128x160_hw_spi, ucg_dev_st7735_18x128x160, ucg_ext_st7735_18) \
ucglib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you’d need to include them in app/include/ucg_config.h and recompile. Simply add the desired fonts to the font table:
#define UCG_FONT_TABLE \
UCG_FONT_TABLE_ENTRY(font_7x13B_tr) \
UCG_FONT_TABLE_ENTRY(font_helvB12_hr) \
UCG_FONT_TABLE_ENTRY(font_helvB18_hr) \
UCG_FONT_TABLE_ENTRY(font_ncenR12_tr) \
UCG_FONT_TABLE_ENTRY(font_ncenR14_hr)
They’ll be available as ucg.<font_name>
in Lua.
Initialize a display via Hardware SPI.
ili9163_18x128x128_hw_spi()
ili9341_18x240x320_hw_spi()
pcf8833_16x132x132_hw_spi()
seps225_16x128x128_univision_hw_spi()
ssd1351_18x128x128_hw_spi()
ssd1351_18x128x128_ft_hw_spi()
ssd1331_18x96x64_univision_hw_spi()
st7735_18x128x160_hw_spi()
ucg.st7735_18x128x160_hw_spi(cs, dc, res)
cs
: GPIO pin for /CS.dc
: GPIO pin for DC.res
: GPIO pin for /RES (optional).ucg display object.
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
cs = 8 -- GPIO15, pull-down 10k to GND
dc = 4 -- GPIO2
res = 0 -- GPIO16, RES is optional YMMV
disp = ucg.st7735_18x128x160_hw_spi(cs, dc, res)
ucg.FONT_MODE_TRANSPARENT
, ucg.FONT_MODE_SOLID
, ucg.DRAW_UPPER_RIGHT
,
ucg.DRAW_UPPER_LEFT
, ucg.DRAW_LOWER_RIGHT
, ucg.DRAW_LOWER_LEFT
, ucg.DRAW_ALL
ucg.font_7x13B_tr
, …
ucglib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you’d need to include them in app/include/ucg_config.h and recompile. Simply add the desired fonts to the font table:
#define UCG_FONT_TABLE \
UCG_FONT_TABLE_ENTRY(font_7x13B_tr) \
UCG_FONT_TABLE_ENTRY(font_helvB12_hr) \
UCG_FONT_TABLE_ENTRY(font_helvB18_hr) \
UCG_FONT_TABLE_ENTRY(font_ncenR12_tr) \
UCG_FONT_TABLE_ENTRY(font_ncenR14_hr)
They’ll be available as ucg.<font_name>
in Lua.
disp:setFont(font)
font
: Constant to identify pre-compiled font.nil
disp:setFont(ucg.font_7x13B_tr)