u8g2 - u8g2 graphics processing library#

Adapted Air780E/Air700E Air780EP Air601 Air101/Air103 Air105 ESP32C3 ESP32S3

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view the demo example of u8g2

Constant#

constant

type

explanation

u8g2.DRAW_UPPER_RIGHT

number

Upper Right

u8g2.DRAW_UPPER_LEFT

number

Upper Left

u8g2.DRAW_LOWER_LEFT

number

Lower Left

u8g2.DRAW_LOWER_RIGHT

number

Lower Right

u8g2.DRAW_ALL

number

All

u8g2.BTN_BW0

number

No border around text

u8g2.BTN_BW1

number

Border around text, 1 pixel border width

u8g2.BTN_BW2

number

Border around text, 2 pixel border width

u8g2.BTN_BW3

number

Border around text, 3 pixel border width

u8g2.BTN_SHADOW0

number

Enable shadows, no gaps from frame

u8g2.BTN_SHADOW1

number

Enable shadows, 1 pixel gap to frame

u8g2.BTN_SHADOW2

number

Enable shadows, 2 pixel gap to frame

u8g2.BTN_INV

number

Reverse Text

u8g2.BTN_HCENTER

number

Place the text in the center of the frame and change the reference position to the center of the text

u8g2.BTN_XFRAME

number

Draw a second 1 pixel box around the button

u8g2.begin(conf)#

u8g2 Display initialization

Parameters

Incoming Value Type

Explanation

table

conf Configuration information, detailed configuration see the following example

Return Value

return value type

explanation

int

Normal initialization 1, already initialized 2, insufficient memory 3, initialization failure return 4

Examples

-- conf Configuration Item Description
-- ic String, master chip type, support custom (custom command) ssd1306 (default) ssd1309 ssd1322 sh1106 sh1107 sh1108 st7567 uc1701 ssd1306_128x32
-- direction Value, direction, optional 0 90 180 270 default 0
-- mode String, Pattern, Optional i2c_sw: Software i2c i2c_hw: Hardware i2c,spi_hw_4pin: Hardware spi
-- i2c_id: Value, valid for hardware i2c
-- i2c_scl: Value, GPIO number of clock line at software i2c
-- i2c_sda: GPIO number of data line for numerical software i2c
-- spi_id、spi_res、spi_dc、spi_cs: Value, SPI number of hardware spi, reset GPIO number, GPIO number of DC line, GPIO number of CS line
-- x_offset: Value, X-axis offset, default drive, 2023.11.10 new configuration item

-- Initialize hardware for i2c ssd1306
u8g2.begin({ic = "ssd1306",direction = 0,mode="i2c_hw",i2c_id=0}) -- direction Optional 0 90 180 270
-- initialize hardware spi ssd1306
u8g2.begin({ic = "ssd1306",direction = 0,mode="spi_hw_4pin",spi_id=0,spi_res=pin.PB03,spi_dc=pin.PB01,spi_cs=pin.PB04}) -- direction Optional 0 90 180 270
-- initialization software i2c ssd1306
u8g2.begin({ic = "ssd1306",direction = 0,mode="i2c_sw", i2c_scl=1, i2c_sda=4}) -- Simulation via PA1 SCL / PA4 SDA

u8g2.close()#

Turn off display

Parameters

None

Return Value

None

Examples

-- If disp is closed and the disp-related API is used again, it needs to be reinitialized.
u8g2.close()

u8g2.ClearBuffer()#

Clear screen, clear all pixels in memory frame buffer

Parameters

None

Return Value

None

Examples

-- Clear screen
u8g2.ClearBuffer()

u8g2.SendBuffer()#

Update data to the screen, send the contents of the memory frame buffer to the display

Parameters

None

Return Value

None

Examples

-- Update the display data to the screen
u8g2.SendBuffer()

u8g2.DrawUTF8(str, x, y)#

Draw a paragraph of text on the display screen, and draw a paragraph of text on the display screen. Only when u8g2.SendBuffer() is called will it be updated to the screen. Note: Set the coordinates to the coordinates of the lower left corner of the display string.

