My attempts at transferring BLYNK_PRINT to Various Displays

EDIT - As I am progressing on this attempt to emulate what smrtr people can do, I have moved my posts to my own topic so as not to clutter up @vshymanskyy accomplishment topic :wink:


Looks like the u8g2 Library also supports the Arduino print() function. But clearly a PCD8544_84X48 LCD doesnā€™t cut itā€¦ at least in u8x8 straight text mode (fixed font size) :slight_smile:

So far I havenā€™t had any results with the u8g2 graphical font mode. I havenā€™t figured out its screen buffer method yet :thinking:

1 Like

Well, this has been fun and allā€¦ but also frustrating due my limited programming experience.

I have managed to use smaller fonts, fitting 8-9 lines per screen, with the u8g2 graphical font and buffer dumpsā€¦ but becasue it needs manual cursor placement for a new line, everything just scrolls along the top line of the screen and instantly becomes unreadable

I just canā€™t get my head around the complexity of pipes and redirects, etc. in order to figure out how to detect any end of line commands in the stdout buffer or in the BLYNK_PRINT routine :confounded:

So, while I have a nice if() routine to scroll the cursor, one line at a time, I canā€™t trigger it as necessary.

Much more hassle then worth for my limited LCD :stuck_out_tongue: But a good ā€œmake brain workā€ project :exploding_head:

So if anyone has insight into simply detecting a EOL '\n' in the outgoing serial buffer or BLYNK_PRINT routine, in a way that an if() loop can utilise, that would be appreciated.

Donā€™t use if, use while :wink: That way you can loop until \n

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

Something like that I think

That works for something like an incoming Serial bufferā€¦ but what I am dealing with is how @vshymanskyy was processing the BLYNK_PRINT. But instead ofā€¦

BLYNK_PRINT Serial;

or his use ofā€¦

BLYNK_PRINT Screen

I am usingā€¦

BLYNK_PRINT u8g2  // U8g2: Library for monochrome displays

void setup() {
  u8g2.begin();
  u8g2.enableUTF8Print();  // Activates UTF8 support for the Arduino print function
//...
}

So, no easy (for me) access to the stdout buffer that handles the Arduino Print() function (as I understand it).

I am tweaking the code I have before posting itā€¦ so far I am getting some resultsā€¦ just not the holy grail of the Blynk logo :stuck_out_tongue_winking_eye:

Hmm, ok I see your issue. I donā€™t have a 5110 screen handy, I used that Nokia to reinforce the house I live inā€¦

1 Like

2nd best use of it :stuck_out_tongue_winking_eye:

Well, I am getting furtherā€¦ but have to use DEBUG to get any real data

Have you seen this library:

It says it has ā€˜experimentalā€™ support for the Nokia display.

Pete.

That library looks niceā€¦ I think I will experiment with it and some of my TFT displaysā€¦ problem is they are Arduino shields and I donā€™t think they are SPI or i2Cā€¦ canā€™t remember.

Well, until I can suss out the proper EOL timing, this is the best I can get without flooding Debug data at itā€¦ and even then it doesnā€™t actually print in the proper line order all the time (note the ms times are out of order).

But something with the EOL must be automatically being accounted for in the buffer dumpā€¦everything lines up to the left margin properlyā€¦ :thinking:

My dream of a ā€œportableā€ Blynk status and debug monitor is still out of my graspā€¦ with this cutting edge screen at least :wink: But as stated, it is good fearningā€¦ I am learning to not toss the thing out the window :stuck_out_tongue_winking_eye:

#include <SPI.h>  // For LCD
#include <U8g2lib.h>  // For LCD
U8G2_PCD8544_84X48_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 16, /* dc=*/ 4, /* reset=*/ 17);  // Nokia 5110 Display

#define BLYNK_PRINT u8g2
//#define BLYNK_DEBUG

#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[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
int line;
int height = 6;
BlynkTimer timer;
WidgetRTC rtc;

