OledLib: OledExpansion Graphics Library in Python
-
OledLib
Onion Omega OledExpansion Graphics Library in Python
Intro
OledLibis a small graphics library for the OledExpansion module for Onion Omega IoT devices.While the
oledExpPython module mainly deals with writing text on screen,OledLibdives deeper into pixel precise graphics.
OledLibbreaks the limit of 8 pages and 128 columns, giving access to all 128x64 pixels of the screen. It is also faster since it uses thei2cinterface 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,OledExpansionbecomes 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
OledLiblibrary.API
clearBuffers: Clears the framebuffer (all elements to0).putPixel(x, y, value): Puts thevalue(0or1) atx,ycoordinates.putRectangle(x, y, width, height, fill): Puts a rectangle (widthxheight) at the specifiedx,ycoordinates. SettingfilltoTruewill fill the rectangle, whereFalsewill draw just the borders.putBitmap(x, y, bitmap): Puts abitmapMxN array of0s and1s tox,ycoordinates.translateBitmap(bitmap): Converts a MxNbitmaparray where each element is abit(0or1), to abytearray MxL where each element is abyte(8bits). Bitmap array sizes can be:0<M<128and0<N<64, and the translated bitmap will have sizes:0<M<128and0<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 thebitmap90 degrees.rotateBitmap180(bitmap): Rotates thebitmap180 degrees.rotateBitmap270(bitmap): Rotates thebitmap270 degrees.blit(): Renders the wholeframebufferto screen at maximum fast rate.pageBlit(pageNo, x, length): Renders portion of a page, (row) withlengthstarting fromx, to screen at maximum fast rate. Does not clear theframebufferafter.bitmapBlit(x, y, translatedBitmap): Instead of filling the whole 128x64 framebuffer it renders only the region of atranslatedBitmapon the screen atx,ylocation, sort of Direct Memory Access (DMA). Requires thetranslatedBitmapfromtranslateBitmap()as input. Does not clear theframebufferafter.
Github link:
-
Wrote some code, PerformanceDMADemo.py to measure the
bitmapBlit()performance for various bitmap sizes (MxNpixels). 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.
