I recently designed a simple device based on a Teensy 3.2 that uses an OLED display via I2C. The software was based on the Adafruit SSD1306 and GFX library. The hardware interface to the OLED display is simply the SDA and SCL lines with 4K7 pull-up resistors. There are no other devices on the I2C bus, and the PCB trace length is quite short. Everything It's a menu driven system with some buttons that do the typical switching between menus and scrolling up and down through values.

Everything works perfectly on the Teensy 3.2. I then swapped-in a Teensy LC to save cost, as we will eventually build at least a hundred of these. The migration was simply swapping the physical module, then switching boards in the Arduino compiler from the 3.2 to the LC.

Running on the LC the OLED display now displays corrupted information, and the display tends to scroll one column of pixels from left to right each time it is updated. When I swap back to the Teensy 3.2 it works fine. I tried swapping in and out several 3.2 and LC modules, and the fault remained consistent with the use of the LC.

Some sample code is posted below. There's not much point in posting any more code as the code is fine because it works on the Teensy 3.2. The hardware is straightforward. I did try lowering the I2C resistors down to 1K each as an experiment, but with no significant impact. My only possible conclusion issue is a timing issue with the I2C interface. I tried lowering the SCL clock frequency with Wire.setClock(100000) but that had no effect.

Any thoughts ?

Here is a code snippet:




Initialization
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Code from one of the routines called from the main loop:
// Initialise the display
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Adafruit library address 0x3D for 128x64, however we found that 3C is correct for our display.
Serial.println(F("SSD1306 allocation failed"));
//for (;; // Don't proceed, loop forever
}

display.clearDisplay();
display.fillRect(0, 0, display.width() - 1, display.height() - 1 , WHITE); // Fill the display with white
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(BLACK, WHITE); // Draw black text on white background
display.setCursor(0, 12); // Set position for title text
display.println(" Product");
display.setCursor(0, 36); // Set position for title text
display.println(" Name");
display.drawRect(2, 2, display.width() - 5, display.height() - 5 , BLACK); // Draw a black border offset from the edge
display.display(); // Update screen