Parameters

Incoming Value Type

Explanation

string

Document Content

int

abscissa

int

Vertical Coordinates

Return Value

None

Examples

u8g2.DrawUTF8("wifi is ready", 10, 20)

u8g2.DrawButtonUTF8(str, x, y, flags, w, h, v, str)#

Draw a box around the provided text. This is similar to DrawUTF8, but adds some decoration to the text. To call u8g2.SendBuffer() will be updated to the screen Note: Set the coordinates to the lower left corner coordinates of the display string

Parameters

Incoming Value Type

Explanation

string

Document Content

int

abscissa

int

Vertical Coordinates

int

flags Multiple flags can be used with the OR operator。

int

The minimum width of the text. If 0 (or lower than the text width), the text width will be used for the frame。

int

Extra space before and after text。

int

Extra space above and below text。

Return Value

None

Examples

u8g2.DrawButtonUTF8("str", 10, 20,u8g2.BTN_BW2,0,2,2)

u8g2.SetFontMode(mode)#

Set font mode

Parameters

Incoming Value Type

Explanation

int

mode Font mode, enable (1) or disable (0) transparent mode

Return Value

None

Examples

u8g2.SetFontMode(1)

u8g2.SetFont(font, indentation)#

Set Font

Parameters

Incoming Value Type

Explanation

userdata

font, u8g2.font_opposansm8 For pure English font 8, there are font_opposansm10 font_opposansm12 font_opposansm16 font_opposansm18 font_opposansm20 font_opposansm22 font_opposansm32 optional u8g2.font_opposansm12_chinese is 12x 12 all Chinese, there are font_opposansm16_chinese font_opposansm24_chinese font_opposansm32_chinese optional, u8g2.font_unifont_t_symbols is symbol.

int

indentation, the right side of ascii in a constant-width font is indented by 0 to 127 pixels. ascii characters in a constant-width font may have a large blank space on the right side. you can delete some of them. If it is left blank or exceeds 127, the right half will be deleted directly. Non-equal-width fonts are invalid.

Return Value

None

Examples

-- Set to Chinese font, valid for subsequent drawStr
u8g2.SetFont(u8g2.font_opposansm12)

u8g2.GetDisplayHeight()#

Get Display Height

Parameters

None

Return Value

return value type

explanation

int

Display height

Examples

u8g2.GetDisplayHeight()

u8g2.GetDisplayWidth()#

Get Display Width

Parameters

None

Return Value

return value type

explanation

int

Display Width

Examples

u8g2.GetDisplayWidth()

u8g2.SetDrawColor(c)#

Assigns a drawing color to all drawing functions.

Parameters

Incoming Value Type

Explanation

int

c Color value 0 No color 1 Colored 2 with background color xor

Return Value

None

Examples

u8g2.SetDrawColor(0)

u8g2.DrawPixel(x,y)#

draw a dot.

Parameters

Incoming Value Type

Explanation

int

X Location.

int

Y Location.

Return Value

None

Examples

u8g2.DrawPixel(20, 5)

u8g2.DrawLine(x0,y0,x1,y1)#

draw a line between two points.

Parameters

Incoming Value Type

Explanation

int

X position of the first point.

int

Y position of the first point.

int

X position of the second point.

int

Y position of second point.

Return Value

None

Examples

u8g2.DrawLine(20, 5, 5, 32)

u8g2.DrawCircle(x0,y0,rad,opt)#

Draw a hollow circle with radius rad at x,y position.

Parameters

Incoming Value Type

Explanation

int

Position of center of circle

int

Position of center of circle

int

circle radius.

int

Select part or all of the circle. Default full drawing optional u8g2.DRAW_UPPER_RIGHT u8g2.DRAW_UPPER_LEFT u8g2.DRAW_LOWER_LEFT u8g2.DRAW_LOWER_RIGHT u8g2.DRAW_ALL

Return Value

None

Examples

u8g2.DrawCircle(60,30,8,u8g2.DRAW_ALL)

