Wemos and Wifi message box

Hi everyone,

At first sorry for my bad english because i am from France. I’ll do my best for explaining my problem.

I am doing a message box. in fact i send a text via Blynk app with the textIn widget and I receive it on a physical LCD and a led call me when a new message is received.
I a am using a Wemos D1 mini

it works well, very well but only if i download the code and if i use it right now.
When i unplug the power to put it on a other power source or simply switch it off and switch it on, the Wemos can’t find the wifi connection.
But if i plug it to my computer and RE-download the sketch it works (if only the wemos stay plugged)…

Could you please help me?

Thank you for all you can do for me

I send you the code if it helps you but for me its works good:

#include <LiquidCrystal_I2C.h> // bibliothèque ecran I2C
#include <Wire.h> // bibliothèque I2C
LiquidCrystal_I2C lcd(0x3F, 16, 2); // adresse I2C et type de LCD
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> // bibliotheque du timer

char auth[] = "help"; // code du projet
char ssid[] = "help"; // nom du reseau
char pass[] = "help";// mot de passe

SimpleTimer timer; // definition nom du timer
int etatbouton = 0; // etat du bouton 

bool recu = false; // booleen du message recu via l'application



void checkbouton() { // boucle du test etat bouton

  etatbouton = digitalRead(D3); // lecture etat bouton

  if (etatbouton == HIGH) { // si bouton appuyé
    Serial.println("appui"); // ecrit dans le port serie "appui"
    lcd.noBacklight(); // eteinte du fond d'ecran
    lcd.noDisplay(); // et de l'ecriture

  }
  else { // sinon
    Serial.println("pas d'appui"); //ecrit dans le port serie "pas dappui"
    lcd.backlight(); // allumage fond d'ecran
    lcd.display(); // et de l'ecriture
    digitalWrite(D7, LOW); // eteinte de la led qui est D7
    recu = false; // mise en etat Faux du message recu

  }

}

void setup()
{
  lcd.begin(); // initialisation lcd
  lcd.backlight();// mise en marche du fond d'ecran
  timer.setInterval(500, checkbouton); // declaration de l'intervalle
  //du controle de l'etat du bouton ici 500ms
  pinMode(D3, INPUT); // declaration du bouton en D3 il recoit l'info
  pinMode(D7, OUTPUT); // declaration de la led en D7 elle envoi l'info
  
  Serial.begin(9600);// initialisation du port serie
  Blynk.begin(auth, ssid, pass); // initialisation de Blynk avec les
  // identifiants

  Serial.print("Blynk Ready\n"); // ecrit dans le port serie que Blynk
  // est connecté une fois les etapes d'authentification validées
}
BLYNK_WRITE(V0) { // la pin virtuelle V0 ecrit: 
  lcd.clear();// nettoyage de l'ecran
  String textIn = param.asStr(); // les parametre recus de lapp (param.Str)
  // sont logés dans une ligne de lettres (string) sous le nom de TextIn
  Serial.print(textIn + "\n"); // ecrit ce texte dans le port serie 
  char val_1[21]; // partie de code pour que selon le nombre de caractere
  char val_2[21];// cela secrive sur plusieurs lignes
  char val_3[21];// en fonction du type d'ecran
  char val_4[21];
  String row1 = textIn.substring(0, 20); // ici pour un ecran de 20x4
  String row2 = textIn.substring(20, 40);
  String row3 = textIn.substring(40, 60);
  String row4 = textIn.substring(60, 80);
  row1.toCharArray(val_1, 21);
  row2.toCharArray(val_2, 21);
  row3.toCharArray(val_3, 21);
  row4.toCharArray(val_4, 21);
  lcd.setCursor(0, 0);
  lcd.print(val_1);
  lcd.setCursor(0, 1);
  lcd.print(val_2);
  lcd.setCursor(0, 2);
  lcd.print(val_3);
  lcd.setCursor(0, 3);
  lcd.print(val_4);
  recu = true; // uen fois le texte recu, passage en etat true
}


