OledLib: OledExpansion Graphics Library in Python
-
OledLib
Onion Omega OledExpansion Graphics Library in Python
Intro
OledLib
is a small graphics library for the OledExpansion module for Onion Omega IoT devices.While the
oledExp
Python module mainly deals with writing text on screen,OledLib
dives deeper into pixel precise graphics.
OledLib
breaks the limit of 8 pages and 128 columns, giving access to all 128x64 pixels of the screen. It is also faster since it uses thei2c
interface which is capable of sending 32 bytes of data simultaneously instead of only 1 byte (oledExp.write(byte)
).With
OledLib
's ability to address each pixel individually,OledExpansion
becomes much more versatile and capable of rendering complex graphics.Features
- 128x64 framebuffer, pixel-level precision.
- Up to 32 bytes sent to screen simultaneously.
- 1-bit bitmap rendering.
- DMA (Direct Memory Access) functionality to fast render a portion of the screen only.
- Special effects: rotation and scaling.
Prerequisites
Requires oledExp and onionI2C Python modules to be installed on the Onion Omega IoT device.
Demonstration
Below is a video showcasing most features of the
OledLib
library.API
clearBuffers
: Clears the framebuffer (all elements to0
).putPixel(x, y, value)
: Puts thevalue
(0
or1
) atx
,y
coordinates.putRectangle(x, y, width, height, fill)
: Puts a rectangle (width
xheight
) at the specifiedx
,y
coordinates. Settingfill
toTrue
will fill the rectangle, whereFalse
will draw just the borders.putBitmap(x, y, bitmap)
: Puts abitmap
MxN array of0
s and1
s tox
,y
coordinates.translateBitmap(bitmap)
: Converts a MxNbitmap
array where each element is abit
(0
or1
), to abyte
array MxL where each element is abyte
(8bits
). Bitmap array sizes can be:0<M<128
and0<N<64
, and the translated bitmap will have sizes:0<M<128
and0<L<8
. Useful for achieving faster rendering rates. Use before callingbitmapBlit()
.scaleBitmap(bitmap, scaleX, scaleY)
: Scales down the givenbitmap
. Each axis can scale differently by settingscaleX
,scaleY
. Positive integer values only.rotateBitmap90(bitmap)
: Rotates thebitmap
90 degrees.rotateBitmap180(bitmap)
: Rotates thebitmap
180 degrees.rotateBitmap270(bitmap)
: Rotates thebitmap
270 degrees.blit()
: Renders the wholeframebuffer
to screen at maximum fast rate.pageBlit(pageNo, x, length)
: Renders portion of a page, (row) withlength
starting fromx
, to screen at maximum fast rate. Does not clear theframebuffer
after.bitmapBlit(x, y, translatedBitmap)
: Instead of filling the whole 128x64 framebuffer it renders only the region of atranslatedBitmap
on the screen atx
,y
location, sort of Direct Memory Access (DMA). Requires thetranslatedBitmap
fromtranslateBitmap()
as input. Does not clear theframebuffer
after.
Github link:
-
Wrote some code, PerformanceDMADemo.py to measure the
bitmapBlit()
performance for various bitmap sizes (MxN
pixels). Measures below are only for rendering one bitmap on screen each time.Bitmap size (in pixels) FPS 64x64 8.38996560114 32x32 27.0965993768 24x24 41.8497593639 16x16 74.5712155108 8x8 180.342651037 4x4 204.498977505 2x2 219.538968167 1x1 226.500566251
-
@elefas-GR nice project and equally nice presentation. thanks for sharing.