BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

LCD Is not working without WIFI

Hello,
lcd is not working.
it works only after connecting to the wifi network and I would like the lcd to work independently

#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BlynkSimpleEsp8266.h>
#include <Timers.h>

#define BLYNK_PRINT Serial
#define D1 5
#define D2 4
#define D3 0
#define treconnect 30

float tempC = 0;
int liczreconnect = 10;

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxx";
char pass[] = "xxx";


LiquidCrystal_I2C lcd(0x27, 20, 4);
OneWire oneWire(0);
DallasTemperature sensors(&oneWire);
Timers <3> akcja;

BlynkTimer timer;

int stanLED_ok=0;
int LED;


void setup()
{


 
Serial.begin(9600);
lcd.backlight();
sensors.begin();
lcd.init();
lcd.clear();
Serial.println(LED);
Blynk.begin(auth, ssid, pass);
}


//Blynk.syncAll();


void loop() {

sensors.requestTemperatures();
float TEMP1 = sensors.getTempCByIndex(0);
float TEMP2 = sensors.getTempCByIndex(1);
float TEMP3 = sensors.getTempCByIndex(2);
float TEMP4 = sensors.getTempCByIndex(3);

lcd.setCursor(0, 0);
lcd.print("TEMP1");
lcd.setCursor (9, 0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print((char)223);
lcd.print("C");

lcd.setCursor(0,1);
lcd.print("TEMP2");
lcd.setCursor (9, 1);
lcd.print(sensors.getTempCByIndex(1));
lcd.print((char)223);
lcd.print("C");

lcd.setCursor(0,2);
lcd.print("TEMP3");
lcd.setCursor (9, 2);
lcd.print(sensors.getTempCByIndex(2));
lcd.print((char)223);
lcd.print("C");

lcd.setCursor(0,3);
lcd.print("TEMP4");
lcd.setCursor (9, 3);
lcd.print(sensors.getTempCByIndex(3));
lcd.print((char)223);
lcd.print("C");

Blynk.run();
Blynk.virtualWrite(V1, TEMP1);
Blynk.virtualWrite(V2, TEMP2);
Blynk.virtualWrite(V3, TEMP3);
Blynk.virtualWrite(V4, TEMP4);

delay(30);


Blynk.run();
timer.run();
}

Please edit your post and add triple backticks ( ``` ) before and after your whole sketch.

First of all, both blynk.begin and blynk.run are blocking functions, so internet connection is required.

Second thing, you should read this
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

Old Blynk works no problem but connecting was

Blynk.config(auth, "blynk-cloud.com", 8442);

Blynk.connect();
if (Blynk.connected()) Blynk.run(); else Blynk.connect();
  
Serial.begin(9600);
lcd.backlight();
sensors.begin();
lcd.init();
lcd.clear();
Serial.println(LED);
timer.setInterval(1000L, temp);

but I cant’ connect to new blynk in the same code. So have to put

Blynk.begin(auth, ssid, pass);

Blynk-cloud.com is the old blynk server, the new blynk server is blynk.cloud
also, Blynk uses 443 port for TLS connections and 80 port for plain connections

1 Like

the new blynk server is blynk.cloud
also, Blynk uses 443 port for TLS connections and 80 port for plain connections

doesn’t work

First of all, both blynk.begin and blynk.run are blocking functions, so internet connection is required

other connection option?

Have you tried Blynk.config(auth); ?

1 Like

Maybe if you shared your code it would help.
Are you manually configuring your WiFi connection first?

Blynk.config and Blynk.connect do work with Blynk IoT, I’ve tried it myself.

Pete.

1 Like

It works
Thank you very much for your help !!

1 Like

Please share the solved code if possible.

@Kamran the hardware that @zkz is using is a NodeMCU. As a said to you in a different topic, your life would be much easier if you were also using a NodeMCU or ESP32.

When you use an Arduino + ESP-01 which is functioning as a WiFi modem in AT mode then you have very limited control over your WiFi system.

Pete.

Hello again.

Another problem. I need to use wifi.manager to manual connect to WIFI.
And it’s the same problem. LCD only works when connected to wifi.
Is it possible to make a code to work lcd with temperature without connecting to wifi?

Yes.

But as you aren’t telling us what changes you made to add WiFi manager to your existing sketch, or even shared you working sketch prior to adding-in WiFi Manager, its impossible to explain how to do this in your case.

BTW, have you looked at Blynk Edgent as an alternative to WiFi Manager?

Pete.

code.
My dream is.
“Put ssid and pass, and if Wi-Fi is not connected, make AP - Wi-Fi manager… but LCD must work all the time.”

of course only wifi manager is enough

#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BlynkSimpleEsp8266.h>
#include <Timers.h>

#define BLYNK_PRINT Serial
#define D1 5 
#define D2 4 
#define D3 0 
#define treconnect 30 

float tempC = 0;
int liczreconnect = 10;
char auth[] = BLYNK_AUTH_TOKEN;
//char ssid[] = "xxx"; 
//char pass[] = "xxx"; 


LiquidCrystal_I2C lcd(0x27, 20, 4);
OneWire oneWire(0);
DallasTemperature sensors(&oneWire); 
Timers <3> akcja;

BlynkTimer timer;

int stanLED_ok=0;
int LED;

void setup() {
  

  
Serial.begin(9600);
lcd.backlight();
sensors.begin();
lcd.init();
lcd.clear();
Serial.println(LED);



// put your setup code here, to run once:
    Serial.begin(115200);
      WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
    // it is a good practice to make sure your code sets wifi mode how you want it.

Blynk.config(auth);

Blynk.connect();
if (Blynk.connected()) Blynk.run(); else Blynk.connect();
    //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wm;

    // reset settings - wipe stored credentials for testing
    // these are stored by the esp library
    wm.resetSettings();

    // Automatically connect using saved credentials,
    // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
    // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
    // then goes into a blocking loop awaiting configuration and will return success result

    bool res;
    // res = wm.autoConnect(); // auto generated AP name from chipid
    // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
    res = wm.autoConnect("AutoConnectAP","password"); // password protected ap

    if(!res) {
        Serial.println("Failed to connect");
        // ESP.restart();
    } 
    else {
        //if you get here you have connected to the WiFi    
        Serial.println("connected...yeey :)");
    }

}

void loop() {
    // put your main code here, to run repeatedly:   
sensors.requestTemperatures();
float TEMP1 = sensors.getTempCByIndex(0);
float TEMP2 = sensors.getTempCByIndex(1);
float TEMP3 = sensors.getTempCByIndex(2);
float TEMP4 = sensors.getTempCByIndex(3);

lcd.setCursor(0, 0);
lcd.print("TEMP1");
lcd.setCursor (9, 0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" C");
 
lcd.setCursor(0,1);
lcd.print("TEMP2");
lcd.setCursor (9, 1);
lcd.print(sensors.getTempCByIndex(1));
lcd.print(" C");

lcd.setCursor(0,2);
lcd.print("TEMP3");
lcd.setCursor (9, 2);
lcd.print(sensors.getTempCByIndex(2));
lcd.print(" C");

lcd.setCursor(0,3);
lcd.print("TEMP4");
lcd.setCursor (9, 3);
lcd.print(sensors.getTempCByIndex(3));
lcd.print(" C");

Blynk.run();
Blynk.virtualWrite(V1, TEMP1);
Blynk.virtualWrite(V2, TEMP2);
Blynk.virtualWrite(V3, TEMP3);
Blynk.virtualWrite(V4, TEMP4);

delay(30);

akcja.process(); //timer Timers.h
if (Blynk.connected()) {
Blynk.run();
timer.run();
}
}

Void loop :scream::scream::scream:

And where is your working sketch without WiFi manager?

If that means that only WiFiManager can achieve this for you then you clearly haven’t looked at Blynk Edgent as I suggested.

Pete.

:rofl::rofl::rofl:

Love the idea of trying to read 4 sensors ever 30ms, and that fact that there a BlynkTimer declared and fed in the void loop, but not used :confused:

Pete.

2 Likes

And where is your working sketch without WiFi manager?

#define BLYNK_DEVICE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BlynkSimpleEsp8266.h>
#include <Timers.h>

#define BLYNK_PRINT Serial
#define D1 5
#define D2 4
#define D3 0
#define treconnect 30

float tempC = 0;
int liczreconnect = 10;

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxx";
char pass[] = "xxx";


LiquidCrystal_I2C lcd(0x27, 20, 4);
OneWire oneWire(0);
DallasTemperature sensors(&oneWire);
Timers <3> akcja;

BlynkTimer timer;

int stanLED_ok=0;
int LED;


void setup()
{


 
Serial.begin(9600);
lcd.backlight();
sensors.begin();
lcd.init();
lcd.clear();
Serial.println(LED);
WiFi.begin(ssid, pass);
Blynk.config(auth);
Blynk.connect();
if (Blynk.connected()) Blynk.run(); else Blynk.connect();
}


//Blynk.syncAll();


void loop() {

sensors.requestTemperatures();
float TEMP1 = sensors.getTempCByIndex(0);
float TEMP2 = sensors.getTempCByIndex(1);
float TEMP3 = sensors.getTempCByIndex(2);
float TEMP4 = sensors.getTempCByIndex(3);

lcd.setCursor(0, 0);
lcd.print("TEMP1");
lcd.setCursor (9, 0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print("C");

lcd.setCursor(0,1);
lcd.print("TEMP2");
lcd.setCursor (9, 1);
lcd.print(sensors.getTempCByIndex(1));
lcd.print("C");

lcd.setCursor(0,2);
lcd.print("TEMP3");
lcd.setCursor (9, 2);
lcd.print(sensors.getTempCByIndex(2));
lcd.print("C");

lcd.setCursor(0,3);
lcd.print("TEMP4");
lcd.setCursor (9, 3);
lcd.print(sensors.getTempCByIndex(3));
lcd.print("C");

Blynk.run();
Blynk.virtualWrite(V1, TEMP1);
Blynk.virtualWrite(V2, TEMP2);
Blynk.virtualWrite(V3, TEMP3);
Blynk.virtualWrite(V4, TEMP4);

delay(30);


Blynk.run();
timer.run();
}

and this actually works?
You appear to be missing quite a lot of WiFi connection code that loops in a while or for loop until WiFi.status() != WL_CONNECTED

Your WiFi manager code seems to have abandoned the concept of connecting to WiFi altogether, so I can’t see how it could ever work, unless it’s using the WiFi credentials that the ESP stores in is NVR.

Even when you sort this out, your void loop is appalling and breaks all the rules of Blynk, so your sketch needs some serious restructuring.

I keep asking this, but have you looked at the Blynk Edgent example?

Pete.

1 Like

Blynk Edgent - no working :frowning: