Hardware Configuration
| Property | Value |
|---|---|
| Display Type | SSD1306 OLED |
| Resolution | 128x64 pixels |
| Interface | I2C (Hardware) |
| Rotation | U8G2_R0 (0 degrees) |
| I2C Address | 0x3C (shifted left by 1 for U8G2) |
| Contrast | 255 (maximum) |
Display Layout
The display uses a grid system where U8G2 breaks the 128x64 pixel screen into 8x8 pixel cells:- Grid Size: 8 cells tall × 16 cells wide
- Cell Origin: (0,0) at top-left corner
- Cell Dimensions: 8×8 pixels each
Display layout showing header, page area, and footer regions
Layout Regions
Header Row (Row 0)
Header Row (Row 0)
- Cells 0-12: Header text (13 cells = 104 pixels)
- Cells 13-15: State icons (3 cells = 24 pixels)
- WiFi status
- Bluetooth status
- Other system indicators
Page Area (Rows 1-6)
Page Area (Rows 1-6)
- 6 rows of main content
- 16 cells wide (128 pixels)
- 48 pixels tall (6 × 8 pixels)
- Content clips to this area when you use
clearPage()
Footer Row (Row 7)
Footer Row (Row 7)
Thread Safety
The display uses a FreeRTOS mutex to ensure thread-safe access from multiple tasks.display_mutex.h
Basic Usage Pattern
example_usage.cpp
Initialization
CallinitDisplay() at startup to initialize the display service:
- Creates the display mutex
- Initializes the U8G2 display object
- Sets the I2C address and display parameters
- Clears the display buffer
Clearing Functions
Use clearing functions to efficiently update specific display regions. All clearing functions useupdateDisplayArea() for partial updates.
| Function | Description | Area Cleared |
|---|---|---|
clearHeader() | Clears header text area | Cells 0-12, row 0 (preserves icons) |
clearIcons() | Clears icon area | Cells 13-15, row 0 (preserves header) |
clearFooter() | Clears footer text area | Cells 0-14, row 7 (preserves timeout) |
clearTimeout() | Clears timeout indicator | Cell 15, row 7 |
clearPage() | Clears main content area | Rows 1-6 |
clearPage() Parameters
clearPage() sets a clipping window to prevent content from overflowing into the header or footer areas.Refresh Functions
Refresh functions update specific display regions after you modify them:| Function | Description | Area Updated |
|---|---|---|
refreshHeader() | Updates header text | Cells 3-15, row 0 |
refreshIcons() | Updates icon area | Cells 0-2, row 0 |
refreshFooter() | Updates footer area | Cells 1-15, row 0 |
refreshPage() | Updates main content | Rows 1-6 |
refreshTimeout() | Updates timeout indicator | Timeout cell |
refreshPage() Parameters
Content Functions
setHeader()
Sets the header text, automatically converting to uppercase:setFooter()
Sets left and right footer text with automatic alignment:- Left text aligns to the left edge
- Right text aligns to the right edge
- Both texts convert to uppercase automatically
- Text caching prevents unnecessary redraws
drawWrappedText()
Draws text with automatic word wrapping:x,y: Starting positiontext: Text to draw (supports literal\nfor line breaks)center: Enable center alignment
Drawing Guidelines
1
Always use mutex protection
Wrap all drawing operations in a mutex lock:
2
Use provided clearing functions
Prefer the clearing functions over manual buffer clearing:
3
Respect layout boundaries
Keep content within designated areas:
- Header content: cells 0-12
- Footer content: cells 0-14
- Icons: cells 13-15
- Use
clearPage()to prevent content overflow
4
Select appropriate fonts
| Area | Recommended Font |
|---|---|
| Header/Footer | u8g2_font_spleen5x8_mu |
| Page content | Choose based on readability needs |
Consider font height when calculating vertical spacing between lines.
Common Patterns
Drawing a Complete Screen
draw_screen.cpp
This pattern clears the page area, draws new content, and refreshes only the affected region.
Updating Header Only
update_header.cpp
Drawing Wrapped Text
wrapped_text.cpp
Performance Considerations
- Partial updates:
updateDisplayArea()only refreshes specific regions - Text caching: Reduces redundant drawing operations
- Clipping windows: Prevents unnecessary buffer operations
- Atomic operations: Mutex ensures drawing operations complete without interruption
Memory Management
- U8G2 library manages the display buffer
- Text caching prevents unnecessary redraws
- PROGMEM stores constant strings (following project guidelines)
Dependencies
| Dependency | Purpose |
|---|---|
| U8G2 Library | Core display functionality |
| FreeRTOS | Mutex for thread safety |
| ESP32 | Hardware I2C interface |
| Pins.h | Hardware pin definitions |

