BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Writing long message from terminal widget to OLED

Hello everyone,

I’m trying to send messages longer than 128 pixels from terminal widget to 0.96" OLED and have the entire message scroll across the screen. OLED is connected to Wemos D1 mini.

I’m having trouble compiling this code as I don’t know how to properly define message as param.asStr() on V1. I’m not a coder, all this is copy/paste from other projects people have done. Anyone has any ideas?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define BLYNK_MAX_SENDBYTES 256 // Default is 128

bool mssg;
char message;
int x, minX;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "my token";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "my ssid";
char pass[] = "my password";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

BLYNK_WRITE(V1) 
{
    if (String("text") == param.asStr())//Initiate OLED transfer
  {
    display.clearDisplay();
    terminal.println(F("Enter Message"));
    mssg=true;
    terminal.flush();
  }
  
  if(mssg==true&&(String("text") != param.asStr()) )//Prints To OLED
    {
    message = param.asStr();
    display.clearDisplay();
     //x=x-2; // scroll speed, make more positive to slow down the scroll
   //if(x < minX) x= display.width();
    display.setCursor(0,32);
    display.print(param.asString());
    display.display();
    mssg=false;
    }
    if(--x < minX) x = display.width();
}

void setup()
{
  Serial.begin(115200);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  //display.startscrollleft(0x00, 0x0F);
  x = display.width();
  minX = -12 * strlen(message);  // 12 = 6 pixels/character * text size 2
 
  Blynk.begin(auth, ssid, pass);
  // You can also specify server;
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Clear the terminal content
  terminal.clear();

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type your command>"));
  terminal.flush(); 
}

void loop()
{
  Blynk.run();   
}

Do you have code that works without Blynk?
I think that is your first step.

Yes, I have code without Blynk and that works fine. But this code without Blynk has fixed message:

char message [] = “my loooooooong message”

And then string length gets determined from this.

What I want to do is determine string length from whatever length message gets sent from terminal. If I get rid of this scroll requirement, I can send message from Blynk terminal to fixed OLED as well but with font size 2 there is very limited number of characters that fit on screen.

Can I do this:

#define message = V1

Because terminal is on V1.

And then in BLYNK_WRITE(V1) say:

message=param.asStr()

I tried lots of different things to resolve this issue to no avail. I’m still not able to compile code that is supposed to send text message longer than OLED width and scroll it across the screen. This is the code I have and I’m sure it is in how message variable is defined:

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define BLYNK_MAX_SENDBYTES 256 // Default is 128
#define message V1


bool mssg;
String message;
int x, minX;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "my token";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "my SSID";
char pass[] = "my password";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// Select your pin with physical button
const int btnPin = 2;

WidgetLED led1(V2);

BlynkTimer timer;

// V2 LED Widget represents the physical button state
boolean btnState = false;
void buttonLedWidget()
{
  // Read button
  boolean isPressed = (digitalRead(btnPin) == LOW);

  // If state has changed...
  if (isPressed != btnState) {
    if (isPressed) {
      led1.on();
    } else {
      led1.off();
    }
    btnState = isPressed;
  }
}

BLYNK_WRITE(V1) 
{
    if (String("text") == param.asStr())//Initiate OLED transfer
  {
    display.clearDisplay();
    terminal.println(F("Enter Message"));
    mssg=true;
    terminal.flush();
  }
  
  if(mssg==true&&(String("text") != param.asStr()) )//Prints To OLED
    {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("message");
    display.display();
    x=x-2; // scroll speed, make more positive to slow down the scroll
    if(--x < minX) x= display.width();
    mssg=false;
    }
    //if(--x < minX) x = display.width();
}

void setup()
{
  Serial.begin(115200);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  //display.startscrollleft(0x00, 0x0F);
  x = display.width();
  minX = -12 * strlen(message);  // 12 = 6 pixels/character * text size 2
 
  Blynk.begin(auth, ssid, pass);
  // You can also specify server;
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Clear the terminal content
  terminal.clear();

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type your command>"));
  terminal.flush(); 

    // Setup physical button pin (active low)
  pinMode(btnPin, INPUT_PULLUP);
  timer.setInterval(150L, buttonLedWidget);
}

void loop()
{
  Blynk.run();
  timer.run();   
}

This is the error I get:

exit status 1
invalid conversion from 'int' to 'const char*' [-fpermissive]

On this line:

minX = -12 * strlen(message); // 12 = 6 pixels/character * text size 2

What I’m trying to do is build a small WiFi pager (Wemos D1 mini with OLED, active speaker, and button for message confirmation. I have this working without scroll requirement but it would function a lot better if I use larger text and scroll it across the screen.

Thanks