Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.

SSD1305 OLED screen initialization problems
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SSD1305 OLED screen initialization problems

by rknox51 on Wed Sep 02, 2020 2:08 pm

Hello all,

I am building a prototype device that controls fluid flow by using stepper motors ( to turn a series of valves. The motors are controlled by the V2 Motor Shield ( using I2C communication with an Arduino Uno. I'm using an SSD1305 OLED screen ( as a display, also using I2C.

I've run into some strange issues when I try to initialize communication with the OLED screen. The first is more relevant to my project, while the second is a general issue I've seen with the screen across several Arduino sketches.

The first issue: I've implemented the code posted below using two shields to drive a total of four steppers (I removed the actual motor-driving code below, I don't think it's relevant but am happy to include it if requested). However, when I try to include a third motor shield, the OLED initialization function fails. Below, I've indicated a) the line that causes the error and b) the location in code where the error actually happens. The function doesn't return error codes or anything like that, so I can't tell exactly what part of the display.begin() function is causing the problem. My first idea was a memory issue, but commenting/uncommenting the Shield_3 line barely affects sketch size (13560 vs 13570 bytes, both 42% of total) and increases the global variable memory from 824 bytes to 886 bytes (40% and 43%, respectively). I'm really at a loss here and am not sure how to go about solving the problem; has anyone ever seen something like this issue before? Or if not, does anyone have a suggestion as to where to look?

The second issue: You can see in the code below that we write messages into the OLED buffer using display.print(). The problem is, the string to write must be no longer than exactly 17 characters. If the string is too long, the screen initialization fails in the same way as it does with the motor shield. This makes a little more sense to me in the sense that at least we're doing something that interacts with the display screen, but I think it's a bit ridiculous that a screen large enough to show a few sentences' worth of text fails to even initialize when you try to print more than three words.

To summarize these two issues, the OLED screen fails to initialize under circumstances that don't really have anything to do with it. Furthermore, the error doesn't even arise when it comes time to interact with whatever is causing the problem; it seems to literally be the presence of these objects in my code that bricks the screen.

Has anyone ever seen problems like this before? I'm happy to provide any additional information. Thank you very much in advance!

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_SSD1305.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>

#define NUM_STEPS 200           // motor steps/revolution
#define OLED_RESET 5            // OLED screen reset pin

int i = 0;                      // counting variable, used to make sure screen is updating

// create OLED display screen object
Adafruit_SSD1305 display(128, 64, &Wire, OLED_RESET);

// create motor shield objects
Adafruit_MotorShield Shield_1(0x67);
Adafruit_MotorShield Shield_2(0x68);
//Adafruit_MotorShield Shield_3(0x69);              // THIS LINE CAUSES THE ERROR IF UNCOMMENTED

void setup() {
    while (!Serial) {delay(100);};
    Serial.println("Screen + motor integration test");

// initialize motor shield objects
//    Shield_3.begin();

    if (!display.begin(0x3C)) {                      // THE ERROR OCCURS AT THIS LOCATION
        Serial.println("Unable to initialize OLED");
        while (1) {yield();}

// text formatting
    display.setTextSize(1);         // standard size
    display.setTextColor(WHITE);    // default color (white)
    display.setTextWrap(true);      // text wrapping on

void loop() {
    display.clearDisplay();             // clear display buffer

    display.setCursor(10, 10);          // write message
    display.print("Hello world!");

    display.setCursor(10, 40);          // write counter variable

    display.display();                  // update display

    i++;                                // increase counter
    delay(1000);                        // wait 1s

Posts: 1
Joined: Wed Sep 02, 2020 1:03 pm

Please be positive and constructive with your questions and comments.