|
| 1 | +# BFU UA Display |
| 2 | + |
| 3 | +Ukrainian text rendering library for MicroPython displays. |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +A lightweight library for rendering Ukrainian text on displays commonly used with ESP32 and MicroPython projects. Standard MicroPython display libraries do not include Ukrainian characters (А, Б, В, Г, Ґ, Д, Е, Є, Ж, З, И, І, Ї, Й, etc.), making it impossible to display Ukrainian text properly. This library solves that problem with a custom 5x7 bitmap font containing all 33 Ukrainian letters (uppercase and lowercase). |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Full Ukrainian Alphabet Support** - All 33 Ukrainian letters (uppercase and lowercase) |
| 12 | +- **Lightweight** - Optimized for ESP32 memory constraints (~2-3 KB) |
| 13 | +- **Display Agnostic** - Works with any display supporting `pixel()` method |
| 14 | +- **Simple API** - Three main functions for text rendering |
| 15 | +- **5x7 Bitmap Font** - Compact and readable on small displays |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +```python |
| 20 | +import mip |
| 21 | +mip.install("bfu_ua_display") |
| 22 | +``` |
| 23 | + |
| 24 | +Or using mpremote: |
| 25 | + |
| 26 | +```bash |
| 27 | +mpremote connect COM3 mip install bfu_ua_display |
| 28 | +``` |
| 29 | + |
| 30 | +## Quick Start |
| 31 | + |
| 32 | +```python |
| 33 | +from machine import I2C, Pin |
| 34 | +from ssd1306 import SSD1306_I2C |
| 35 | +from bfu_ua_display import ua_text, ua_text_center |
| 36 | + |
| 37 | +# Initialize display |
| 38 | +i2c = I2C(0, scl=Pin(22), sda=Pin(21)) |
| 39 | +oled = SSD1306_I2C(128, 64, i2c) |
| 40 | + |
| 41 | +# Draw Ukrainian text |
| 42 | +ua_text(oled, "ПРИВІТ УКРАЇНО!", 0, 0) |
| 43 | +ua_text_center(oled, "BFU Electronics", 28) |
| 44 | + |
| 45 | +# Update display |
| 46 | +oled.show() |
| 47 | +``` |
| 48 | + |
| 49 | +## API Reference |
| 50 | + |
| 51 | +### ua_text(display, text, x, y, color=1, bg_color=0, clear_bg=False) |
| 52 | + |
| 53 | +Render text at specified position with Ukrainian character support. |
| 54 | + |
| 55 | +**Parameters:** |
| 56 | +- `display` - Display object with `pixel()` method |
| 57 | +- `text` - String to render (Ukrainian, English, numbers, symbols) |
| 58 | +- `x` - X coordinate (left edge) |
| 59 | +- `y` - Y coordinate (top edge) |
| 60 | +- `color` - Foreground color (default: 1) |
| 61 | +- `bg_color` - Background color (default: 0) |
| 62 | +- `clear_bg` - Clear background behind text (default: False) |
| 63 | + |
| 64 | +**Returns:** Total width of rendered text in pixels |
| 65 | + |
| 66 | +**Example:** |
| 67 | +```python |
| 68 | +ua_text(oled, "Температура: 25°C", 0, 0) |
| 69 | +``` |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### ua_text_center(display, text, y, color=1, bg_color=0, clear_bg=False, display_width=128) |
| 74 | + |
| 75 | +Render text centered horizontally on the display. |
| 76 | + |
| 77 | +**Parameters:** |
| 78 | +- `display` - Display object |
| 79 | +- `text` - String to render |
| 80 | +- `y` - Y coordinate (top edge) |
| 81 | +- `color` - Foreground color (default: 1) |
| 82 | +- `bg_color` - Background color (default: 0) |
| 83 | +- `clear_bg` - Clear background (default: False) |
| 84 | +- `display_width` - Display width in pixels (default: 128) |
| 85 | + |
| 86 | +**Returns:** X coordinate where text was rendered |
| 87 | + |
| 88 | +**Example:** |
| 89 | +```python |
| 90 | +ua_text_center(oled, "УКРАЇНА", 28) |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +### ua_text_scaled(display, text, x, y, scale=2, color=1, bg_color=0, clear_bg=False) |
| 96 | + |
| 97 | +Render text with scaling (2x, 3x, etc.). |
| 98 | + |
| 99 | +**Parameters:** |
| 100 | +- `display` - Display object |
| 101 | +- `text` - String to render |
| 102 | +- `x` - X coordinate (left edge) |
| 103 | +- `y` - Y coordinate (top edge) |
| 104 | +- `scale` - Scaling factor (1=normal, 2=double, etc.) |
| 105 | +- `color` - Foreground color (default: 1) |
| 106 | +- `bg_color` - Background color (default: 0) |
| 107 | +- `clear_bg` - Clear background (default: False) |
| 108 | + |
| 109 | +**Returns:** Total width of rendered text in pixels |
| 110 | + |
| 111 | +**Example:** |
| 112 | +```python |
| 113 | +ua_text_scaled(oled, "ПРИВІТ", 0, 0, scale=2) |
| 114 | +``` |
| 115 | + |
| 116 | +## Supported Characters |
| 117 | + |
| 118 | +- **Ukrainian Alphabet**: А Б В Г Ґ Д Е Є Ж З И І Ї Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ь Ю Я (uppercase and lowercase) |
| 119 | +- **English Alphabet**: A-Z, a-z |
| 120 | +- **Numbers**: 0-9 |
| 121 | +- **Symbols**: Common punctuation and special characters |
| 122 | + |
| 123 | +## Display Requirements |
| 124 | + |
| 125 | +The library works with any display object that implements: |
| 126 | + |
| 127 | +- `pixel(x, y, color)` - Set individual pixel (required) |
| 128 | +- `show()` - Update display (optional, for buffered displays) |
| 129 | +- `fill_rect(x, y, width, height, color)` - Fill rectangle (optional, for optimization) |
| 130 | + |
| 131 | +## Compatibility |
| 132 | + |
| 133 | +**Tested with:** |
| 134 | +- ESP32 with MicroPython v1.19+ |
| 135 | +- SSD1306 OLED displays (128x64, 128x32) via I2C/SPI |
| 136 | + |
| 137 | +**Compatible with:** |
| 138 | +- Any MicroPython-compatible board |
| 139 | +- Any display supporting the `pixel()` method |
| 140 | + |
| 141 | +## Examples |
| 142 | + |
| 143 | +### Multi-line Text |
| 144 | + |
| 145 | +```python |
| 146 | +oled.fill(0) |
| 147 | +ua_text(oled, "Рядок 1", 0, 0) |
| 148 | +ua_text(oled, "Рядок 2", 0, 10) |
| 149 | +ua_text(oled, "Рядок 3", 0, 20) |
| 150 | +oled.show() |
| 151 | +``` |
| 152 | + |
| 153 | +### Scaled Text |
| 154 | + |
| 155 | +```python |
| 156 | +oled.fill(0) |
| 157 | +ua_text_scaled(oled, "ВЕЛИКИЙ", 0, 0, scale=2) |
| 158 | +oled.show() |
| 159 | +``` |
| 160 | + |
| 161 | +### Centered Text |
| 162 | + |
| 163 | +```python |
| 164 | +oled.fill(0) |
| 165 | +ua_text_center(oled, "УКРАЇНА", 10) |
| 166 | +ua_text_center(oled, "2026", 28) |
| 167 | +oled.show() |
| 168 | +``` |
| 169 | + |
| 170 | +## License |
| 171 | + |
| 172 | +MIT License |
| 173 | + |
| 174 | +## Documentation |
| 175 | + |
| 176 | +For complete documentation, examples, and troubleshooting, visit: |
| 177 | + |
| 178 | +**https://github.com/BrainFromUkraine/bfu_ua_display** |
| 179 | + |
| 180 | +## Author |
| 181 | + |
| 182 | +BFU Electronics |
0 commit comments