PDA

View Full Version : Problem with OLED 128x32 I2C



Massel
02-22-2014, 11:46 PM
Hello everyone,

I just had a strange problem with the adafruit I2C OLED module.
I reduced the code to the following:


#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 ;)

PaulStoffregen
02-25-2014, 09:40 PM
I tried this just now on a Teensy 3.1 and Adafruit OLED here. I could not reproduce the problem.

1512
(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:



//#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.

PaulStoffregen
02-26-2014, 02:46 PM
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....

Massel
02-26-2014, 07:13 PM
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

Massel
03-01-2014, 07:00 PM
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...

Nantonos
03-01-2014, 09:39 PM
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.

Massel
03-02-2014, 08:15 AM
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...

PaulStoffregen
03-04-2014, 11:41 AM
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?

Massel
03-04-2014, 12:13 PM
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.

PaulStoffregen
03-04-2014, 12:31 PM
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....

Massel
03-04-2014, 12:34 PM
Here is the wiring:
1555

Massel
03-04-2014, 01:07 PM
Ok,
It stopped around 1600 and on another run at 9494...
running at delay(20).

Headroom
03-04-2014, 04:54 PM
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.

PaulStoffregen
03-04-2014, 04:54 PM
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.

Massel
03-04-2014, 05:04 PM
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.

Massel
03-04-2014, 05:16 PM
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.

Massel
03-04-2014, 05:18 PM
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.

PaulStoffregen
03-04-2014, 05:28 PM
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.



#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);
}

Massel
03-04-2014, 06:17 PM
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 ;)

Massel
03-04-2014, 06:43 PM
and it stopped at 7336...

PaulStoffregen
03-04-2014, 07:50 PM
Mine's still running here, using Adafruit's latest on Teensyduino 1.18. It just passed 39100.

PaulStoffregen
03-04-2014, 07:52 PM
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?

I have no idea. They're working perfectly on the Adafruit OLED I have here.

PaulStoffregen
03-05-2014, 02:33 PM
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.

Nantonos
03-05-2014, 04:56 PM
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.

PaulStoffregen
03-10-2014, 06:27 PM
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.

1615

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.

Massel
03-10-2014, 08:31 PM
I was just testing something and wanted to use the OLED, guess what? It wasn't working!
And here's the thing!
It is not working with the Teensy running at 24MHz!!
It is running at 48MHz!!!

Can you reproduce this?

Massel
03-15-2014, 10:20 AM
Hi,

I'am able to reproduce this problem, you too?
Would be nice to get this running at 24MHz, cause 48MHz just means more power consumption in my case.

George1
03-20-2014, 09:06 PM
Hi,

I had a similar problem with Teensy 3.1 where it freeze and it wouldn't go through all the animation steps in the Adafruit example code. I changed the frequency to 48MHz and it seems to work fine now. I will do additional testing but changing run frequency from 24 to 48MHz seem to have help for sure. The power use is not much higher according to my power supply (few more mA than before). Thanks Massel.

George

PaulStoffregen
05-27-2014, 09:12 PM
Here is an update that attempts to fix this bug at 24 MHz.

If you're still watching this old thread, please let me know if this fixes the problem for you?

daperl
05-27-2014, 11:39 PM
How do I get this OLED to not cause buzzing when I use it with the audio shield? That's the real question.

PaulStoffregen
05-28-2014, 09:42 PM
Do you hear the noise if you listen with headphones plugged into the headphone jack?

If so, then the display is somehow corrupting the audio. If you get a clean signal with headphones, but noise on line-out or from the headphone jack when connecting to some other system, then the issue is probably a ground loop problem. These are very different types of problems, even though the noise can sound very similar, so the first step is to try to figure out which type of problem you have.

daperl
05-29-2014, 06:13 AM
The noise is the same through the headphone jack. I have a relatively complicated circuit, so I'll try to recreate the problem with a simpler circuit, but my requirements are to use this display while using both the line-in and line-outs of the audio shield. When I set the gain of the line-in mixer input to 0.0, the noise of the display refresh goes away.

Massel
05-29-2014, 07:48 PM
I will test the new lib!
Is the change also impacting the 48MHz usage? Cause I switched to 48MHz and I have had a few problems with the OLED and 48MHz...
I Will test it over the next days.

Thanks for the update!!!

PaulStoffregen
05-29-2014, 08:05 PM
This update is now part of 1.19-rc1.

http://forum.pjrc.com/threads/25888-Teensyduino-1-19-Release-Candidate-1-Available

If you're going to test within the next day or two, please install 1.19-rc1 so you'll also have the many other small fixes.

Massel
06-03-2014, 06:52 AM
Hey Paul,
I have tested the OLED with 24MHz for two days now and it was working fine all the time. I will go on testing at the weekend again with different setups.
But for now it it working pretty nice (and the use of 24Mhz increased my battery life time by one hour ;) )

Thx

PaulStoffregen
06-03-2014, 07:07 AM
Thanks for the update.

Version 1.19 is now release, with support for slower low-power speeds, all the way down to only 2 MHz. But the USB doesn't work below 24 MHz.