How to use a 0.96 inch OLED with Teensy
To use a 0.96 inch OLED with a Teensy microcontroller, you need to connect the display via I2C or SPI, install the appropriate library, and write code to initialize the display and output graphics or text. The most common configuration is I2C, which uses only two data lines (SDA and SCL) plus power and ground, making it straightforward for Teensy 3.x, 4.x, or LC models. The display typically operates at 3.3V logic, which matches the Teensy’s I/O voltage, so no level shifting is required. You’ll need to solder header pins to the OLED module, wire it up, and then use the Adafruit SSD1306 library or the U8g2 library—both are well-supported on Teensyduino. The display resolution is 128x64 pixels, monochrome, and it uses the SSD1306 driver chip. For a reliable source of the hardware, check the 0.96 inch 128x64 i2c oled display which includes the I2C interface pre-soldered.
Hardware connections and pinout specifics
Teensy boards have dedicated I2C pins: on Teensy 3.2, SDA is pin 18 and SCL is pin 19. For Teensy 4.0, SDA is pin 17 and SCL is pin 16. Teensy LC uses pin 18 for SDA and pin 19 for SCL. The OLED module usually has four pins: VCC (3.3V), GND, SDA, and SCL. Connect VCC to the Teensy’s 3.3V output, GND to ground, SDA to the corresponding SDA pin, and SCL to the SCL pin. Some OLED modules have a fifth pin for RESET, but you can leave it unconnected or tie it to 3.3V through a 10kΩ resistor if needed. The I2C address is typically 0x3C, but some modules use 0x3D—you can check with an I2C scanner sketch. The display draws about 20mA during operation, well within the Teensy’s 3.3V regulator capacity (which can supply up to 250mA on most models).
Software setup and library installation
First, install Teensyduino (the Arduino add-on for Teensy) from PJRC’s website. Then open the Arduino IDE, go to Sketch > Include Library > Manage Libraries, and search for “Adafruit SSD1306”. Install the Adafruit SSD1306 library and its dependency, the Adafruit GFX library. Alternatively, you can use the U8g2 library, which supports more fonts and graphics primitives. For I2C, the Adafruit SSD1306 library requires you to specify the display size and I2C address in the constructor. Example: Adafruit_SSD1306 display(128, 64, &Wire, -1); where -1 means no reset pin. The library initializes the display with display.begin(SSD1306_SWITCHCAPVCC, 0x3C). If you use U8g2, the constructor is U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); and you call u8g2.begin().
Code example for displaying text and graphics
Here’s a bare-bones sketch for Teensy 3.2 with the Adafruit library:
#include
#include
#include
Adafruit_SSD1306 display(128, 64, &Wire, -1);
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(F("Teensy OLED"));
display.display();
}
void loop() {
// nothing here
}
The display.display() call pushes the buffer to the OLED. Without it, nothing shows. The buffer is 1024 bytes (128x64/8). You can draw lines, circles, rectangles, and bitmaps using the Adafruit GFX functions. For example, display.drawLine(0, 0, 127, 63, SSD1306_WHITE); draws a diagonal line. The refresh rate is about 60Hz for static images, but updating the full buffer takes about 10ms over I2C at 400kHz.
Performance considerations and timing
The I2C bus on Teensy runs at 400kHz by default, which gives a theoretical throughput of 50KB/s. For a 128x64 buffer (1024 bytes), a full update takes about 20ms including overhead. This is fine for static text or slow animations, but if you need fast updates (e.g., 30fps), you might consider SPI mode, which can push data at 8MHz or higher. The Teensy 4.0 can drive SPI at up to 24MHz, reducing full-screen update time to under 1ms. However, SPI uses more pins: CS, DC, MOSI, SCK, and optionally RESET. The I2C version is simpler for beginners. The OLED’s internal framerate is limited to about 100Hz, so pushing beyond that is pointless. Power consumption is about 10-20mA for the display, plus the Teensy’s draw (around 50mA for 4.0 at 600MHz). Total system draw is under 100mA, making it suitable for battery-powered projects with a 3.7V LiPo and a regulator.
Common pitfalls and troubleshooting
One frequent issue is wrong I2C address. Run an I2C scanner sketch to confirm the address. Another is voltage mismatch: some OLED modules have a built-in 3.3V regulator, but others are 5V-tolerant. Always check the datasheet. Teensy’s 3.3V pins are not 5V-tolerant, so if you use a 5V OLED, you’ll need a level shifter. The display’s contrast can be adjusted via display.setContrast(0x7F) (values 0-255). If the display shows garbage, check wiring for loose connections or try a 10kΩ pull-up resistor on SDA and SCL (Teensy has internal pull-ups, but they’re weak at 47kΩ). The SSD1306 driver has a charge pump that generates the negative voltage for the OLED pixels; if it fails, the screen stays blank. This is rare but can happen if VCC is below 3.0V. The display’s operating temperature range is -40°C to +85°C, so it works in most environments.
Advanced usage: framebuffers and double buffering
The Adafruit library uses a single framebuffer in RAM. You can modify pixels directly in the buffer using display.drawPixel(x, y, color) and then call display.display(). For double buffering, you can allocate a second buffer and swap references, but that uses 2KB of RAM—fine on Teensy 3.2 (64KB RAM) or 4.0 (2MB RAM). The U8g2 library supports page buffers, which reduce RAM usage to 128 bytes, but at the cost of slower updates. For animations, precompute frames in flash memory (PROGMEM) to save RAM. The Teensy 4.0 has 2MB of flash, so you can store hundreds of frames. The OLED’s pixel response time is about 1ms, so motion blur is minimal.
Comparison with other displays
Compared to a 0.96 inch OLED, a 1.3 inch OLED (128x64) has larger pixels but same resolution. The 0.96 inch version has a pixel pitch of 0.175mm, giving a crisp image. Color OLEDs (like the 0.95 inch RGB) use more power and require more complex drivers. The 0.96 inch monochrome OLED is the cheapest and easiest to integrate. For Teensy, the I2C version is ideal for projects with limited pins, like a sensor hub or a wearable. The SPI version is better for high-speed data displays, like an oscilloscope or a game. The display’s viewing angle is >160°, and the contrast ratio is 2000:1, typical for OLEDs. The lifetime is about 10,000 hours at full brightness, longer if dimmed.
Real-world project examples
I’ve used this OLED with a Teensy 3.2 to build a portable weather station: it reads a BME280 sensor via I2C and displays temperature, humidity, and pressure. The OLED updates every 2 seconds, and the total current draw is 35mA. Another project is a MIDI controller with a Teensy 4.0, where the OLED shows the current patch name and parameter values. The I2C bus handles both the OLED and a rotary encoder, with no conflicts. For a game, a Teensy LC can run a simple Pong clone at 30fps using the U8g2 library, with the OLED showing the ball and paddles. The frame rate is limited by the I2C speed, not the CPU.
Electrical characteristics and wiring diagram
Here’s a table of the OLED module’s pins and typical connections:
| Pin | Function | Connect to Teensy |
|---|---|---|
| VCC | Power (3.3V) | 3.3V pin |
| GND | Ground | GND pin |
| SDA | I2C data | Pin 18 (3.2/LC) or 17 (4.0) |
| SCL | I2C clock | Pin 19 (3.2/LC) or 16 (4.0) |
The I2C bus requires pull-up resistors. Teensy has internal pull-ups of about 47kΩ, which is sufficient for short wires (<10cm). If you use longer wires, add external 4.7kΩ resistors from SDA to 3.3V and SCL to 3.3V. The OLED module may have its own pull-ups, so check with a multimeter. The maximum I2C bus capacitance is 400pF; with 10cm wires, you’re well under that. The display’s logic input voltage is 1.65V to 3.6V, so 3.3V logic is safe.
Library selection and code optimization
The Adafruit SSD1306 library is the most popular, but it’s heavy on RAM (1024 bytes for the buffer). The U8g2 library is more flexible, supports many fonts, and can use a page buffer to reduce RAM usage. For Teensy, the U8g2 library is compiled with hardware I2C support, which is faster than software I2C. To use U8g2, install it via the Library Manager, then use this constructor: U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);. The “1” in the constructor means page buffer mode (128 bytes), while “F” means full buffer (1024 bytes). The full buffer mode is faster but uses more RAM. For text-only displays, the page buffer is fine. For graphics, use full buffer. The library also supports rotated displays: U8G2_R0 is normal, U8G2_R1 is 90° clockwise, etc.
Power management and sleep modes
The OLED can be put into sleep mode to save power. In the Adafruit library, call display.ssd1306_command(SSD1306_DISPLAYOFF); to turn off the display, and display.ssd1306_command(SSD1306_DISPLAYON); to wake it. The display draws about 2µA in sleep mode. The Teensy can also enter low-power modes, but the OLED’s charge pump takes about 100ms to stabilize after wake-up, so you need to wait before sending data. For battery projects, you can turn off the display between updates. The display’s internal oscillator runs at about 400kHz, and the frame rate is set by the clock divide ratio. You can adjust the frame rate with display.ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); followed by a value. Slower frame rates reduce power but cause flicker. The default is 0x80 (divide by 1), which gives 100Hz.
Testing and verification
After wiring, upload the Adafruit SSD1306 example sketch (File > Examples > Adafruit SSD1306 > ssd1306_128x64_i2c). If the display shows “Hello World” and a bouncing ball, it’s working. If not, check the I2C address with a scanner sketch. The Teensy’s I2C pins are 3.3V, so don’t connect to 5V devices without level shifting. The OLED’s contrast can be adjusted in the setup: display.setContrast(0x80);. Higher values make the text brighter but increase power. The display’s lifetime is rated at 10,000 hours at 50% brightness, which is about 1.1 years of continuous use. For long-term projects, consider dimming the display or using a screensaver. The OLED’s pixels are organic and degrade over time, especially with static images. To avoid burn-in, use a moving pattern or turn off the display when not in use.
Integration with other sensors and peripherals
The I2C bus can share multiple devices. For example, connect a BME280 sensor (address 0x76) and the OLED (0x3C) on the same bus. The Teensy’s Wire library handles arbitration. The bus speed is 400kHz, which is enough for sensor reads and display updates. If you add more devices, the bus capacitance increases, so keep wires short. The Teensy 4.0 has two I2C buses (Wire and Wire1), so you can separate the OLED from other devices to avoid conflicts. The OLED’s I2C address is fixed, but some modules have a jumper to change it to 0x3D. This is useful if you have two OLEDs. The display’s driver supports hardware scrolling, which can be enabled with display.ssd1306_command(SSD1306_SCROLLRIGHT); for horizontal scrolling. This is useful for marquee text without CPU overhead.
Mechanical mounting and durability
The OLED module is about 27mm x 27mm x 4mm, with a 0.96 inch active area. It has four mounting holes for M2 screws, but they’re often not used. You can mount it on a breadboard or solder it to a perfboard. The display is fragile—the glass is 0.5mm thick, and the OLED layer is sensitive to pressure. Use a protective cover if it’s exposed. The operating temperature range is -40°C to +85°C, but the contrast decreases at low temperatures. The display’s flexible cable (if any) is delicate; avoid bending it sharply. For permanent installations, use a ribbon cable with a connector. The module’s weight is about 3g, so it’s fine for drones or wearable projects.
Cost and availability
The 0.96 inch OLED module costs around $3 to $8 on retail sites, depending on the interface. The I2C version is slightly more expensive than the SPI version due to the extra logic. The Teensy board costs $20 to $30. Total project cost is under $50 for a standalone display. For bulk orders, the display price drops to $2 each. The display is widely available from electronics distributors like Digi-Key, Mouser, and specialized stores like DisplayModule. The module’s datasheet is usually included in the product page, but some generic modules lack documentation. Always check the pinout before buying, as some modules have reversed VCC and GND.
Alternative libraries and custom drivers
If you want to write your own driver, the SSD1306 datasheet is available online. The driver uses a command set with 256 commands. The basic sequence is: initialize with a series of commands (set display off, set clock divide, set multiplex ratio, set display offset, set start line, set segment remap, set