[SOLVED] ITEAD OLED SSD1306 with U8Glib ?

Hi folks,

Anyone got this OLED: http://imall.iteadstudio.com/im130625003.html

Working with this library: Google Code Archive - Long-term storage for Google Code Project Hosting.

I have the OLED working with the Adafruit & Multi library but the code is too large for my application - it looks like U8GLIB will fit OK but I'm having problems getting it working - just so many options :slight_smile:

I'm using I2C & address 0x3C along with the reset line on D8.

Or, alternatively, has anyone stripped out the Adafruit Library so it just prints text and occupies much less space?

Any points would be great - cheers.

point5:
Or, alternatively, has anyone stripped out the Adafruit Library so it just prints text and occupies much less space?

I modified Bill Greiman's SSD1306ASCII library to add scaled characters (up to 8X) and H/W SPI support. But it doesn't do I2C. You'd have to add that yourself. If you're interested in it let me know.

A simple "hello world" sketch is about 5.5K and uses about 50 bytes of ram. If you removed the code for drawing larger characters you could reduce the size by ~1K.

Hi point5

How did you wire the OLED? What is your u8glib constructor? What exactly does not work?

Oliver

Hi both,

Many thanks for responding.

jboyton, that sounds ideal but alas I don't have the skills to implement the I2C code myself, I guess I will keep my eyes peeled for when this pops up in the future.

olikraus, Sorry, when I say doesnt work I guess I mean 'no signs of life' or nothing being written to the screen. the OLED was wired: SDA-A4, SCL-A5, GND-GND, VCC-3V3 & RST-D8 and I tried quite a few constructors, a couple Adafruit ones within the demo code and some others I found lurking in the forums.

Cheers.

Does your current hardware setup work with the Adafruit lib? If yes, then it also should work with u8glib.
In this case, please use this constructor:

U8GLIB_SSD1306_128X64(U8G_I2C_OPT_NONE)

However Reset pin is not supported and you must manually either pull D8 to high or connect RST with VCC

Oliver

point5:
jboyton, that sounds ideal but alas I don't have the skills to implement the I2C code myself, I guess I will keep my eyes peeled for when this pops up in the future.

Well I couldn't resist doing it. I more or less copied the I2C code from another library so it wasn't as if I had to figure much out on my own.

Using I2C is a lot slower than SPI, which is why I hadn't bothered before. And the text-only library is usually (but not always) slower than drawing text with the Adafruit library. But maybe speed isn't an issue for you.

Hi Oliver & jboyton,

Oliver - I tried the constructor above but it wouldn't compile but I guess you mean:

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

I have the reset pin pulled high but still no joy?

jboyton, WOW - that's fast and very good of you, how can I give the code a spin?

If the same setup works with the Adafruit lib, it should also work with u8glib.

Maybe you can post your code and also a picture of your setup.

Oliver

Hi Oliver - the setup works with the Adafruit demo so guessing it must be code, this is what I'm testing - any good?

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);	// I2C / TWI 

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 22, "Hello World!");
}

void setup(void) {
  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
}

void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(50);
}

Here you go, no promises. Good luck.

With the text library your sketch should look like this:

#include <SSD1306_text.h>
#include <Wire.h>

#define OLED_RESET 4
SSD1306_text display(OLED_RESET);

void setup(void) {
  display.init();
  display.clear();
  display.print("Hello World!");
}

void loop(void) {}

readme.txt (728 Bytes)

SSD1306_text.cpp (8.38 KB)

SSD1306_text.h (2.6 KB)

ssdfont.h (3.07 KB)

Hej jboyton, very cool indeed - worked right off the bat and with a nice small footprint - you have given us a nice light driver which is bound to be useful to many, will you be popping this up on github or similar to share?

Thanks again, your help is much appreciated.

Glad it actually worked for you. I was thinking of trying to do this when I came across the code that Bill Greiman produced (which in turn originated with Adafruit code). I mainly just added the ability to scale characters since for my project I want 5x7, 10x14 and 15x21 sized characters, or something similar.

I forgot to mention that you can do limited graphics by doing direct writes to the screen:

sendData(u) -- u is unsigned 8-bit value

Since there is no read/modify/write this call clobbers any previously written pixels in the vertical 8 pixel slice on the screen. So you can't do real graphics where different elements coexist without worry; for that you need u8glib. But at least it allows for a way to draw simple things like vertical or horizontal lines, with some care.

I've attached a hastily prepared example that includes drawing a little box.

edit: If you're not using a reset pin (I didn't know you could just tie it high), you might want to change the code so that it doesn't set whatever pin you're passing in the constructor as an output pin. Look in the .cpp file for "rst_" and comment out those 4 lines and the two calls to delay().

demo.ino (1.25 KB)

Thanks again jboyton - all working nicely :slight_smile:

Are you using the reset pin?

I may have misunderstood from the above comments where you posted that you were pulling it high. I tried that with my own display and it wouldn't work. It had to have a low pulse after being powered on.

Since u8glib doesn't support the reset pin for I2C for the 1306 maybe that's why it wouldn't work for you.

I need a small footprint library for simple text display on the 128x64 OLED so I'm trying to use the "SSD1306_text" library that jboyton created and uploaded but I'm unable to compile even the HelloWorld sketch with 1.6.9.
Errors...

In file included from C:\Users\pf\Documents\Arduino\libraries\SSD1306_text\SSD1306_text.cpp:13:0:

C:\Users\pf\Documents\Arduino\libraries\SSD1306_text\ssdfont.h:3:29: error: variable 'font' must be const in order to be put into read-only section by means of 'attribute((progmem))'

static unsigned char font[] PROGMEM = {

^

If I change the font array to const type I get a conversion error:

C:\Users\pfV\Documents\Arduino\libraries\SSD1306_text\SSD1306_text.cpp:148:26: error: invalid conversion from 'const unsigned char*' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

uint8_t *base = font + 5 * c;

Any tips to get this to compile or whether there is another very small text only library for use with the OLEDs?

pfarkas,

U8g2 (u8glib V2) includes a text only library. Still not sure what had been the original problem with u8glib, but u8g2 just will use standard TWI.h and SPI.h libs.

Oliver