
How it works
This program joins ESP-IDF's I2C master driver to the u8g2 graphics library. A small hardware layer hands u8g2's byte stream to I2C port 0 on GPIO4 (SCL) and GPIO5 (SDA) at 400 kHz, with the internal pull-ups enabled, and addresses the SSD1306 controller at 0x3C. u8g2 draws into a frame buffer in RAM and sends the whole buffer to the 128×64 panel when a picture is complete.
The demo runs its scenes in a loop: text, geometric shapes, pixel operations, a progress bar, a bouncing-ball animation, a bitmap, then a screen with the cycle number. Text, shapes, pixel operations and the bitmap each hold for 3 s. The cycle-number screen holds for 2 s. The program waits 200 ms between progress-bar updates and 80 ms between animation frames. At the start of each round the program logs Demo cycle and the next number. The display runs from 3V3 and the S31 from a 5 V battery on SIM VIN.
What to watch
Enable verbose in Serial to see each DEMO line, starting with DEMO: Text Display. Enable verbose to see the configuration lines, which report the SDA and SCL pins, the 400000 Hz bus clock and the display address.
What's on the bench
- Battery
- ESP32-S31 (development source)
- OLED 128×64
How it's wired
- Battery · pos→ESP32-S31 (development source) · vin
- Battery · neg→ESP32-S31 (development source) · gnd
- ESP32-S31 (development source) · 3v3→OLED 128×64 · vcc
- ESP32-S31 (development source) · gnd→OLED 128×64 · gnd
- ESP32-S31 (development source) · g4→OLED 128×64 · scl
- ESP32-S31 (development source) · g5→OLED 128×64 · sda
This project runs prebuilt firmware on the emulated board; open it in the simulator to watch it work and inspect every part live.
Try this
- Compare the Serial timestamps for DEMO: Text Display and DEMO: Geometric Shapes. The gap includes the 3 s hold and the time it takes to draw and send the text screen.
- Watch the last screen of each round: it shows the cycle number, and the same number appears in the Demo cycle line in Serial.
- Open the MPU-6050 identity example next. It uses the same two pins and pull-ups to read a sensor at a different address.



