Since | Origin / Contributor | Maintainer | Source |
---|---|---|---|
2017-06-02 | Oli Kraus, Arnim Läuger | Arnim Läuger | u8g2.c |
U8g2 is a graphics library developed at olikraus/u8g2 with support for many different displays. It is the successor of U8glib which is not developed any further.
The NodeMCU firmware supports the following displays in I²C and SPI mode:
SPI only:
This integration is based on v2.19.8.
Hook up SDA and SCL to any free GPIOs. Eg. graphics_test.lua expects SDA=GPIO16 and SCL=GPIO17. They are used to set up nodemcu’s I²C driver before accessing the display:
id = i2c.HW0
sda = 16
scl = 17
i2c.setup(id, sda, scl, i2c.FAST)
Hook up pins to any free GPIOs:
Again, refer to the initialization sequence eg. in graphics_test.lua:
sclk = 19
mosi = 23
bus = spi.master(spi.HSPI, {sclk=sclk, mosi=mosi})
The Lua bindings for this library closely follow u8g2’s object oriented C++ API. Based on the u8g2 class, you create an object for your display type.
SSD1306 via I²C:
sla = 0x3c
disp = u8g2.ssd1306_i2c_128x64_noname(id, sla)
SSD1306 via SPI:
cs = 22
dc = 16
res = 0 -- RES is optional YMMV
disp = u8g2.ssd1306_128x64_noname(bus, cs, dc, res)
This object provides all of u8g2’s methods to control the display. Refer to graphics_test.lua to get an impression how this is achieved with Lua code. Visit the u8g2 homepage for technical details.
I²C and HW SPI based displays with support in u8g2 can be enabled. To get access to the respective constructors, enable the desired entries for I²C and SPI displays in u8g2’s sub-menu (run make menuconfig
).
u8g2 comes with a wide range of fonts for small displays. They can be supplied as strings or compiled into the firmware image to decrease the RAM footprint. Simply add the desired fonts to the font selection sub-entry via make menuconfig
.
They’ll become available as u8g2.<font_name>
in Lua.
XBM bitmaps are supplied as strings to drawXBM()
. This off-loads all data handling from the u8g2 module to generic methods for binary files. See graphics_test.lua.
In contrast to the source code based inclusion of XBMs in upstream u8g2 library, it’s required to provide precompiled binary files. This can be performed online with Online-Utility’s Image Converter: Convert from XBM to MONO format and upload the binary result.
Initialize a display via I²C.
u8g2.ld7032_i2c_60x32()
u8g2.sh1106_i2c_128x64_noname()
u8g2.sh1106_i2c_128x64_vcomh0()
u8g2.ssd1305_i2c_128x32_noname()
u8g2.ssd1306_i2c_128x32_univision()
u8g2.ssd1306_i2c_128x64_noname()
u8g2.ssd1306_i2c_128x64_vcomh0()
u8g2.ssd1309_i2c_128x64_noname0()
u8g2.ssd1309_i2c_128x64_noname2()
u8g2.ssd1306_i2c_64x48_er()
u8g2.ssd1306_i2c_96x16_er()
u8g2.ssd1325_i2c_nhd_128x64()
u8g2.ssd1327_i2c_seeed_96x96()
u8g2.st7588_i2c_jlx12864()
u8g2.uc1602_i2c_128X32()
u8g2.uc1604_i2c_jlx19264()
u8g2.uc1608_i2c_erc24064()
u8g2.uc1608_i2c_240x128()
u8g2.uc1610_i2c_ea_dogxl160()
u8g2.uc1611_i2c_ea_dogm240()
u8g2.uc1611_i2c_ea_dogxl240()
u8g2.uc1611_i2c_ew50850()
u8g2.ssd1306_i2c_128x64_noname(id, address[, cb_fn])
id
i2c interface id, see i2c moduleaddress
I²C slave address of display (unshifted)cb_fn
optional callback function, see Framebuffer callbacku8g2 display object
id = i2c.HW0
sda = 16
scl = 17
sla = 0x3c
i2c.setup(id, sda, scl, i2c.FAST)
disp = u8g2.ssd1306_i2c_128x64_noname(id, sla)
Initialize a display via Hardware SPI.
u8g2.il3820_v2_296x128()
u8g2.ist3020_erc19264()
u8g2.ld7032_60x32()
u8g2.ls013b7dh03_128x128()
u8g2.max7219_32x8()
u8g2.nt7534_tg12864r()
u8g2.pcd8544_84x48()
u8g2.pcf8812_96x65()
u8g2.sh1106_128x64_noname()
u8g2.sh1106_128x64_vcomh0()
u8g2.ssd1305_128x32_noname()
u8g2.ssd1306_128x32_univision()
u8g2.ssd1306_128x64_noname()
u8g2.ssd1306_128x64_vcomh0()
u8g2.ssd1306_64x48_er()
u8g2.ssd1306_96x16_er()
u8g2.ssd1309_128x64_noname0()
u8g2.ssd1309_128x64_noname2()
u8g2.sed1520_122x32()
u8g2.ssd1322_nhd_256x64()
u8g2.ssd1325_nhd_128x64()
u8g2.ssd1327_seeed_96x96()
u8g2.ssd1329_128x96_noname()
u8g2.ssd1606_172x72()
u8g2.ssd1607_200x200()
u8g2.st7565_64128n()
u8g2.st7565_ea_dogm128()
u8g2.st7565_ea_dogm132()
u8g2.st7565_erc12864()
u8g2.st7565_lm6059()
u8g2.st7565_nhd_c12832()
u8g2.st7565_nhd_c12864()
u8g2.st7565_zolen_128x64()
u8g2.st7567_jxl12864()
u8g2.st7567_pi_132x64()
u8g2.st7588_jlx12864()
u8g2.st7920_s_128x64()
u8g2.st7920_s_192x32()
u8g2.st75256_jlx172104()
u8g2.st75256_jlx256128()
u8g2.uc1601_128X32()
u8g2.uc1604_jlx19264()
u8g2.uc1608_240x128()
u8g2.uc1608_erc24064()
u8g2.uc1610_ea_dogxl160()
u8g2.uc1611_ew50850()
u8g2.uc1611_ea_dogm240()
u8g2.uc1611_ea_dogxl240()
u8g2.uc1701_ea_dogs102()
u8g2.uc1701_mini12864()
u8g2.ssd1306_128x64_noname(cs, dc[, [res][, cb_fn]])
cs
GPIO pin for CSdc
GPIO pin for DCres
GPIO pin for RES, none if omittedcb_fn
optional callback function, see Framebuffer callbacku8g2 display object
sclk = 19
mosi = 23
cs = 22
dc = 16
res = 17
bus = spi.master(spi.HSPI, {sclk=sclk, mosi=mosi})
disp = u8g2.ssd1306_128x64_noname(bus, cs, dc, res)
Each display type can be initialized to provide the framebuffer contents in run-length encoded format to a Lua callback. This mode is enabled when a callback function is specified for the setup function. Hardware display and framebuffer callback can be operated in parallel. If the callback function is the only parameter then no signals for a hardware display are generated, leaving a virtual display.
The callback function can be used to process the framebuffer line by line. It’s called with either nil
as parameter to indicate the start of a new frame or with a string containing a line of the framebuffer with run-length encoding. First byte in the string specifies how many pairs of (x, len) follow, while each pair defines the start (leftmost x-coordinate) and length of a sequence of lit pixels. All other pixels in the line are dark.
n = struct.unpack("B", rle_line)
print(n.." pairs")
for i = 0,n-1 do
print(string.format(" x: %d len: %d", struct.unpack("BB", rle_line, 1+1 + i*2)))
end
u8g2.ssd1306_i2c_128x64_noname(id, address[, cb_fn])
u8g2.ssd1306_i2c_128x64_noname(cb_fn)
u8g2.ssd1306_128x64_noname(cs, dc[, [res][, cb_fn]])
u8g2.ssd1306_128x64_noname(cb_fn)
id
, address
, cs
, dc
, res
see abovecb_fn([rle_line])
callback function. rle_line
is a string containing a run-length encoded framebuffer line, or nil
to indicate start of frame.Constants for various functions.
u8g2.DRAW_UPPER_RIGHT
, u8g2.DRAW_UPPER_LEFT
, u8g2.DRAW_LOWER_RIGHT
, u8g2.DRAW_LOWER_LEFT
, u8g2.DRAW_ALL
,
u8g2.R0
, u8g2.R1
, u8g2.R2
, u8g2.R3
, u8g2.MIRROR
,
u8g2.font_6x10
, …