u8g2.DrawDisc(x0,y0,rad,opt)#

Draw a solid circle with radius rad at x,y position.

Parameters

Incoming Value Type

Explanation

int

Position of center of circle

int

Position of center of circle

int

circle radius.

int

Select part or all of the circle. Default full drawing optional u8g2.DRAW_UPPER_RIGHT u8g2.DRAW_UPPER_LEFT u8g2.DRAW_LOWER_LEFT u8g2.DRAW_LOWER_RIGHT u8g2.DRAW_ALL

Return Value

None

Examples

u8g2.DrawDisc(60,30,8,u8g2.DRAW_ALL)

u8g2.DrawEllipse(x0,y0,rx,ry,opt)#

Draw a hollow ellipse with radius rad at x,y position.

Parameters

Incoming Value Type

Explanation

int

Position of center of circle

int

Position of center of circle

int

Ellipse Size

int

Ellipse Size

int

Select part or all of the circle. Default full drawing optional u8g2.DRAW_UPPER_RIGHT u8g2.DRAW_UPPER_LEFT u8g2.DRAW_LOWER_LEFT u8g2.DRAW_LOWER_RIGHT u8g2.DRAW_ALL

Return Value

None

Examples

u8g2.DrawEllipse(60,30,8,u8g2.DRAW_ALL)

u8g2.DrawFilledEllipse(x0,y0,rx,ry,opt)#

Draw a solid ellipse with radius rad at x,y position.

Parameters

Incoming Value Type

Explanation

int

Position of center of circle

int

Position of center of circle

int

Ellipse Size

int

Ellipse Size

int

Select part or all of the circle. Default full drawing optional u8g2.DRAW_UPPER_RIGHT u8g2.DRAW_UPPER_LEFT u8g2.DRAW_LOWER_LEFT u8g2.DRAW_LOWER_RIGHT u8g2.DRAW_ALL

Return Value

None

Examples

u8g2.DrawFilledEllipse(60,30,8,15)

u8g2.DrawBox(x,y,w,h)#

Draw a box (filled box starting from the x / y position (upper left edge)).

Parameters

Incoming Value Type

Explanation

int

X position of upper left edge

int

Y position of upper left edge

int

The width of the box

int

Height of the box

Return Value

None

Examples

u8g2.DrawBox(3,7,25,15)

u8g2.DrawFrame(x,y,w,h)#

Draw a box from the x / y position (upper left edge) (empty box)).

Parameters

Incoming Value Type

Explanation

int

X position of upper left edge

int

Y position of upper left edge

int

The width of the box

int

Height of the box

Return Value

None

Examples

u8g2.DrawFrame(3,7,25,15)

u8g2.DrawRBox(x,y,w,h,r)#

Draw a filled box/frame with a rounded edge starting from the x / y position (top left edge).

Parameters

Incoming Value Type

Explanation

int

X position of upper left edge

int

Y position of upper left edge

int

The width of the box

int

Height of the box

int

Radius of the four edges

Return Value

None

Examples

u8g2.DrawRBox(3,7,25,15)

u8g2.DrawRFrame(x,y,w,h,r)#

Draw an empty box/frame with rounded edges starting from the x / y position (top left edge).

Parameters

Incoming Value Type

Explanation

int

X position of upper left edge

int

Y position of upper left edge

int

The width of the box

int

Height of the box

int

Radius of the four edges

Return Value

None

Examples

u8g2.DrawRFrame(3,7,25,15)

u8g2.DrawGlyph(x,y,encoding)#

Draws a graphic character. The character is placed at the specified pixel position x and y.

Parameters

Incoming Value Type

Explanation

int

Position of characters on the display

int

Position of characters on the display

int

Unicode value of character

Return Value

None

Examples

u8g2.SetFont(u8g2_font_unifont_t_symbols)
u8g2.DrawGlyph(5, 20, 0x2603)    -- dec 9731/hex 2603 Snowman

u8g2.DrawTriangle(x0,y0,x1,y1,x2,y2)#

