Turn ESP32 + OLED as a real-time “serial monitor”, Blynk debugging monitor, etc

Dear friends, for all of you that have ESP32 and OLED, either integrated like on HELTEC or TTGO dev boards, or simple stand alone additions, here is a nice function using the OLED as a real-time “serial monitor”, Blynk debugging monitor, etc.

Using the supplied demo sketch below; In the relevant #define lines enter in your: I2C_ADDRESS, sda_pin, scl_pin, wire_Frequency and rst_pin (if your OLED has this need, some like the TTGO many only need the sda/scl).

You will see all the normal Blynk processes as well as anything you want printed, using myConsole.println() , myConsole.printf() etc to your OLED display… with auto line feed, auto scrolling up, long lines splitting ( > 20 characters depending on font), auto termination wrapping (according to display character capacity), etc… basically a mini Serial Monitor!!!

The demo sketch below, has been adjusted for the HELTEC ESP32 OLED dev board that has 128x64 in resolution. You can change this resolution to fulfill your OLED resolution as long as you use OLED with SSD1306 controller.

NOT TO FORGET: this demo sketch is heavily based on @vshymanskyy’s excellent work and assistance that allowed @Gunner to continue forward with his “myConsole” implementation, and recently these scrolling additions that I have contributed.

Last but not least, in order to run the demo sketch below, you will need to install the latest versions of these libraries:

for further research and reference see:

/// ESP32 + OLED PRINTING LIKE Serial.print but in OLED ///
/// also support printing on OLED for BLYNK_PRINT messages ///

#define I2C_ADDRESS 0x3C /// default for HELTEC OLED
#define sda_pin 4
#define scl_pin 15
#define wire_Frequency 200000   /// could be in the range of 100000 to 400000
#define rst_pin 16  /// <== delete this line if your OLED does not have/support OLED reset pin 

//#define BLYNK_DEBUG
#define BLYNK_NO_BUILTIN  // Disable Blynk's built-in analog & digital pin operations


/// Example scrolling display for 64 pixel high display that is 128x64 ///

/// #include <Wire.h> /// not necessary as it is included by command #include "SSD1306AsciiWire.h" bellow
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

SSD1306AsciiWire oled;

int chPos = 0;
// Define a custom console for OLED debug output
class CustomConsole
  : public Print // This automatically adds functions like .println()
    CustomConsole() {}
    virtual size_t write(uint8_t ch) {  // Grabs character from print
       if (chPos >= 20 || char(ch)=='\n') { /// auto line splitting if line is bigger than 20 characters, font depended ...
          chPos = 0;
      if ( char(ch)!='\n') {
          Serial.print(char(ch));  // Repeat all character output to Serial monitor
          chPos++ ;
      return 1; // Processed 1 character
    // define variables used in myConsole

// initiate myConsole
CustomConsole myConsole;
#define BLYNK_PRINT myConsole

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESPmDNS.h>  // For OTA
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "AUTH"; /// put your Blynk auth here ///
char ssid[] = "SSID"; /// put your WiFi name ///
char pass[] = "PASSWORD"; /// put your WiFi password ///

///char server[] = ""; /// in case of local server etc ... ///
///int port = 8080;

char currentTime[9];
char currentDate[11];

BlynkTimer timer;
WidgetRTC rtc;

void setup() {
  /// IT IS VERY IMPORTAND TO GIVE YOUR VALUES IN THE Wire.begin(...) bellow Wire.begin(sda_pin, scl_pin, wire_Frequency); form 100000 to 400000
  Wire.begin(sda_pin,scl_pin, wire_Frequency); /// wire_Frequency: form 100000 to 400000
  #ifdef rst_pin
  pinMode(rst_pin,OUTPUT); /// THIS IS THE RESET PIN OF HELTEC OLED ... ///
  digitalWrite(rst_pin, LOW);    // set GPIO16 low to reset OLED
  digitalWrite(rst_pin, HIGH); // while OLED is running, must set GPIO16 in high  
  oled.begin(&Adafruit128x64, I2C_ADDRESS); /// in this demo sketch the selected resolution is 128x64
  oled.setFont(System5x7); /// you can change this font but always choose monospaced font for "defined" characters length per line...
  ///    oled.setFont(Adafruit5x7);

  #error INCLUDE_SCROLLING must be non-zero. Edit SSD1306Ascii.h
  // Scrolling is not enable by default for INCLUDE_SCROLLING set to one.
  oled.setScroll(true); /// activating the vertical scrolling ///
  // Scrolling is enable by default for INCLUDE_SCROLLING greater than one.

  pinMode(HARDWARE_LED, OUTPUT);  // initialize onboard LED as output  
  digitalWrite(HARDWARE_LED, HIGH); // dim the LED 
  timer.setInterval(5010L, TimeDatecheck);
  timer.setInterval(6030L, RSSIcheck);
  timer.setInterval(2045L, FlashLED);
  WiFi.begin(ssid, pass); /// provided you have put the correct one above ///
  Blynk.config(auth); /// provided you have put the correct one above ///
  ArduinoOTA.setHostname("HALTEC_ESP32_OLED");  /// For OTA recognition put yours here ///
  ArduinoOTA.begin();  // For OTA

  setSyncInterval(360);  // Time Sync

void loop() {
  ArduinoOTA.handle();  // For OTA

void TimeDatecheck() {
  myConsole.printf("%02d:%02d:%02d %02d/%02d/%04d\n",hour(), minute(), second(), month(), day(), year());

void RSSIcheck() {
  Blynk.virtualWrite(V10, WiFi.RSSI()); // RSSI
  myConsole.print("Brd #1 - RSSI:");

void FlashLED() {
  digitalWrite(HARDWARE_LED, LOW);  // Turn ON
  digitalWrite(HARDWARE_LED, HIGH);  // Turn OFF


2 posts were split to a new topic: I just bought the ESP32 with the built in OLED. I do have a couple issues though that I can’t figure out