OLED_I2C: an example that runs
Yes. You can use the OLED_I2C library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (OLED display, 128x64). The example below, "Text, a number and a frame on an OLED with OLED_I2C", runs on the Arduino Uno R3.
Built in on Mokxi: #include <OLED_I2C.h> and it builds, with nothing to install. Free, and no account needed.
What OLED_I2C does
An SSD1306 OLED drawn in a frame buffer: begin(SSD1306_128X64), setFont(SmallFont), print(), printNumI(), printNumF(), drawBitmap(), drawLine(), drawRect(), drawCircle(), invert() and update(). That is what OLED_I2C, by Henning Karlsen (Rinky-Dink Electronics), covers. The sketch below uses it on the Arduino Uno: “Text, a number and a frame on an OLED with OLED_I2C”.
The OLED_I2C library's interface (Henning Karlsen, Rinky-Dink Electronics), text, numbers, bitmaps and shapes on an SSD1306 OLED over I2C, drawn in a frame buffer and sent with update().
Drawing changes the buffer only, as upstream; update() sends it.
The calls follow release 2.21 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | OLED_I2C |
|---|---|
| Author | Henning Karlsen (Rinky-Dink Electronics) |
| Include | #include <OLED_I2C.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | OLED display, 128x64, OLED display, 128x32 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <OLED_I2C.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "OLED_I2C" by Henning Karlsen (Rinky-Dink Electronics) from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add OLED_I2C to lib_deps in PlatformIO. Mokxi follows the calls of release 2.21, so a sketch written here builds there too.
What to know in the simulator: The two pins can be any two here; upstream wants the board's I2C pins on most boards. The fonts are Mokxi's own drawings in the library's font format.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
OLED myOLED(2, 3)
Makes myOLED, the OLED object the calls below are made on.
myOLED.begin(SSD1306_128X64)
Starts it up and returns true if it started, false if it did not. Call it once in setup(). Arguments: model.
myOLED.setFont(SmallFont)
Sets the font to the value you pass in.
myOLED.print("OLED_I2C", CENTER, 0)
Prints it.
myOLED.drawRect(0, 16, 127, 47)
Draws the rect.
myOLED.update()
Sends what has been drawn to the screen. Nothing appears until you call it.
Example: Text, a number and a frame on an OLED with OLED_I2C
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <OLED_I2C.h>
OLED myOLED(2, 3); // SDA, SCL
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
void setup() {
Serial.begin(9600);
if (!myOLED.begin(SSD1306_128X64)) {
Serial.println("no OLED");
while (1);
}
myOLED.setFont(SmallFont);
myOLED.print("OLED_I2C", CENTER, 0);
myOLED.setFont(MediumNumbers);
myOLED.printNumI(2026, CENTER, 24);
myOLED.drawRect(0, 16, 127, 47);
myOLED.update();
Serial.println("updated");
}
void loop() {}Wiring
- Arduino Uno R3 2 to OLED display, 128x64 SDA
- Arduino Uno R3 3 to OLED display, 128x64 SCL
- Arduino Uno R3 5V to OLED display, 128x64 VCC
- Arduino Uno R3 GND to OLED display, 128x64 GND
Try OLED_I2C without installing anything
Open the example, change the sketch, and keep your version in a free account.