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

Weird behavior!

Hey my daughter and I are messing around, trying to teach her the basics of IoT. We tapped up some code to increment a counter and display it and also reset the counter. In the code for printing we did lcd.print(0,0,"Counter =" + counter); It started printing my SSID, password, Blynk version etc. Can someone tell me why it does this? Full code below.

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#ifndef STASSID
#define STASSID "8888888888888"
#define STAPSK  "***********"
#endif

int counter = 0;
const char* ssid = STASSID;
const char* password = STAPSK;
char auth[] = "***********";

#define onboardLED D4

WidgetLCD lcd (V0);

void setup() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    delay(5000);
    ESP.restart();
  }
  ArduinoOTA.setHostname("sab");
  Blynk.begin(auth,STASSID,STAPSK);
  ArduinoOTA.begin(); 
  lcd.clear();
  lcd.print(0,0, "sab started");
  Blynk.syncAll();
  pinMode(onboardLED,OUTPUT);
  }

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

BLYNK_WRITE(V1){
  if (param.asInt()==1) {
    lcd.clear(); 
  }
}

BLYNK_WRITE (V2){
  if  (param.asInt()==1){
    lcd.clear();
    counter+=2;
    lcd.print(0,0,"Counter =" + counter);  
  }
}

We can help you, but what is your question? where is the issue ? :thinking:

BLYNK_WRITE(V1){
  if (param.asInt()==1) {
    lcd.clear(); 
counter=0; // to reset
  }
}

In the V2 function this print line I was hoping to print a string then the variable but instead on the button poll it prints random data as per previous post. :point_up:

Try that :
lcd.print(0,0,“Counter =” + String(counter));

2 Likes

Yea, thanks, just mystified that it started pulling SSID, password etc. with that command.

1 Like

Just a guess, but with the originally coded line you may have inadvertently been generating incrementing memory/variable designations instead of a string & variable, and thus the code was printing whatever string matched the generated value?

2 Likes