-2

The gist of my issue is in the title. I have a cheap ebay SSD1306 128x64 display which I hooked up to my arduino, and checked the wiring at least 50 times and the address is correct, the display has the jumper set to 0x78 and the arduino (Nano with ATmega168) sees it on an i2c scanner as 0x3C which is expected.

Now I installed Adafruit's SSD1306 and GFX libraries and an OLED i2c library I found somewhere (can't find it, sorry. In the IDE it's called OLED_I2C) and ran both example codes (shortened Adafruit's to fit on a 168) and I can't get it to show anything. I've tried many things including trying the 128x32 code with no luck, not even missing every other line. I think the display works since it shows up in the scanner, does anyone have any idea what could be wrong? Thanks in advance

My shortened Adafruit code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


void setup() {
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  testdrawline();      // Draw many lines

  testdrawrect();      // Draw rectangles (outlines)
}

void loop() {
}

void testdrawline() {
  int16_t i;

  display.clearDisplay(); // Clear display buffer

  for(i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, SSD1306_WHITE);
    display.display(); // Update screen with each newly-drawn line
    delay(1);
  }
  for(i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, SSD1306_WHITE);
    display.display();
    delay(1);
  }

  delay(2000); // Pause for 2 seconds
}

void testdrawrect(void) {
  display.clearDisplay();

  for(int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, SSD1306_WHITE);
    display.display(); // Update screen with each newly-drawn rectangle
    delay(1);
  }

  delay(2000);
}
5
  • 1
    The scanner (?) finds the display at address 3C but you configure the lib for address 3D. Also the Adafruit code is not specified for a 168. That could be a problem. I also would not expect to find the device at 0x3C if the jumper is set to 0x78, What did I miss? And where do you use the mizzterious OLED I2C library? I don't seen an include. You mentioned "both examples" but showed only one. Perhaps I do not know enough to understand your question (or at least the facts) but I'm complete confused. ;-) – Peter Paul Kiefer Jan 17 '20 at 12:44
  • Yeah i only showed the adafruit one because i felt it was enough to show where my error was. I didn't use that library in my adafruit code, I tried using its example separately. From online tutorials apparently if the display is at 0x78 it shows up at 0x3C. can you show me where i set it to 0x3D? much appreciated – Xilog Jan 18 '20 at 8:54
  • 1
    @Xilog Yeah it's probably an adressing problem, the Oled display you are using , the SSD1306 has an IIC interface, and IIC interfaces have around 127 adrsses as much as I know, the possible two address for such a display are 0x3C and 0x3D, but since it showed in the I2c scanner that it's at 0x3C you should declare that in the 19th line in the code you provide instead of 0x3D change it to 0x3C. – Shams El-Deen Jan 18 '20 at 18:46
  • We know the address is 3C, so why want you to change it to 3D? You just can access it at the already configured address like @ShamsEl-Deen proposed. Another thought: Are you sure the 0x3C is your OLEAD display? Perhaps you have another I2C device with address 0x3C connected the "scanner"'s I2C bus and your OLED at 0x78 is invisible, for some reason. – Peter Paul Kiefer Jan 19 '20 at 11:39
  • Thanks, I found it on line 19 and changed it but it didn't fix anything. I am sure that the display is 0x3C. When i disconnect it the scanner says no devices found. – Xilog Jan 20 '20 at 13:35
2

I have some experience with the the screen you are using and I hope these tips can solve your problem.

  • Changing the Address in the code

The OLED display you are using uses what is called I2c or IIC protocol which is the abbreviation of "Inter Intergrated Circuit", here is it's Wikipedia page to read about it.

The IIC communication has 7 bit address space, that means there is 127 distinctive address for example 0x3C,0x3D,0x38 etc....

Your display might have either the address 0x3C or 0x3D so you might try changing theses values until anything would show up.

  • Unhooking any other IIC device

Although you can hook many IIC devices but as was said in the comments it's better to unhook everything except it, to troubleshoot.

  • Correct voltage ?

You might know that some displays uses 3.3v or some uses 5v, but as it showed in the IIC scanner, I don't think that is the problem in your case but you should consider it.

  • Try using other sketches

Well, I think that 99% of the problem lays in your code (sometimes happens to me), so I suggest using other library examples or completely other libraries, or if you would like to take the challenge open the datasheet for the ssd1306 and make your own library and codes.

I hope these tips will help you or any other viewer.

As a side note I am a student, so I completely will appreciate anybody editing the answer to make better or more clear.

2
  • this is not an answer nor a solution. – hcheung Jan 22 '20 at 12:49
  • Thanks so much i'll try your tips. Much appreciated – Xilog Jan 23 '20 at 3:19
2

I tried researching a while after asking this question. Turns out changing OLED_RESET to -1 fixed it.

Photo

2

The confusion about I2C address really comes from whether it's treated as a byte or 7-bit (MSB).

For example, on the OLED PCB, it's stated address I2C = 0x78, which is 0b_0111_1000 (I2C address write).

In the Adafruit Arduino SSD1306 library, it uses 7-bit I2C address, that 0x78 becomes 011_1100 (taking the 7-bit MSB) = 0x3C

1

I copied your code and load to my display. It doesn't show anything. Here is the code that I had run successfully.

#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);

void setup() {

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  display.display();
  delay(2000);

  display.clearDisplay();      //this line to clear previous logo
  display.setTextColor(WHITE); //without this no display
  display.print("Hello World!");//your TEXT here
  display.display();            //to shows or update your TEXT
}

void loop() {

 }

Good Luck, Aung Myo Oo

1
  • Thanks, however I fixed it with something else. Check my answer if you need details – Xilog Jul 7 '20 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.