Problem with OLED 128x32 I2C

Massel

Well-known member
Hello everyone,

I just had a strange problem with the adafruit I2C OLED module.
I reduced the code to the following:
Code:
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 9
Adafruit_SSD1306 display(OLED_RESET);
#define LED_PIN 13
bool blinkState = false;
int counter = 0;

void setup() {
    pinMode(LED_PIN, OUTPUT);
    // initialize communication
    Wire.begin();
    Serial.begin(38400);
    // initialize OLED
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    // display text
    display.setCursor(0,0);
    display.print("working...");
    display.display();
}

void loop() {
    // blink LED to indicate activity
    digitalWrite(LED_PIN, blinkState);
    blinkState = !blinkState;
    counter++;
    display.clearDisplay();
    display.setCursor(0,0);
    display.print(counter);
    display.display();
    Serial.print(counter); Serial.print("\n");    
    delay(200);
}

The interesting part is, that the same code on the same board with the same circuit stops after 1 to 5 cycles. But why?
Everything this code should do is let the LED blink and print a increasing number on the OLED display.
After counting a couple of cycles (random between 1 and 5) it seams like the Teensy 3.1 got stuck. The OLED display shows the last number and the LED stays in the state it has.

Is there a problem in the lib, in the code, or is it just to late at night ;)
 
Last edited:
I tried this just now on a Teensy 3.1 and Adafruit OLED here. I could not reproduce the problem.

oledtest.jpg
(click for full size)

I did have to comment out 2 of the includes, and I changed the reset to pin 4, since that's where my board has it connected.

Here's the exact code I tried:

Code:
//#include "I2Cdev.h"
//#include "MPU6050.h"
#include "Wire.h"

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define LED_PIN 13
bool blinkState = false;
int counter = 0;

void setup() {
    pinMode(LED_PIN, OUTPUT);
    // initialize communication
    Wire.begin();
    Serial.begin(38400);
    // initialize OLED
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    // display text
    display.setCursor(0,0);
    display.print("working...");
    display.display();
}

void loop() {
    // blink LED to indicate activity
    digitalWrite(LED_PIN, blinkState);
    blinkState = !blinkState;
    counter++;
    display.clearDisplay();
    display.setCursor(0,0);
    display.print(counter);
    display.display();
    Serial.print(counter); Serial.print("\n");    
    delay(200);
}

I tested with Teensyduino 1.18 & Arduino 1.0.5 on Linux 64 bit.
 
Last edited:
Hmmm... there might be a problem afterall?

I left this running at it mysteriously stopped much later, at 8040.

I'll keep running tests over the next few days....
 
Thx!
I will go on testing too!

By the way, I'm using Mac OSX 10.9.1 & Arduino 1.0.5 & Teensyduino 1.18
 
Any news so far?

The Program seams to stop within the first 10 cycles in my setup...
I really don't know what is going on there...
 
Massel, if you run the code Paul gave (with the I2Cdev include commented out) does it still stop after 10 cycles? Since you are running two I2C devices with different I2C implementations, this might be the problem.
 
Nantonos, I just tried disconnecting the 2nd I2C device and deleting the relating lib references.
No changes in behavior!

But thanks for the advice, in the final project the MPU6050 (2nd I2C device) is running on fast I2C with a sample rate of 333Hz.
I hope if the display finally runs it still runs with the 2nd I2C device using like 90% of the I2C capabilities...
 
I've been working with this again today, and I just can't seem to reproduce the problem. I have no idea what I did that got it to stop at 8040 before. Today I've had it count past 20000 (and still going) three times.

Massel, can you please post a photo of your setup? Maybe this Adafruit display is sensitive to wiring or something else? Your's is always stopping before counting to 10, right?
 
Ok,

I just wired it again. And it seams to run. Even with the MPU6050 connected on the same I2C bus (but not running).
The only difference is the breadboard (components are the same), cause I'm not at home right now.
I will check the other breadboard...

Ok, as I wrote this post it stopped at 2940.
I will post a picture of the board in a minute.
 
I did several tests with the delay set to only 2, or no delay in loop(). I could not reproduce the problem.

