NODEMCU DHT servo reedswitch lcd

I’m needing help with getting my lcd to display a virtual pin from another nodemcu in my home. I will post the code from both sketches. I also am having trouble learning how to make the lcd do a page like effect one screen with temp+humidity and then go to door status then loop.

I have the dht11 working fine and displaying temp and rh.

I’m kind of stuck for now. I know my code is all over the place but most of it is copy pasted together.

//This is the bedroom mcu.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
#include <Adafruit_Sensor.h>
#include <DHT_U.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

#define DHTTYPE DHT11

#define DHTPIN 14


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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NETGEAR";
char pass[] = "";
BlynkTimer timer;
Servo servo;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);

//Below is for servo neutral.
BLYNK_WRITE(V3) {

  servo.write(param.asInt());
  timer.setTimeout(2000L, ServoNeutral);  // In two seconds, Run the void ServoNeutral() routine.
}


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(true);

  if (isnan(h) || isnan(t)) {
    Serial.println("DHT FAILURE");
    return;
  }
  Blynk.virtualWrite(V20, h);
  Blynk.virtualWrite(V21, t);
}
//This is the pin I'm wanting to read. V1 is a open/closed value for my screen door.
BLYNK_WRITE(1)
{
  int pinValue = param.asInt(); 
}

void ServoNeutral() {
  servo.write(60);
}

void setup() {

  // Debug console Serial.begin(115200);

  Blynk.begin(auth, ssid, pass, IPAddress(10, 0, 0, 2), 8442);

  dht.begin();
  timer.setInterval(1000L, sendSensor);
  // You can also specify server:

  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);

  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  servo.attach(15); // 15 means D8 pin of ESP8266


}
//messy..
void backpack() {

  Wire.begin(D2, D1);
  lcd.begin();
  lcd.home();
  lcd.setCursor(1, 0);
  lcd.print(dht.readTemperature(true));
  delay (250);//How can this be replaced to refresh the updated values, this delay is messing up my loop
  lcd.setCursor(1,1);
}


void loop()
{
  timer.run();
  Blynk.run(); // You can inject your own code or combine it with other sketches.
  backpack();
}

this is the screendoor mcu’s sketch below.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

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


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

bool current = 0;
bool previous = 1;

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NETGEAR";
char pass[] = "";
void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(10,0,0,2), 8442);
  pinMode(14, INPUT_PULLUP); //DOOR
}

void switchstate(){
  current = digitalRead(14);
  if (current != previous){
    previous = current;
    if (current == LOW)
          {
              Blynk.virtualWrite(2, "1");
              Blynk.virtualWrite(1, "Closed.");
              Blynk.notify("Door Closed");
          }
          else
         {
              Blynk.virtualWrite(2, "0");
              Blynk.virtualWrite(1, "Open.");
              Blynk.notify("Door Opened");
         }    
  }
}
void loop()
{
  Blynk.run();
  switchstate();
}

How can I retrieve the state from a remote MCU? I have the blynk server on a pi so it is local. I have an eventor state that causes the door open state to trigger the servo on the lightswitch but I’m wanting to display the door state on a physical i2c lcd.

Try the Bridge Widget

Simple steps like set position, print data, wait for timer, clear screen, set new posistion, print new data, rinse and repeat.

My main thing now is I’m struggling with is to now output the bridge virtual pin variable to my lcd display.

I have only sent bridged data to Display Widgets, but the principle should be the same… although you will need to set cursor position “locally”… the following is UNtested…

On sending MCU (not showing the usual bridge setup):

bridge1.virtualWrite(vPin, "Data"); // Using vpin of receiving MCU

On receiving MCU:

BLYNK_WRITE(vPin) {
    Data = param.asStr();
    PLCD.setCursor(0, 2);
    PLCD.print(Data);
}
1 Like