ESP-IDF Development Basics
reTerminal Sticky is an e-paper information display designed to keep weather, schedules, notes, and lightweight data visible over long periods. With ESP-IDF, you can use its e-paper display, touchscreen, physical buttons, and onboard peripherals to build your own always-visible information pages.
This guide walks you through running the Comprehensive Development Demo (Sticky_dashboard_demo), exploring the project structure, and adding a custom page. The next two guides cover onboard peripherals, display refresh, and deep sleep.
Flashing the example project replaces the firmware currently running on Sticky. Make sure the device does not contain anything you need to keep before continuing.
Share Your Project
If you have built a project with reTerminal Sticky, we would love for you to contribute it to Sticky Playground and share your ideas with the community. We appreciate every developer who helps make the Playground better.
Follow the contribution guide in the repository README, prepare your project, and submit a Pull Request. Once your project has been reviewed and published, other users can install and try it through Sticky Playground.
Development Environment
Before you begin, prepare the following:
- reTerminal Sticky
- A USB-C cable that supports data transfer
- A Windows, Linux, or macOS computer
- ESP-IDF v5.4
Sticky_dashboard_demo was developed and tested on hardware with ESP-IDF v5.4. If ESP-IDF is not installed yet, follow Espressif’s ESP32-S3 ESP-IDF v5.4 Getting Started Guide to install it first.
After installation, run the following command in an ESP-IDF terminal:
idf.py --version
The output should include:
ESP-IDF v5.4
A charge-only USB-C cable can power Sticky, but the computer cannot detect its serial port through that cable. If the device charges but no serial port appears, try a cable that supports data transfer.
The main Sticky development resources used in the Demo are listed below:
| Hardware | Use in the Demo |
|---|---|
| 3.97-inch, 800 × 480 four-level grayscale e-paper display | Draw and retain page content over long periods |
| Capacitive touchscreen | Detect left and right swipes |
| UP, DOWN, and AI buttons | Change pages, refresh, and enter Deep Sleep |
| SHT40, RTC, battery gauge, and IMU | Provide environmental, time, battery, and orientation data |
| MicroSD and PDM microphone | Read text and capture audio |
| Buzzer | Provide operation feedback |
For complete specifications and hardware relationships, read the Hardware Overview first.
Run the Demo
Both ESP-IDF examples are under examples/esp-idf/ in the OSHW-reTerminal-Sticky repository.
| Example | Project directory | Use it to |
|---|---|---|
| Dashboard Demo | examples/esp-idf/dashboard | Follow this series on page development, peripheral integration, e-paper refresh, and low-power operation |
| Peripheral Examples | examples/esp-idf/peripherals | Test individual onboard peripherals or use the examples as a reference |
Clone the repository and open its root directory:
git clone https://github.com/Seeed-Projects/OSHW-reTerminal-Sticky.git
cd OSHW-reTerminal-Sticky
To follow this series, enter the Dashboard project directory:
cd examples/esp-idf/dashboard
To run the peripheral examples, enter this directory from the repository root:
cd examples/esp-idf/peripherals
Both projects load shared components from examples/esp-idf/components/.
Open an ESP-IDF v5.4 terminal in the directory containing the top-level CMakeLists.txt. Set the target chip before the first build:
idf.py set-target esp32s3
Build the project:
idf.py build
After the build succeeds, connect Sticky with a USB-C data cable. Replace PORT with the device serial port (for example, COM5 on Windows), then flash the firmware and open the serial monitor:
idf.py -p PORT flash monitor
Linux usually uses /dev/ttyUSB0 or /dev/ttyACM0. macOS usually uses /dev/cu.usbserial-* or /dev/cu.usbmodem-*. Press Ctrl+] to exit the serial monitor.
After startup, the serial output includes:
I (...) sticky_dashboard: Starting reTerminal Sticky Dashboard Demo
The Home page appears after the first screen refresh. Use the UP/DOWN buttons or swipe left and right to view the pages in sequence:
Home -> Sensor -> Battery -> Note -> IMU -> Microphone -> Home
The same firmware automatically detects SSD1677 or SSD2677; no manual controller selection is needed.
Home demonstrates four-level grayscale and does not display RTC time. The other five pages use monochrome images and show RTC time in the status bar.
A full e-paper refresh completes a full pixel update. When it finishes, the new content remains stable on the screen.
Project Structure
Sticky_dashboard_demo separates hardware access, application logic, and page rendering:
examples/esp-idf/
|-- components/ Shared driver components
|-- peripherals/
`-- dashboard/
|-- CMakeLists.txt
`-- main/
|-- main.cpp Initialization and main event loop
|-- pin_config.h Pins and device addresses
|-- board/ Power, GPIO, and shared buses
|-- devices/ Onboard peripheral access
|-- app/ State, data, events, and page navigation
|-- pages/ Page rendering
`-- ui/ Canvas, fonts, and shared status bar
When a page displays hardware data, the data follows this path:
Hardware
↓
devices Read the device
↓
app_data Update application data
↓
AppState Store page state
↓
pages Render the page
↓
Canvas Produce the complete image
↓
display Refresh the e-paper display
Each directory has a clear responsibility:
| Directory | Responsibility |
|---|---|
board/ | Initialize board-level power and buses shared by multiple devices |
devices/ | Initialize, read, or control specific hardware |
app/ | Store state, update data, process events, and select pages |
pages/ | Render pages from AppState |
ui/ | Provide Canvas, fonts, and the shared status bar |
This structure keeps hardware communication, data processing, and page rendering separate. When adding a feature, you usually only need to connect its data source, extend AppState, and create a page. You do not need to rebuild the existing display, input, or refresh framework.
Page rendering and screen refresh
A page Renderer (the page rendering function) only writes content to Canvas. After rendering, the App layer refreshes the e-paper display:
render_current_page(canvas, state);
ESP_RETURN_ON_ERROR(
refresh_current_page(state), "app", "refresh current page");
refresh_current_page() selects the refresh method from state.current_page: Home uses a four-level grayscale full refresh, while the other pages use a monochrome full refresh. Page files therefore only draw to Canvas. The existing Device and App flow handles Display initialization and refresh.
Canvas uses 800 × 480 landscape logical coordinates with the origin at the top-left corner. Screen rotation is handled by sticky_display, so pages do not need to transform coordinates again.
The display adapter uses examples/esp-idf/components/seeed_epaper to handle controller differences; the Demo App layer manages pages and refresh policy. Separate APIs provide grayscale full, monochrome full, and monochrome partial refreshes, covered in the third guide.
Data Flow and Page Display
The Sensor page shows a complete data path: the SHT40 reads temperature and humidity, the application stores the data, and the page displays the result.
SHT40
↓
sticky_sht40_read()
↓
update_environment()
↓
AppState.environment
↓
sensor_page_render()
↓
Canvas
Read the sensor
main/devices/sticky_sht40.* wraps SHT40 hardware access. During initialization, it uses the sensor I2C bus already created by the Board layer:
ESP_ERROR_CHECK(board_init());
ESP_ERROR_CHECK(sticky_sht40_init(board_sensor_i2c_bus()));
The RTC, battery gauge, and IMU also use this shared bus, so a separate I2C bus does not need to be created for each device.
Update application state
EnvironmentState in main/app/app_state.h stores the temperature, humidity, and read status needed by the page:
struct EnvironmentState {
float temperature_c = 0.0F;
float humidity_percent = 0.0F;
bool valid = false;
esp_err_t error = ESP_ERR_INVALID_STATE;
};
main/app/app_data.cpp calls the Device API and writes the result to AppState. The core relationship is:
Sht40Reading reading = {};
const esp_err_t result = sticky_sht40_read(reading);
state.environment.error = result;
state.environment.valid = result == ESP_OK;
After a successful read, the function also stores the temperature and humidity. If the read fails, valid remains false, while the error code and serial log help identify the problem.
Render sensor data
main/pages/sensor_page.cpp only reads the state. It displays the temperature when the data is valid, or N/A in the same position if the read failed:
canvas.draw_text(76, 235, "Temperature:", 3, GrayLevel::Black);
if (state.environment.valid) {
std::snprintf(value, sizeof(value), "%.1f C",
static_cast<double>(state.environment.temperature_c));
canvas.draw_text(500, 235, value, 3, GrayLevel::Black);
} else {
canvas.draw_text(500, 235, "N/A", 3, GrayLevel::Black);
}
When the Sensor page opens, the App layer updates the data, renders the page, and refreshes the screen in sequence. The page does not read the SHT40 directly.
This path applies to most data pages: first identify the data source, then pass the data to the page through AppState. The second Wiki guide uses Battery, MicroSD, IMU, and Microphone to show different types of peripheral data.
The complete Dashboard attaches SHT40 after Board and before Display so the display can read external temperature at startup, falling back to internal temperature if unavailable. This is not a per-frame measurement. A failed SHT40 command is retried once after a delay without resetting shared I2C. The Sensor page uses monochrome full refresh.
Add the Hello Page
Start from the six-page main in the organization repository and add Hello in the five steps below. The page displays fixed text and reuses the existing layout, input, and refresh flow. No branch switch is needed.
After the change, the page order becomes:
Home -> Sensor -> Battery -> Note -> IMU -> Microphone -> Hello -> Home
Step 1: Create the page files
Create main/pages/hello_page.h with the following complete contents:
#pragma once
class Canvas;
struct AppState;
void hello_page_render(Canvas &canvas, const AppState &state);
Create main/pages/hello_page.cpp with the following complete contents:
#include "hello_page.h"
#include "app_state.h"
#include "canvas.h"
#include "page.h"
void hello_page_render(Canvas &canvas, const AppState &state)
{
page_draw_layout(canvas, state, "Hello Sticky", "My First Page");
canvas.draw_text(76, 250, "ESP-IDF Ready", 3, GrayLevel::Black);
canvas.draw_line(76, 310, 718, 310, GrayLevel::Black);
}
page_draw_layout() draws the same border, status bar, and title used by the other monochrome pages. The Hello page only needs to add its own content.
The Demo defines only Home as a four-level grayscale page, so the new Hello page automatically uses a monochrome full refresh. Use GrayLevel::Black and GrayLevel::White for a regular new page. If a page needs four-level grayscale, also add its PageId to page_uses_gray4().
Step 2: Add the page ID
In main/app/app_state.h, replace the PageId enum with this complete definition. Append Hello to preserve existing page IDs:
enum class PageId {
Home,
Sensor,
Battery,
Note,
Imu,
Microphone,
Hello,
};
Hello displays fixed text, so no new AppState data members or changes to app_data.cpp are needed. Appending this enum value preserves existing IDs, the state layout, and field meanings, so kSavedStateMagic can remain unchanged for this extension. Reassess compatibility if you later change the saved layout or the meaning of page IDs.
Step 3: Register the page
In main/app/app.cpp, add this include beside the existing page headers:
#include "hello_page.h"
In the switch inside page_name(), add this case after the existing Microphone case:
case PageId::Hello:
return "Hello";
In the switch inside render_current_page(), add this case after the existing Microphone case:
case PageId::Hello:
renderer = hello_page_render;
break;
Step 4: Add the page to navigation
Continue in main/app/app.cpp. In the switch inside select_next_page(), replace the existing Microphone case with the following excerpt, which also adds the Hello case. Leave the other cases unchanged:
case PageId::Microphone:
state.current_page = PageId::Hello;
break;
case PageId::Hello:
state.current_page = PageId::Home;
break;
In the switch inside select_previous_page(), replace the existing Home case with the following excerpt, which also adds the Hello case. Keep the existing Microphone → Imu case and all other cases; do not add duplicate Home or Microphone cases:
case PageId::Home:
state.current_page = PageId::Hello;
break;
case PageId::Hello:
state.current_page = PageId::Microphone;
break;
In restore_app_state_after_deep_sleep() in the same file, replace the existing page-range check with this excerpt so Hello can be restored after sleep:
if (restored.current_page < PageId::Home ||
restored.current_page > PageId::Hello) {
return false;
}
The original upper limit is PageId::Microphone. Change only that limit to PageId::Hello; retain the version, length, checksum, and remaining restore logic.
Step 5: Add the page to the build system
In SRCS in main/CMakeLists.txt, add one line immediately after "pages/home_page.cpp". The excerpt below shows that location; leave the remaining sources and INCLUDE_DIRS unchanged:
# Page framework
"pages/page.cpp"
"pages/home_page.cpp"
"pages/hello_page.cpp"
Hello uses the existing monochrome full refresh. The shared layout draws the RTC status bar, and minute events keep its time updated. Buttons, touch, AI refresh, and sleep reuse the existing event handling; no Hello-specific event or change to page_uses_gray4() is needed.
Save the changes, then build and flash the project again:
idf.py build
idf.py -p PORT flash monitor
When you open the Hello page, the screen should show My First Page and ESP-IDF Ready.
Check the following, waiting for each refresh to finish before continuing:
- Use DOWN or swipe left to confirm
Microphone → Hello → Home. - Use UP or swipe right to confirm
Home → Hello → Microphone, then check the complete page loop in both directions. - Short-press AI on Hello. Confirm that it redraws and the log shows
Hello displayed: mono full. - Stay on Hello until the next minute. Confirm that the status bar time changes and the log includes
RTC updated:. - Hold AI on Hello for about two seconds and release it after the beep. Once asleep, press AI again and confirm that Hello is restored. See Refresh and Low Power for the sleep flow.
- Return from Hello to Home and check black, dark gray, light gray, and white.
At this point, you have completed the full page integration process:
Create page files
↓
Add PageId
↓
Register the Renderer
↓
Add bidirectional navigation and the restore range
↓
Update CMakeLists.txt
↓
Build and verify on the device
Application Extension Workflow
Use the following sequence when creating a new information page:
- Identify the data the page needs and check whether the project already provides a corresponding Device API.
- If no API is available, add hardware access under
devices/. Otherwise, reuse the existing API. - Store the page data, validity state, and error code in
AppState. - Read the data and update the state in
app_data. - Create a Page Renderer, then add the page to
PageId, page routing, and the navigation order. - Add the new
.cppfile tomain/CMakeLists.txt, build the project, and verify both the display and error states on the device.
Keep these module responsibilities separate when extending the application:
- Pages only read
AppStateand draw to Canvas. They do not access hardware directly. - Device modules only handle hardware access. They do not draw UI.
- Shared buses and power resources are managed by the Board layer.
- After a page is rendered, the App layer refreshes the e-paper display.
FAQ
-
The new page causes an
undefined referenceerrorThe page
.cppfile is missing frommain/CMakeLists.txt, or the function declaration does not match its implementation. Confirm that the source file is included inSRCS, then check the function name and parameters before rebuilding. -
The new page builds but cannot be opened
Adding only a
PageIdor Renderer is not enough. Confirm that the page is registered inrender_current_page()and that itsPageIdis included in both forward and reverse navigation. -
Page content has the wrong orientation on the device
Pages should always use the 800 × 480 logical coordinate system with the origin at the top left. The Display layer handles the 180° rotation required by the physical screen, so do not rotate coordinates again in a Page Renderer.
-
Page text is displayed as
?The built-in bitmap font supports printable ASCII. Unsupported characters, such as Chinese characters and
℃, are displayed as?. Add the required glyphs or use characters already supported by the font. -
The project fails to build after moving to another computer
The
build/directory contains paths and configuration generated on the original computer. Confirm that ESP-IDF v5.4 and the ESP32-S3 target are selected. If the error remains, delete only the generatedbuild/directory and rebuild the project.
Next Step
This guide covered two basic development paths:
Page integration: Page files -> PageId -> Renderer -> Page navigation -> CMake
Data display: Device -> app_data -> AppState -> Page -> Canvas -> Display
The next guide continues with the same Demo and explains:
- Reading Battery, MicroSD, IMU, and Microphone data and displaying it on pages
- How Button and Touch trigger page changes and refreshes through
AppEvent - How different peripherals reuse shared resources managed by the Board layer
Continue with ESP-IDF Pages and Peripherals.