void setup() {
  u8g2.begin();
  u8g2.enableUTF8Print();  // Set for Arduino Print() support
  u8g2.setFont(u8g2_font_u8glib_4_hf);  // Choose a suitable font
  u8g2.drawFrame(0, 0, 83, 47);  // Draw Frame
  line = height;

  Blynk.begin(auth, ssid, pass, "xxx.xxx.xxx.xxx", 8442);

  rtc.begin();
  setSyncInterval(30);  // Show somthing on the screen every 30 seconds (Time Sync: OK)
 
  timer.setInterval(100, []() {  // Up Time
    Blynk.virtualWrite(V1, millis() / 1000);
  });
  
  ArduinoOTA.setHostname("Lolin32");  // For OTA
  ArduinoOTA.begin();  // For OTA
}

void loop()
{
  u8g2.setCursor(0, line);// Sets the left/bottom start point for first character
  u8g2.sendBuffer();  // this is what dumps data the th LCD

  // Makeshift... line shifter
  line += height;
  if (line > 48) {
    line = height;
  }

  Blynk.run();
  timer.run();
  ArduinoOTA.handle();  // For OTA
}

BLYNK_WRITE(V0) {  // Optional frame and screen clear
  if (param.asInt() == 1) {
    u8g2.drawFrame(0, 0, 83, 47);  // Draw Box
  } else {
    u8g2.clearDisplay();
  }
}
1 Like

off topic: How much does that heat-sink help?
Temps before/after?

@Gunner
which LCD are you using?
which library are you using?
i have used Adafruit_GFX & Adafruit_PCD8544 Libraries for my project.

Negligible at bestā€¦ without it the metal casing never gets above 39Ā°C I just put the heat sink there cuz it was rattling around on my desk otherwise :wink:

Now the little regulator, that gets hot :fire: ā€¦ but then I am also using the ESP32 to power a 3.3v rail on the breadboard for a ESP-01 as I donā€™t have any other regulators.

1 Like

It is a Chineseium Nokia knockoff PCD-8544

And the library for this project is the aformentioned u8g2 because it has the needed, for this application, UTF8 support for the Arduino print function.

@vshymanskyy I think I am in the right direction in looking for syncing EOL and my own cursor positioning,

But I am not well versed in C++ to both discover the correct point (without insight) wherein I might intercept and and interpret (I am working on that via Google) the outgoing characters from BLYNK_PRINT to the target (i.e. Serial, Serial1, Screen, u8g2, etc).

At this point I would like to simultaneously and internally (via code) monitor the output as well as react to specific characters in said output.

I have found a few files locations in the Blynk Library, based on a simple search of BLYNK_PRINT, but can you, or someone, point me to the correct file, and perhaps correct segment of said file, where the characters are actually passed on?

@Gunner
The easiest way is to define your own custom console object:

// Lets define a custom console
class CustomConsole
    : public Print // This automatically adds functions like .println()
{
public:
    CustomConsole() {}

    virtual size_t write(uint8_t ch) {
        // Process symbols here:
        //if (ch == '\n') ...
        return 1; // <- this means we processed 1 symbol
    }
private:
    // Here you can define some variables you want to use in your console
    int cursorY = 0;
    int cursorX = 0;
};

// Now we instantiate it
CustomConsole myConsole;

// And use for Blynk output
#define BLYNK_PRINT myConsole

... [rest of the sketch] ...

These print(), println() functions are added from Print class, and it will call your write function every time it wants to print a symbol. You can then apply your own logic of any complexity :wink:

P.S. Another example of how this approach is used in Blynk library, is WidgetTerminal.

1 Like

Getting closerā€¦

1 Like

Well thank you @vshymanskyy Once I got my head around it, I made it work with this wee little LCD.

Not much practical use on such a small screen, but all output is more or less readable :wink: Larger font at the start for a logo that, while truncated, is all lined upā€¦ then to a smaller font for ā€œnormalā€ serial output.

Nice thing is, this should work on any size LCD that the u8g2 Library supports.

And for anyone interested, here is the code.

Much of my if() checking is just for displaying the Blynk Logo the way I wanted it :stuck_out_tongue_winking_eye: and could be discarded to simplify the print output, which scrolls line by line until at the bottom, then clearing and starting from the top.

#include <SPI.h>  // For LCD
#include <U8g2lib.h>  // For LCD
U8G2_PCD8544_84X48_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 16, /* dc=*/ 4, /* reset=*/ 17);  // Nokia 5110 Display

