126x64 OLED screen compatibility with teensy4.1

khoadley

Member
I am trying to run a monochrome OLED 128x64 screen from adafruit on a teensy4.1. While this is part of a larger project, I am having trouble running even the simple example code as part of the u8g2lib package "hello world". I do not consider myself an expert, but I do think I have it set up properly (with libraries). I have the data and clk connected to pins 19 and 18 respectively. The screen is powered by a 5 volt signal from the teensy and also connected via ground. I am running the code below but am not getting anything on the screen. Hoping someone might have a hint on how to sort this out. Thanks in advance!

Code:
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

/*
  U8g2lib Example Overview:
    Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
    Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
    U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
    
*/
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 18, /* data=*/ 19, /* reset=*/ U8X8_PIN_NONE);   // ESP32 Thing, pure SW emulated I2C



void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr);    // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
  delay(1000); 
}
 
Do you have a link to the OLED display that you have? Might be a powering issue.

You're also using software i2c (SW_I2C), not hardware (HW_I2C). Is that intended?

Also:
Pin 18 is usually data.
Pin 19 is usually clock.
Not sure if that would matter with software i2c though.
 
That isn't the driver seen in use - and that code doesn't show the i2c address (which is always confusing as 0x3c or 0x3d)

Found a sketch used here with a PJRC i2c demo board that starts like this:
Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
 
Thank you all for your responses! Submo and Defragster, I will try out your suggests ASAP! Submo, the SW vs. HW was not intended (I was literally going down the line of options in the example code). Will double back and try HW as well. I have also attached a link to the specific screen I am using adafruit-monochrome OLED. I do wonder if it is indeed a power issue as I have not gotten the screen to light up at all (although the green led on the back of the screen does light up, confirming it is receiving power). Thanks again.
 
Last edited:
Defragster, I am not sure I understand your comment 'this isn't the driver seen in use'. Sorry, limited background on this on my end. Is there more to the demo code I can use to trouble shoot? I have had success using the 128x32 OLED screen with the teensy4.1 (also using the u8g2lib). Having no luck with the bigger screen though.
 
Defragster, I am not sure I understand your comment 'this isn't the driver seen in use'.
What I believe he was suggesting, is to try out using the Adafruit SSD1306 driver, which even if that is not the driver you wish to use
it will help isolate the issues.

Looks like the display is setup to be 3.3v compatible.

Might help if you posted some pictures, like the wiring and the back of the display, so we can see which version of the display,
plus the hardware jumpers.

For example, from the Adafruit documentation: https://learn.adafruit.com/monochrome-oled-breakouts/wiring-128x64-oleds
looks like there is a silkscreen issue on configuring for I2C versus SPI.


I don't use this library, so hard to know all of the in's and out's

As has been mentioned, might use HW I2C version of the setup, again not sure which one, maybe something like:
U8G2_SSD1306_128X64_NONAME_1_HW_I2C

Also I don't know what their default I2C address is in this library. but from:
Looks like maybe it defaults to the lowest valid address for the display? 0x3c?
If so I think by default this one is setup for 0x3D, so that thread shows someone having luck with their display like:
Code:
  u8x8.setI2CAddress(0x7a);//0x3d x 2
  u8x8.begin();
 
Had a quick look at the schematic for the OLED, and I don't think you should be powering it by 5v at VIN. The i2c lines are connected to VIN via a resistor, and I'm pretty sure the Teensy won't like that. That OLED can be powered by 3.3v (at VIN) so I would stick with that to be safe. Hopefully you haven't killed any pins.
 
Back
Top