void loop() {

  Blynk.run(); // faire tourner le code prorpe a Blynk
  timer.run(); // idem pour le timer
  if (recu == true && etatbouton == HIGH) { // si il y a un 
    // message recu et que le bouton est appuyé
    digitalWrite(D7, HIGH);// on fait clignoter la led intervalle de 500ms
    delay(500);
    digitalWrite(D7, LOW);
    delay(500);
  }
}```

First of all, your void loop is terrible.
Read this:

Secondly, how are you connecting power to your Wemos, and to your LCD display?

Pete.

Hi Pete,

And thanks again and again for your help with my projects.

So i modify my terrible loop just after reading the link you send me.
My wemos is connected to the USB port and my LCD directly on my wemos ( with my others projects it works).

Even with the modifications i’ve done ( for the loop) the problem is the same, it works well just after downloading the sketch but when i switch off and the on, Blynk told me “wemos is offline” and i can’t reconnect it. Unless i redownload the code and don’t unplug the wemos.

here is my modify code:

#include <LiquidCrystal_I2C.h> // bibliothèque ecran I2C
#include <Wire.h> // bibliothèque I2C
LiquidCrystal_I2C lcd(0x3F, 16, 2); // adresse I2C et type de LCD
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> // bibliotheque du timer

char auth[] = "help"; // code du projet
char ssid[] = "help"; // nom du reseau
char pass[] = "help";// mot de passe

SimpleTimer timer; // definition nom du timer
int etatbouton = 0; // etat du bouton

bool recu = false; // booleen du message recu via l'application



void checkbouton() { // boucle du test etat bouton

  etatbouton = digitalRead(D3); // lecture etat bouton

  if (etatbouton == HIGH) { // si bouton appuyé
    Serial.println("appui"); // ecrit dans le port serie "appui"
    lcd.noBacklight(); // eteinte du fond d'ecran
    lcd.noDisplay(); // et de l'ecriture

  }
  else { // sinon
    Serial.println("pas d'appui"); //ecrit dans le port serie "pas dappui"
    lcd.backlight(); // allumage fond d'ecran
    lcd.display(); // et de l'ecriture
    digitalWrite(D7, LOW); // eteinte de la led qui est D7
    recu = false; // mise en etat Faux du message recu
  }
}

  void averti(){
  if (recu == true && etatbouton == HIGH) { // si il y a un
    // message recu et que le bouton est appuyé
    digitalWrite(D7, HIGH);// on fait clignoter la led intervalle de 500ms
    delay(500);
    digitalWrite(D7, LOW);
    delay(500);
  }
  }



void setup()
{
  lcd.begin(); // initialisation lcd
  lcd.backlight();// mise en marche du fond d'ecran
  timer.setInterval(500, checkbouton); // declaration de l'intervalle
  //du controle de l'etat du bouton ici 500ms
  timer.setInterval(500, averti);
  pinMode(D3, INPUT); // declaration du bouton en D3 il recoit l'info
  pinMode(D7, OUTPUT); // declaration de la led en D7 elle envoi l'info

  Serial.begin(9600);// initialisation du port serie
  Blynk.begin(auth, ssid, pass); // initialisation de Blynk avec les
  // identifiants

  Serial.print("Blynk Ready\n"); // ecrit dans le port serie que Blynk
  // est connecté une fois les etapes d'authentification validées
}
BLYNK_WRITE(V0) { // la pin virtuelle V0 ecrit:
  lcd.clear();// nettoyage de l'ecran
  String textIn = param.asStr(); // les parametre recus de lapp (param.Str)
  // sont logés dans une ligne de lettres (string) sous le nom de TextIn
  Serial.print(textIn + "\n"); // ecrit ce texte dans le port serie
  char val_1[21]; // partie de code pour que selon le nombre de caractere
  char val_2[21];// cela secrive sur plusieurs lignes
  char val_3[21];// en fonction du type d'ecran
  char val_4[21];
  String row1 = textIn.substring(0, 20); // ici pour un ecran de 20x4
  String row2 = textIn.substring(20, 40);
  String row3 = textIn.substring(40, 60);
  String row4 = textIn.substring(60, 80);
  row1.toCharArray(val_1, 21);
  row2.toCharArray(val_2, 21);
  row3.toCharArray(val_3, 21);
  row4.toCharArray(val_4, 21);
  lcd.setCursor(0, 0);
  lcd.print(val_1);
  lcd.setCursor(0, 1);
  lcd.print(val_2);
  lcd.setCursor(0, 2);
  lcd.print(val_3);
  lcd.setCursor(0, 3);
  lcd.print(val_4);
  recu = true; // uen fois le texte recu, passage en etat true
}


void loop() {

  Blynk.run(); // faire tourner le code prorpe a Blynk
  timer.run(); // idem pour le timer

}

What happens if you disconnect the LCD from the Wemos, does the Wemos connect to Blynk after a reboot?

Pete.

thanks Pete for your answer,

The problem is the same, even if i disconnect the LCD.
It works and the wemos is connected juste after the download

Are you powering the Wemos via USB from the PC when you can’t get a re-connection, or from an external PSU?

Pete.

Also, what do you see in your serial monitor if you set your baud rate to 74880 in the sketch and the serial monitor?

Have you tried uploading with the “Erase Flash - All Flash Contents” option?

Pete.

i tried different things when i can’t get a reconnection,
I tried the USB from my PC, a power bank and the power from my house ( i don’t how to say that in english) via the phone charger

It is the same things with de 74800 baud ( modified in sketch and serial monitor):

i tried with the ““Erase Flash - All Flash Contents”” option unfortunately i can’t again when i reboot :disappointed_relieved:

So do you see anything in the serial monitor (if the serial monitor is already open then close it and re-open).
Do you see anything in the serial monitor when you press the reset button?
If so, then post it here.

Pete.

thank again Pete for the time you spend for me.

Here is what is written in ne serial monitor just after a reset:
" ets Jan 8 2013,rst cause:2, boot mode:(1,6)"

If you move the Serial.begin to the beginning of void setup, do you get any different output in the serial monitor?

If not, then have you tried a simple sketch instead?

Pete.

Hi Pete,
So i tried to put Serial.begin at the beginning of the void setup but nothing changes, i have the same message in the serial monitor.

Then i tried with 2 different simple sketches and i have the same issue. It works just after the download but if i switch off and then on, i can’t reconnect it to the wifi.

But what is strange is that before with a simple sketch project i could switch off and on for replugging it on a other power source i had no problem

It sounds as if you’re using the wrong settings in the Arduino IDE to flash your device, or your board has developed a fault.

Pete.

thanks Pete for your so quick answer,

Do you have any idea to fix it? lastly i’ll change the board

What settings are you using in the IDE?

Pete.

here is my settings

That looks fine.
You could check your board for solder bridges between pins, or splatter that’s caused small blobs of solder to short-out components, but otherwise you may need a new board.

It’s very rare for these boards top develop a problem. I have around 40 of them and I’ve only experienced one that developed a problem. You should obviously take normal anti-static precautions when handling them, and avoid applying 5v to the 3.3v pin.

Pete.

So i changed the board a brand new board,

The problem was the same, but i tried something different, I disconnected power of the display, then i plug the power of the wemos, i wait and he find the wifi connection.
Then i re-plugged the power of the display , the wemos stay connected but the display don’t works well (it is only full squares on the screen ).

So i looked at the serial monitor and i saw that :
"[82424] Heartbeat timeout
appui
appui
appui
appui
appui
[87393] Connecting to blynk-cloud.com:80
[87457] Ready (ping: 30ms).
appui
appui
"

I discover something new:

the wemos can connect only if i unplug the ground. once finding the connection, i replug the ground. and it stays connected.

But unfortunately the LCD doesn’t works while on the serial monitor it works perfectly

I’d previously asked you to disconnect everything from the Wemos. I thought that the tests you were doing after that were with just the Wemos board and nothing else!

Pete.