Connecting 0.91 inch 128x32 OLED screen to ESP01S and displaying text

Hi there,
I'm new to using the ESP01S and I'm trying to connect a 0.91 inch 128x32 OLED SSD1306 screen to it. I know how to connect the screen to an Arduino Nano and how to display text using the "u8g2" library, here's the code I use:

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED

void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();					// clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");	// write something to the internal memory
  u8g2.sendBuffer();					// transfer internal memory to the display
  delay(1000);  
}

But I'm not sure if that library is compatible with the ESP01S or if there is a better library to use. Any suggestions, diagrams or examples of working code would be appreciated.

Library guide and reference page: Home · olikraus/u8g2 Wiki · GitHub

Yes I already tried to read the docs, but as I sad I'm new to all this so I couldn't figure out how to do it

The best approach with new hardware is to start with a library example, and see if it compiles, runs and works as expected on your setup.

I know how to use that OLED screen with my Arduino Nano, and there is an code example I used

Hi @ruku,

Take a look at this EXAMPLE

HTH?

1 Like

Excellent! Try it with the ESP01S and report back to us.

I tried it without success, that's why I'm asking for help

I will give it a try, thank you!

But you forgot to tell us what you did and what went wrong.

For hints on successful posting, please read and follow the instructions in the "How to get the best out of this forum" post.

Nothing happened, there is nothing that went wrong. I don't know how to do it, that's all.
I've tried

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 1, /* data=*/ 0, /* reset=*/ U8X8_PIN_NONE);   // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED

Connected screen like this - VCC to 5V (from Arduino Nano), GND to GND (also Nano), IO0 to SLC (SCK in my case) and IO2 to SDA
clock is SCL and data is SDA, so I don't know why it's not working

Nothing happened

Really?

Have you connected the computer and display to the ESP01? Powered everything up?

Can you enter any program, and have that program successfully compile and load on the ESP?

If so, did the ESP01 print anything at all on the serial monitor, and otherwise do what you expect?

Did you run the I2C address scanner program to see if the ESP detects the proper display address?

If the answer to all those questions is yes, then try the display program and report what actually happened. It was not "nothing".

Found solution, I was using

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=SCL*/ 0, /* data=SDA*/ 1); 

This WAS WRONG, I though "1" was for GPIO2, turns out its "2"

So the working code is

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, 0, 2);   

void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();					
  u8g2.setFont(u8g2_font_ncenB08_tr);	
  u8g2.drawStr(0,10,"Hello World!");	
  u8g2.sendBuffer();					
  delay(1000);  
}

And if you want to use U8x8 it's like this

U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(0, 2);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.