// Define a custom console for LCD debug output
class CustomConsole
  : public Print // This automatically adds functions like .println()
{
  public:
    CustomConsole() {}
    virtual size_t write(uint8_t ch) {  // Grabs character from print?
      u8g2.print(char(ch));  // Add character to LCD buffer
      Serial.print(char(ch));  // Repeat all character output to Serial monitor
      if (char(ch) == ']') {  // Watch for closing brackets
        x++;  // Increment bracket count
        if (x == 4) {  // If after forth closing bracket on millis count...
          line -= height;  // ... backstep one line to fit Blynk Logo on screen
        }
      }
      if (ch == '\n') {  // End of line check
        line += height;  // Increment next line down
        u8g2.sendBuffer();  // Dump buffer to LCD
        if (line >= 49) {  // Last line on screen check
          if (x == 4) {  // If after fourth closing bracket on millis count...
            delay(10000);  // ... delay 10 seconds to view Blynk Logo
            u8g2.setFont(u8g2_font_u8glib_4_hf);  // set font to smaller size for remainder of debug prints
            u8g2.clearDisplay();  // Clear display
          }
          u8g2.sendBuffer();  // Dump buffer to LCD
          u8g2.setCursor(0, height);  // Reset line to top of screen
          line = height;  // Reset line counter
          delay(500);  // Small delay to allow visual of last line output on LCD
          u8g2.clearDisplay();  // Clear display
        } else {
          u8g2.sendBuffer();  // Dump buffer to LCD
          u8g2.setCursor(0, line);  // Set curser to next line down
        }
      }
      return 1; // Processed 1 character
    }
  private:
    // Here you can define some variables you want to use in your console
    int x = 0;  // bracket counter
    int line;  // line counter
    int height = 6;  // Line pixel height
};

// Now we instantiate it
CustomConsole myConsole;

#define BLYNK_PRINT myConsole
//#define BLYNK_DEBUG

#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[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "xxx.xxx.xxx.xxx";
int line;
int height = 6;  // Line pixel height
BlynkTimer timer;
WidgetRTC rtc;

void setup() {
  line = height;  // Reset line counter
  Serial.begin(115200);
  u8g2.begin();  // Start LCD library
  u8g2.enableUTF8Print();  // Activates UTF8 support for the Arduino print function
  u8g2.setFont(u8g2_font_micro_mr);  // choose a suitable font for Logo
  u8g2.setCursor(0, 6);  // Sratrt at top line of LCD

  //Blynk.connectWiFi(ssid, pass);
  //Blynk.config(auth, server, 8442);
  Blynk.begin(auth, ssid, pass, server, 8442);
  rtc.begin();
  setSyncInterval(30);  // Time Sync - not working with Blink.config()??
  BLYNK_LOG("Hello Gunner");  // Say Hello

  timer.setInterval(1000, []() {  // Up Time
    Blynk.virtualWrite(V1, millis() / 1000);  // Display Uptime in seconds
    BLYNK_LOG("Hello Gunner");  // Initial message
    //u8g2.print(WiFi.RSSI());  // Optional RSSI strength 
  });

  ArduinoOTA.setHostname("Lolin32");  // For OTA
  ArduinoOTA.begin();  // For OTA
}

void loop() {
  Blynk.run();
  timer.run();
  ArduinoOTA.handle();  // For OTA
}
5 Likes

Yes! it verx! ā€¦ one of the purposes of this was to eventually have a localised (aka On Device) debug of things normally only seen on the Serial monitorā€¦

So somehow, my device lost connectionā€¦ considering it does nothing right now but (supposedly) regularly sync the timeā€¦ but refuses to say so?? 'nother issue 'nother day :wink:

I still have it plugged into the PC for testingā€¦ so it was nice to compare the twoā€¦

image

OH, Lookā€¦ Something? happened after a really big number :stuck_out_tongue: ā€¦ Now all I need is a higher resolution LCD, or a nice wide format OLEDā€¦ added to my Christmas list.

1 Like

Need something compact, enough screen real estateā€¦ but affordable for individual device useā€¦

Probably still not big enough?? But might work with reduced font.

I like the idea! In spare time will try to use my brand new (but already 2 years oldā€¦) UC1608 240x128 display supported by u8glib. Will Blynk logo fit on that? :laughing:

1 Like