ESP8266/SSD1306 OLED using I2C - Migrating project from UNO to Espduino

I am trying to connect a 0.96" OLED display to ESPDUINO using I2C. It is black screen. It works perfectly on the UNO but not on the new board. Hell, its only 4 wires so i shouldn't have problems right? This is what I have tried:

  1. Triple checked the wiring (works on the UNO)

  2. Made sure i am getting VCC and GND on the OLED pins

  3. Ran the I2C finder to connect to the OLED and double check the address (It was 0x3C) so the display is communicating with the ESP. "Blink" programs just fine and blinks the blue onboard LED

  4. I ran my scope on the DATA and CLK lines and got an I2C serial signal. I read in "Kolbans's Book On ESP8266" that 4k7 ohm pullups on the DATA and CLK can help so I added them and got a way better signal but I still don't have a display.

  5. Added auxiliary power supply to the ESP in case my USB was not supplying enough power.

Now it comes down to code, I think. This is my first foray in to ESP8266 chips. The code comes from the Adafruit site via github. I pulled out a majority of the code and just left the basics to get me started. Does the code run the same between Atmel and ESP chips? Any ideas what I am doing wrong?

This is just the basic sketch from Adafruit: ssd1306_128x64_i2c.ino

I would post the ENTIRE code but there was a message that it exceeded 9000 characters and needed to be corrected so here is the first half :confused: I had to delete after LOOP.

/*********************************************************************




This example is for a 128x64 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)

/

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

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

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

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done
  
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(2000);

  // Clear the buffer.
  display.clearDisplay();

  // draw a single pixel
  display.drawPixel(10, 10, WHITE);
  // Show the display buffer on the hardware.
  // NOTE: You _must_ call display after making any drawing commands
  // to make them visible on the display hardware!
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw many lines
  testdrawline();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw rectangles
  testdrawrect();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw multiple rectangles
  testfillrect();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw mulitple circles
  testdrawcircle();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw a white circle, 10 pixel radius
  display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
  display.display();
  delay(2000);
  display.clearDisplay();

  testdrawroundrect();
  delay(2000);
  display.clearDisplay();

  testfillroundrect();
  delay(2000);
  display.clearDisplay();

  testdrawtriangle();
  delay(2000);
  display.clearDisplay();
   
  testfilltriangle();
  delay(2000);
  display.clearDisplay();

  // draw the first ~12 characters in the font
  testdrawchar();
  display.display();
  delay(2000);
  display.clearDisplay();

  // draw scrolling text
  testscrolltext();
  delay(2000);
  display.clearDisplay();

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello, world!");
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.println(3.141592);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print("0x"); display.println(0xDEADBEEF, HEX);
  display.display();
  delay(2000);
  display.clearDisplay();

  // miniature bitmap display
  display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  display.display();
  delay(1);

  // invert the display
  display.invertDisplay(true);
  delay(1000); 
  display.invertDisplay(false);
  delay(1000); 
  display.clearDisplay();

  // draw a bitmap icon and 'animate' movement
  testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}


void loop() {
  
}



}

[/code]

So you're using the SDA/SCL on the board?

Yes

ElHefe:
I am trying to connect a 0.96" OLED display to ESPDUINO using I2C. It is black screen. It works perfectly on the UNO but not on the new board. Hell, its only 4 wires so i shouldn't have problems right? This is what I have tried:

  1. Triple checked the wiring (works on the UNO)

The Uno is a 5V device, the ESP is 3.3V?

ElHefe:
2. Made sure i am getting VCC and GND on the OLED pins

  1. Ran the I2C finder to connect to the OLED and double check the address (It was 0x3C) so the display is communicating with the ESP. "Blink" programs just fine and blinks the blue onboard LED

  2. I ran my scope on the DATA and CLK lines and got an I2C serial signal. I read in "Kolbans's Book On ESP8266" that 4k7 ohm pullups on the DATA and CLK can help so I added them and got a way better signal but I still don't have a display.

  3. Added auxiliary power supply to the ESP in case my USB was not supplying enough power.

So you have not verified that your ESP actually is controlling your display?

Write a simple test routine that draws a line on the display.

The ESPduino code is not completely Arduino compatible. So maybe the Adafruit library is using a shortcut to improve responsiveness and the ESPduino core does not support that shortcut.

ElHefe:
Now it comes down to code, I think. This is my first foray in to ESP8266 chips. The code comes from the Adafruit site via github. I pulled out a majority of the code and just left the basics to get me started. Does the code run the same between Atmel and ESP chips? Any ideas what I am doing wrong?

This is just the basic sketch from Adafruit: ssd1306_128x64_i2c.ino

I would post the ENTIRE code but there was a message that it exceeded 9000 characters and needed to be corrected so here is the first half :confused: I had to delete after LOOP.

If the adafruit code is doing any bit manipulations that could be a source of some of your fails. The ESP is a 32bit cpu were the UNO,MEGA are 8 bit cpu's.

I would start by writing a bare test function to verify the electrical connectivity. Then start testing each function of the AdaFruit library.

Chuck.

Write a simple test routine that draws a line on the display.

I wrote a quick function test for the UNO. It just draws a short line. Works great on the UNO, not at all on the ESP. see below.

The same code loads in the ESP ok and responds to the I2C scanner sketch and returns: 0X3C address. So the display is communicating but not displaying a line.

The Uno is a 5V device, the ESP is 3.3V?

No, the esp runs off USB or 6-12 plug looks just like the UNO.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup()   {
  Serial.begin(9600);
  display.clearDisplay();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3D (for the 128x64)

  display.drawPixel(  10  , 10  , WHITE);
  display.drawPixel(  10  , 11  , WHITE);
  display.drawPixel(  10  , 12  , WHITE);
  display.drawPixel(  10  , 13  , WHITE);
  display.drawPixel(  10  , 14  , WHITE);
  display.drawPixel(  10  , 15  , WHITE);
  display.drawPixel(  10  , 16  , WHITE);
  display.drawPixel(  10  , 17  , WHITE);
  display.drawPixel(  10  , 18  , WHITE);
  display.drawPixel(  10  , 19  , WHITE);
  display.drawPixel(  10  , 20  , WHITE);
  display.drawPixel(  10  , 21  , WHITE);
  display.display();                          

}

void loop() {
  

}

BTW, should i have posted this in the "Display" forum?

Fixed it:

#define OLED_RESET 4 //changed this to 16 and now it works! I think it was continuously resetting.

ElHefe:
Fixed it:

#define OLED_RESET 4 //changed this to 16 and now it works! I think it was continuously resetting.

This helped me a lot! do you know why 4 had to be changed to 16!