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

LCD Wemos and switch

I do this for my Physical LCD backlight using a virtual button.

LiquidCrystal_I2C PLCD(0x3F, 20, 4);
BLYNK_WRITE(V38) {
  int BL = param.asInt();
  if (BL == 1) {
    //Serial.println("LCD Backlight ON");
    PLCD.backlight();
  } else {
    //Serial.println("LCD Backlight OFF");
    PLCD.noBacklight();
  }
}

Thank you Gunner for your answer,

But i really need for my project that a physical button activate or deactivate the display.
In fact, this button il connected to a lid of a box, then when the lid is open, it activate the display and deactivate it when you close the box…

Do you have any idea for it?

with an arduino UNO no problem to do it, but with blynk and wemos i can’t do do it unfortunately.

What type of widget do you have attached to V0 in your app, how is it configured, and what role does this play in your process?

At the moment, your code won’t read the state of your physical switch unless the value of V0 changes, either because the user makes this change in the app, or because the widget is set to push its value on a regular basis.

Pete.

Hi Pete,
Thank you again for your answer.
I use the “text Input” widget, and connected it as you said before at V0.
the effect is when i write a texte in this widget it write this text on my physical display.

i need for my project that a physical button activate or deactivate the display.
In fact, this button il connected to a lid of a box, then when the lid is open, it activate the display and deactivate it when you close the box…

do you think i have to put this part of sketch in the loop ?( i already tried it):

etatbouton=digitalRead(3);
if (etatbouton == HIGH) {
  Serial.println("appui");
  lcd.noBacklight();
  lcd.noDisplay();
}
  else{
    Serial.println("pas d'appui");
    lcd.backlight();
    lcd.display();
  }

No, don’t put it in the loop!
Create a function and call it with a timer every 500ms.

Pete.

thanks Pete,

would you have the kindness to give me an example please?

Add this to your void loop:

timer.setInterval(500, Check_Switch_State);

and add this function:

void Check_Switch_State()
{
 your code to check the state of your switch in here....
}

Pete.

Hi Pete thank you again for your answer,
So i modified the sketch with your recommandation as you can see below but it doesn’t work unfortunately.
and in serial i don’t see “appui” or " pas appui".
only the text i’ve write in the widget is on the display and on the serial.

Thank you for your patience, really thank you.

Can you check what i’ve done please?

/* Comment this out to disable prints and save space */
#include <LiquidCrystal_I2C.h> // bibliothèque ecran I2C
#include <Wire.h> // bibliothèque I2C
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “help”;
char ssid[] = “help”;
char pass[] = “help”;

SimpleTimer timer;
int etatbouton = 0;

void checkbouton(){

etatbouton=digitalRead(D4);
if (etatbouton == HIGH) {
Serial.println(“appui”);
lcd.noBacklight();
lcd.noDisplay();
}
else{
Serial.println(“pas d’appui”);
lcd.backlight();
lcd.display();
}
}

void setup()
{
lcd.begin();
lcd.backlight();

pinMode(D4, INPUT);
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);

Serial.print(“Blynk Ready\n”);
}
BLYNK_WRITE(V0) {
lcd.clear();
String textIn = param.asStr();
Serial.print(textIn + “\n”);
lcd.setCursor(0, 0);
lcd.print(textIn);
}

void loop() {

Blynk.run();
timer.setInterval(500, checkbouton);

}

Sorry, I mis-typed last time, the timer declaration should be in your void setup, not void loop

Your void loop needs timer.run(); adding in.

Pete.

i corrected it now,

i can see in the serial " appui" and my display is in nodisplay() and noBacklight()
But when i push the button, the state doesn’t change , it stays in the state i describe you before
her is my correction with your help:

#include <LiquidCrystal_I2C.h> // bibliothèque ecran I2C
 #include <Wire.h> // bibliothèque I2C
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "help";
char ssid[] = "help";
char pass[] = "help";

SimpleTimer timer;
int etatbouton = 0;


void checkbouton() {

  etatbouton = digitalRead(D3);
  if (etatbouton == HIGH) {
    Serial.println("appui");
    lcd.noBacklight();
    lcd.noDisplay();
  }
  else {
    Serial.println("pas d'appui");
    lcd.backlight();
    lcd.display();
  }
}

void setup()
{
  lcd.begin();
  lcd.backlight();
 timer.setInterval(500, checkbouton);
  pinMode(D3, INPUT);
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  Serial.print("Blynk Ready\n");
}
BLYNK_WRITE(V0) {
  lcd.clear();
  String textIn = param.asStr();
  Serial.print(textIn + "\n");
  lcd.setCursor(0, 0);
  lcd.print(textIn);
}


void loop() {

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

}

As I explained in my last post, this line needs to be in void setup() not void loop()

When you’re posting code, you need to put triple backticks at the beginning and end of your code so that it displays correctly - I’ve fixed your last couple of posts.

Pete.

oh thanks Pete,
i haven’t find the “backticks” traduction but now i know what it is.

I corrected it in my upper sketch and download it right now but it doesn’t change…
i am always in “appui” state with nobacklight and nodisplay state and when i push the button nothing changes
here is my correction:

#include <LiquidCrystal_I2C.h> // bibliothèque ecran I2C
#include <Wire.h> // bibliothèque I2C
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "help";
char ssid[] = "help";
char pass[] = "help";

SimpleTimer timer;
int etatbouton = 0;


void checkbouton() {

  etatbouton = digitalRead(D3);
  if (etatbouton == HIGH) {
    Serial.println("appui");
    lcd.noBacklight();
    lcd.noDisplay();
  }
  else {
    Serial.println("pas d'appui");
    lcd.backlight();
    lcd.display();
  }
}

void setup()
{
  lcd.begin();
  lcd.backlight();
timer.setInterval(500, checkbouton);
  pinMode(D3, INPUT);
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  Serial.print("Blynk Ready\n");
}
BLYNK_WRITE(V0) {
  lcd.clear();
  String textIn = param.asStr();
  Serial.print(textIn + "\n");
  lcd.setCursor(0, 0);
  lcd.print(textIn);
}


void loop() {

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

}```

Exactly which type of Wemos are you using, and how is your physical switch wired?

Pete.

Thank you Pete, really thank you for the time you spend for my project. I appreciate it much.

here is the picture of my project my wemos is a D1 mini:

I’m not going to try to work out a wiring schematic from that.

How is your switch wired?

Pete.

ok Pete, i’ll try to explain it in english.

One side D3, resistor 220 OHM and ground and the other side to 5V ( from the wemos pin)

Hi Pete,

I fixed the problem, it was my resistor which was defective. Now it works.
I would like to thank you so much.
Could you tell me how could i thank you for the time you spent for me and your kindness?

1 Like

That’s great news :smile:

Just stick at it and keep using Blynk and Wemos devices!

Pete.

1 Like

A post was split to a new topic: LCD project not displaying