I've started running it again with delay(200), exactly as the code above in reply #2. It's already counted up to 9850 and still going. I'll leave it running....
 
It is not unheard off that breadboards have some problems with intermittant contacts. Perhaps try to solder connections or use another more reliable method for connecting signals.
 
Can you try removing the motion sensor and all its wires, and power the OLED from Teensy 3.1's VIN (5V) to the VIN pin on the OLED. Leave the OLED's 3.3V pin disconnected.

Mine's still running here, just passed 77100.
 
Interesting,

I'm at home now and working with the other PC (mac mini) again, and the code stopped after 1 cycle. I guess there is something going on with the libs or versions here...
I will check that.

Then I will use the setup you just explained.
 
Checked everything.

I had different time stamps of the used libs (Wire and SSD1306).
I copied these, now they are the same on both Macs.

The code is running (like it was all day) on the MacBook with the Teensyduino 1.18 rc4 installed.
It is not running on the Mac mini with the Teensyduino 1.18 installed.
Both Macs have the same OSX-Version and the same Arduino version (1.0.5)

I think this is the only difference.
 
Going on (sry for all these posts, I just write them as I figure out things...).

The code just stopped at litte over 3500 on the MacBook with the setup you gave me using VIN instead of 3.3V.
 
We both must be using an older version of Adafruit's library. The latest requires #include <SPI.h>.

I just downloaded the latest version from here:

https://github.com/adafruit/Adafruit_SSD1306

I'm starting another test now. I'm running this latest version from Adafruit (with the file edited for the 128x32 size), and Teensyduino 1.18 on Arduino 1.0.5.

Perhaps you could get the latest code from Adafruit and use a fresh copy of Arduino 1.0.5 with Teensyduino 1.18 (not any of the prior "rc" versions)?

Here is the exact code I'm running. I'm using Teensy 3.1 set to "Serial" and "96 MHz" in the Tools menu.

Code:
#include <Wire.h>
#include <SPI.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define LED_PIN 13
bool blinkState = false;
int counter = 0;

void setup() {
    pinMode(LED_PIN, OUTPUT);
    // initialize communication
    Wire.begin();
    Serial.begin(38400);
    // initialize OLED
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    // display text
    display.setCursor(0,0);
    display.print("working...");
    display.display();
}

void loop() {
    // blink LED to indicate activity
    digitalWrite(LED_PIN, blinkState);
    blinkState = !blinkState;
    counter++;
    display.clearDisplay();
    display.setCursor(0,0);
    display.print(counter);
    display.display();
    Serial.print(counter); Serial.print("\n");    
    delay(200);
}
 
Just installed Arduino 1.0.5 and Teensyduino 1.18.
Downloaded the linked SSD1306 lib and copied into the lib folder... and the GFX lib, too.
https://github.com/adafruit/Adafruit-GFX-Library

With these libs I just got half characters !? At least it seams as if only the top 2 to 3 pixels get printed on the screen. Whats going on there?
Same setup with the old libs is running right now (over 700) on the Mac Mini which is progress ;)
 
Just a quick followup... mine's still running here with Adafruit's latest code. It's counted to 348500 and still going. I've been running it from a 5V power supply, not a computer.

You're testing with the board connected to a Mac, right? Maybe OS-X is doing something unexpected that Teensy isn't handling well? I'm just guessing here, but I really do want to figure out what's going wrong.
 
The code is running (like it was all day) on the MacBook with the Teensyduino 1.18 rc4 installed.
It is not running on the Mac mini with the Teensyduino 1.18 installed.
Both Macs have the same OSX-Version and the same Arduino version (1.0.5)

I think this is the only difference.

Does the Mac Mini perhaps have a low powered or poorly regulated USB power?
To eliminate this as a factor, try powering from a 5V supply or use a powered USB hub.
 
Just wanted to post a final followup on this.

My Adafruit OLED has been running for several days from a 5V power adaptor, without any sign of trouble. It's still counting. Here's on last photo before I shut it off.

oled.jpg

I'm afraid this problem is going to be filed under non-reproducible for now. I just can't do anything about it until I can find a way to make it happen here.
 
Back
Top