Proje Defteri

OLED Simulator for SSD1306 and U8g2

Paste Arduino code for an SSD1306, SH1106 or any U8g2 display and see the screen as you type. Loops, functions and delay() animations run too. Nothing to compile or install, it all runs in your browser.

    The screen redraws half a second after you stop typing. Paste a whole sketch or just a few drawing lines; a missing display object is created for you.

    Preview OLED screens without uploading

    Designing a screen for a 0.96 inch OLED usually means a loop of edit, compile, upload and squint: is the text two pixels too low, does the number still fit when it reaches four digits, is the icon centred? This simulator cuts that loop down to typing. It reads the display code from your sketch and draws the result on a pixel-accurate 128x64 screen, the same size as the SSD1306 modules sold for Arduino and ESP32.

    How it works

    1. Pick an example or paste your own sketch. A complete program with setup() and loop() works, and so do a few loose drawing lines.
    2. The simulator finds the display declaration, for example Adafruit_SSD1306 display(128, 64, &Wire, -1); or U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);, and takes the screen size from it.
    3. It runs setup() once and then loop(), and records a frame every time display(), sendBuffer() or nextPage() sends the buffer.
    4. delay() advances a virtual clock, so animations play back at their real speed. Each display() call counts about 25 ms, roughly what a 128x64 frame takes over 400 kHz I2C.
    5. Errors and warnings show up under the screen with a line number; click it to jump to that line.

    What is supported

    AreaSupported
    Adafruit GFXdrawPixel, drawLine, drawFastHLine/VLine, drawRect, fillRect, drawRoundRect, fillRoundRect, drawCircle, fillCircle, drawTriangle, fillTriangle, drawBitmap, drawXBitmap, fillScreen, setCursor, setTextSize, setTextColor (with background), setTextWrap, print, println, write, getTextBounds, setRotation, invertDisplay, cp437
    U8g2clearBuffer, sendBuffer, firstPage/nextPage, drawPixel, drawLine, drawHLine/VLine, drawFrame, drawBox, drawRFrame, drawRBox, drawCircle, drawDisc, drawEllipse, drawTriangle, drawXBM/XBMP, drawBitmap, drawStr, drawUTF8, print, setDrawColor (incl. XOR), setFontPos*, U8G2_R0..R3
    C++ languagevariables, arrays (also 2D and PROGMEM), #define, if/else, for, while, do, switch, your own functions, sprintf, dtostrf, String(), millis(), random(), map(), math functions
    SensorsDHT and DallasTemperature calls return sample values so dashboards have something to show; analogRead() returns a slowly changing value

    Adafruit GFX output is pixel exact: the drawing routines follow the order of the library's own source, and text uses the same 5x7 classic font. U8g2 shapes are exact too, but U8g2 fonts are not bundled; text drawn with them is approximated with the 5x7 font at a similar height. For real U8g2 font sizes, see the U8g2 font list. Custom GFX fonts (setFont(&FreeSans9pt7b)) fall back to the classic font, which you can turn into a custom one with the Adafruit GFX font converter.

    Why not just use Wokwi?

    Wokwi emulates the whole microcontroller, so it compiles your sketch, runs every library and simulates the wiring. That is the right tool when you need to test sensors, interrupts or the circuit itself. When the question is only "what will the screen look like", a full compile is slow: here the preview updates as you type and also accepts a few loose drawing lines that would not compile on their own. Use this page to design the screen, then test the finished sketch on Wokwi or real hardware.

    Images and animations

    drawBitmap() expects one bit per pixel, eight pixels per byte, most significant bit on the left. The OLED bitmap generator draws icons in exactly that format, and image2cpp converts a photo or logo. Paste the array above setup() and the simulator draws it. For a GIF, the GIF to OLED animation tool creates the frame arrays and the playback loop.

    Common problems the simulator points out

    Nothing on the screen. Adafruit_SSD1306 draws into a 1024-byte buffer in RAM. Until display.display() runs, the panel shows nothing new; the message list warns when that call is missing. With U8g2 the call is sendBuffer().

    The Adafruit logo flashes at startup. begin() fills the buffer with the Adafruit splash logo. If you call display() before clearDisplay(), the logo appears on the real screen. The simulator flags this order.

    Strange symbols instead of °, ü or é. Arduino stores those characters as two or three UTF-8 bytes, and the classic font prints one symbol per byte. The degree sign is display.write(247), or 248 after display.cp437(true).

    It works here but not on the board. Check the I2C address (0x3C on most modules, sometimes 0x3D), the wiring and the free RAM: on an Uno the 1024-byte buffer of a 128x64 screen takes half of the 2 KB. An SH1106 module (often sold as 1.3 inch) driven by the SSD1306 library shows a column of noise, because its controller has 132 columns; use Adafruit_SH1106G or a U8G2_SH1106 class. The Arduino OLED SSD1306 guide covers wiring step by step.

    Using a character LCD instead? The LCD simulator runs LiquidCrystal and LiquidCrystal_I2C code for 16x2 and 20x4 displays.

    Frequently Asked Questions

    How do I simulate an SSD1306 OLED without hardware?

    Paste your sketch into the editor on this page. The simulator reads the Adafruit_SSD1306 or U8G2 declaration to get the screen size, runs setup() and loop(), and draws every display() or sendBuffer() call on the virtual screen. Animations play back with the timing of your delay() calls. There is nothing to install and no account.

    How is this different from Wokwi?

    Wokwi compiles the whole sketch and emulates the microcontroller, which is the right tool for testing wiring, sensors and timing. This simulator interprets only the display part of the code, so the screen updates about half a second after you stop typing, with no compile step. It is meant for laying out screens: text positions, font sizes, icons and menus.

    Why is my OLED blank even though the code compiles?

    The most common cause is a missing display.display() call. Adafruit_SSD1306 draws into a 1024-byte buffer in RAM, and nothing reaches the screen until display() sends it. With U8g2 the same job is done by sendBuffer(). Other causes are a wrong I2C address (0x3C on most modules, sometimes 0x3D), begin() failing because the board ran out of RAM, or an SH1106 module driven with the SSD1306 library.

    Does it support U8g2 fonts?

    U8g2 drawing functions are simulated exactly, but the hundreds of U8g2 fonts are not bundled. Text drawn with setFont() is approximated with the 5x7 font scaled to a similar height, so the position is right but the glyph shapes and widths are estimates. Adafruit GFX text with the built-in font is pixel exact.

    Can I simulate a 128x32 or SH1106 display?

    Yes. The size comes from your code: Adafruit_SSD1306 display(128, 32, &Wire, -1) gives a 128x32 screen, and a U8G2 class name such as U8G2_SH1106_128X64_NONAME_F_HW_I2C gives 128x64. If the code has no declaration, the size selector is used. 128x64, 128x32, 64x48, 72x40, 96x16, 64x32 and 128x128 are available.

    Is my code uploaded anywhere?

    No. The code is interpreted by JavaScript in your browser and never leaves it. It is autosaved in this browser's local storage, and the share link carries the code inside the link itself, so nothing is stored on a server.