Draw a triangle (solid polygon).

Parameters

Incoming Value Type

Explanation

int

Point 0X Position

int

Point 0Y Position

int

Point 1X Position

int

Point 1Y position

int

Point 2X Position

int

Point 2Y position

Return Value

None

Examples

u8g2.DrawTriangle(20,5, 27,50, 5,32)

u8g2.SetBitmapMode(mode)#

Defines whether the bitmap function will write the background color

Parameters

Incoming Value Type

Explanation

int

mode Font mode, enable (1) or disable (0) transparent mode

Return Value

None

Examples

u8g2.SetBitmapMode(1)

u8g2.DrawXBM(x, y, w, h, data)#

Draw Bitmap

Parameters

Incoming Value Type

Explanation

int

X Coordinates

int

y Coordinates

int

bitmap width

int

Bitmap Height

int

Bitmap data, each bit representing a pixel

Return Value

None

Examples

-- The mold can be taken using PCtoLCD2002 software.
-- In (0,0) for the upper left corner, draw a 16x 16 "today" bitmap
u8g2.DrawXBM(0, 0, 16,16, string.char(
    0x80,0x00,0x80,0x00,0x40,0x01,0x20,0x02,0x10,0x04,0x48,0x08,0x84,0x10,0x83,0x60,
    0x00,0x00,0xF8,0x0F,0x00,0x08,0x00,0x04,0x00,0x04,0x00,0x02,0x00,0x01,0x80,0x00
))

u8g2.DrawDrcode(x, y, str, size)#

Buffer Drawing QRCode

Parameters

Incoming Value Type

Explanation

int

x Coordinates

int

y Coordinates

string

The content of the two-dimensional code

int

Display size (note: the generated size of the two-dimensional code is related to the content to be displayed and the error correction level. the generated version is an indefinite size of 1-40 (corresponding to 21x21-177x177). if the size is different from the set size, the two-dimensional code will be automatically displayed in the middle of the specified area. if the two-dimensional code is not displayed, please check the log prompt.)

Return Value

return value type

explanation

nil

No return value

Examples

None


u8g2.SetContrast(contrast)#

Adjust screen contrast

Parameters

Incoming Value Type

Explanation

int

Contrast ratio (the value range is related to IC, such as st7567 0-63)

Return Value

return value type

explanation

nil

No return value

Examples

None


u8g2.drawGtfontGb2312(str,size,x,y)#

Using gtfont to display gb2312 strings

Parameters

Incoming Value Type

Explanation

string

str Display String

int

size Font size (supports 16-192 size fonts)

int

x abscissa

int

y Vertical Coordinates

Return Value

None

Examples

u8g2.drawGtfontGb2312("Ah ah ah",32,0,0)

u8g2.drawGtfontUtf8(str,size,x,y)#

Using gtfont to display UTF8 strings

Parameters

Incoming Value Type

Explanation

string

str Display String

int

size Font size (supports 16-192 size fonts)

int

x abscissa

int

y Vertical Coordinates

Return Value

None

Examples

u8g2.drawGtfontUtf8("Ah ah ah",32,0,0)

u8g2.CopyBuffer(buff)#

Get the underlying image buffer

Parameters

Incoming Value Type

Explanation

userdata

zbuff instance, the space should be greater than or equal to the size of the underlying buff

Return Value

return value type

explanation

int

Returns buff size on success, otherwise nil

Examples

-- This function can only be called after u8g2 is initialized.

-- Get Size
local sz = u8g2.CopyBuffer()

-- Copy the bottom layer buff
local buff = zbuff.create(sz)
u8g2.CopyBuffer(buff)

u8g2.SetPowerSave(is_enable)#

Set power saving mode

Parameters

Incoming Value Type

Explanation

boolean

Enabled or not. true enabled, false disabled

Return Value

return value type

explanation

nil

No return value

Examples

-- This API was added on 2023.11.02
-- Power saving on
u8g2.SetPowerSave(true)
-- Power saving off
u8g2.SetPowerSave(false)