Newbie - I2C screen and wemos D1 help

Hi All,

I’ve just started playing with my Wemos and a I2C 128x64 screen

I wanted to make a coin ticker as in several post but was unable to get any to work, they either needed a esp8266 dev board or just failed to compile.

So the best approach is to write my own but using other scripts as a reference, this way I learn how it works and hopefully increases my skills. The first problem is the number of resources is overwhelming, and none seem to have the info I need.

// Libraries
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 0  // GPIO0
Adafruit_SSD1306 OLED(OLED_RESET);

// WiFi settings
const char* ssid     = "mywifi";
const char* password = "mypasswd";

void setup() {
  
  // Serial
  Serial.begin(115200);
  delay(10);

   // Initialize display
  OLED.begin();
  OLED.clearDisplay();
  
  //Add stuff into the 'display buffer'
  OLED.setTextWrap(false);
  OLED.setTextSize(1);
  OLED.setTextColor(WHITE);
  OLED.setCursor(0,0);
  
  // We start by connecting to a WiFi network
  OLED.println("Connecting to ");
  OLED.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    OLED.println(".");
    OLED.clear();
  }

  OLED.println("");
  OLED.println("WiFi connected");  
  OLED.println("IP address: ");
  OLED.println(WiFi.localIP());

  OLED.display(); //output 'display buffer' to screen 

}

void loop() {
  delay(2000);

//Clear screen
   OLED.println("Running Main Prog ");
   OLED.println(".");

  }

What I would like to happen is the screen pause after the WIFI connection with the delay and then clear / refresh the following text to appear on the top of the display. Also maybe use scrolling text for longer lines such as IP address or a url.

I can’t seem to find a resource for the OLED cmds using adafruit I know I did search but found lots of alternate LED cmds that failed on this GFX lib.

Thanks
Newbie P

Hi,

Ok I have managed to get the screen to do as I wanted and clear and refresh, though I am not 100% sure I am doing it correctly as I have basically repeated the init code.

void loop() {
  delay(2000);

  OLED.clearDisplay();
  OLED.setCursor(0,1);
  OLED.println("TESTING...");
  OLED.display(); //output 'display buffer' to screen  

}

I guess I have to have the OLED.display line at the bottom of every section I print in?
And I noticed the OLED.clearDisplay has to be Capitalized correctly.

P

The first thing to do after installing a library is RUN THE EXAMPLES.

The Adafruit_SSD1306 library draws text, graphics to an internal buffer. You then call display() to blit the updated buffer to the screen.

Just study the example code.

David.

I guess I have to have the OLED.display line at the bottom of every section I print in?

When you do a print or any of the graphic functions the changes are made to a screen buffer. The contents of the buffer are not transferred to the screen's memory (displayed) until the OLED.display() function is executed. So the OLED.display() function only needs to be called when you want to actually write to the screen, not necessarily every section.

Thanks guys that makes sense.