Menu

Wemos-VirginSoil-OLED-Callbacks

The Wemos-VirginSoil-OLED-Callbacks comes with the IOTAppStory library as explained here.

This example code is to demonstrate a possible solution to providing feedback about the state of the application to the end user using the Lolin(Wemos) D1 mini OLED Shield. In the previous examples we used the serial monitor to view printed messages (VirginSoil-Full) or a NeoPixel to show colors.

 

Methods used

 

Required D1 mini shields

 

As we already talked about the defines, include & initializing the IOTAppStory library in the VirginSoil-Basic example and the IAS methods in the VirginSoil-Full example we will skip that here.

#include <SSD1306.h>

SSD1306  display(0x3c, D2, D1);

Include Daniel Eichhorn's OLED library
Initialize OLED

 

// ======================== SETUP ======================== 
void setup() {
  display.init();
  display.flipScreenVertically();
  display.clear();
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(48, 35, F("Wait"));
  display.display();

  ...
}

Setup OLED and display "Wait"

 

// ======================== SETUP ======================== 
void setup() {
  ...

  IAS.onModeButtonShortPress([]() {
    Serial.println(F(" If mode button is released, I will enter in firmware update mode."));
    Serial.println(F("*-------------------------------------------------------------------------*"));
    dispTemplate_threeLineV2(F("Release"), F("for"), F("Updates"));
  });

  IAS.onModeButtonLongPress([]() {
    Serial.println(F(" If mode button is released, I will enter in configuration mode."));
    Serial.println(F("*-------------------------------------------------------------------------*"));
    dispTemplate_threeLineV2(F("Release"), F("for"), F("Config"));
  });

  IAS.onConfigMode([]() {
    dispTemplate_threeLineV2(F("Connect to"), F("Wi-Fi"), "xxxxx-soil");
  });

  IAS.onFirmwareUpdateCheck([]() {
    dispTemplate_threeLineV2(F("Checking"), F("for"), F("Updates"));
  });

  IAS.onFirmwareUpdateDownload([]() {
    dispTemplate_threeLineV2(F("Download"), F("&"), F("Install App"));
  });

  IAS.onFirmwareUpdateError([]() {
    dispTemplate_threeLineV1(F("Update"), F("Error"), F("Check logs"));
  });

  ...
}

We used the functions dispTemplate_*** to display texts on the OLED. They are declared at the end of the sketch. Find out more about callbacks here.

 

// ======================== LOOP ======================== 
void loop() {
  IAS.loop();


  //-------- Your Sketch starts from here ---------------

  if (millis() - printEntry > 5000 && digitalRead(D3) == HIGH) {
    printEntry = millis();
    dispTemplate_threeLineV1(F("Loop"), F("Running"), F("Do Stuff..."));
  }
}

Display "Loop Running Do Stuff..." Keep in mind that this also works as a "reset" for the OLED screen. As it would otherwise keep displaying the last message from the callbacks.

Added by