RTC Widget, LCD 16x2 display and Mega 2560

Hello guys,
I would like to use RTC Widget and send date and time to LCD 16x2 (HD44780) connected on Arduino Mega 2560. Is it possible?
May I just send lcd.print(hour()) or lcd.print(currentTime) like in RTC example?

I appreciate any answer. Thanks.

No, lcd.print() is a LCD Widget specific command set. You will need to use whatever command/data format the (physical) LCD library requires.

Thanks Gunner,
It woked. I put this part of RTC example in Void Loop().
Now I can see Time and Date from my LCD 16x2 (HD44780).

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + "/" + month() + "/" + year();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("HORA: ");
  lcd.print(" ");
  lcd.setCursor(7,0);
  lcd.print(currentTime);
  lcd.setCursor(0,1);
  lcd.print("DATA: ");
  lcd.print(" ");
  lcd.setCursor(7,1);
  lcd.print(currentDate);
  delay(2000);

Not recommended for Blynk sketches and if you continue you are sure to have major problems. Study the Blynk timer rather than halting all processing for 2s over and over again in loop().

I stand corrected… it looks like the developers based their commands off another standard library.

BTW, you should be able to differentiate between the two LCD’s (Widget and Physical) by renaming one or the other… i.e. changing WidgetLCD lcd(V1); to WidgetLCD lcd2(V1); then using lcd2.print("Hello World").

You should also avoid placing all of that (and the delay… big no no) in the void loop() instead set up a timer and use a timed loop, and remove the delay().

http://docs.blynk.cc/#blynk-firmware-blynktimer

Thanks Costas and Gunner,

I am not using Widget LCD just Physical LCD 16x2 (HD44780).
I am using all structure from RTC example from https://examples.blynk.cc/

Now I removed what I sad before from Void Loop() and edited void clockDisplay() .

 void clockDisplay()
    {
      // You can call hour(), minute(), ... at any time
      // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + "/" + month() + "/" + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("HORA: ");
  lcd.print(" ");
  lcd.setCursor(7,0);
  lcd.print(currentTime);
  lcd.setCursor(0,1);
  lcd.print("DATA: ");
  lcd.print(" ");
  lcd.setCursor(7,1);
  lcd.print(currentDate);
  delay(2000);

It´s working fine.
It´s needed 2s to see information on physical LCD.
It´s ok now?

I would say no but you haven’t provided enough code for anyone to answer the question.

delay() is bad form in any sketch. Looks like you have just created a function to cover the bad stuff you had in loop().

Use Blynk timer:

Call function at timed intervals with no delays(), so called every 2s but no pause in code execution.

I didn’t create a function. It’s all from RTC example.
I don’t know how I could hold information in physical LCD without delay.
Thanks.

Paste your formatted code.

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <LiquidCrystal.h>  // include the library code:
#include <DHT.h>
#include <DHT_U.h>


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

#define W5100_CS  10
#define SDCARD_CS 4
#define SS_PIN 53
#define RST_PIN 5
#define DHTPIN A5
#define DHTTYPE DHT11 // Define o tipo de sensor DHT utilizado

DHT dht(DHTPIN, DHTTYPE);
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

LiquidCrystal lcd(25, 24, 7, 6, 3, 2); // initialize the library with the numbers of the interface pins

 int porta1 = 22;
 int porta2 = 23;
 int tranca = 31;
 int lampada = 30;
 char st[20];
 int buzzer = 33;
 int GasFumaca = 35;


BlynkTimer timer;

WidgetRTC rtc;

// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + "/" + month() + "/" + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("HORA: ");
  lcd.print(" ");
  lcd.setCursor(7,0);
  lcd.print(currentTime);
  lcd.setCursor(0,1);
  lcd.print("DATA: ");
  lcd.print(" ");
  lcd.setCursor(7,1);
  lcd.print(currentDate);
  delay(2000);

/************************************************
  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
************************************************/
  
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  pinMode(lampada,OUTPUT);
  digitalWrite(lampada,HIGH);
  
  
  SPI.begin();      // Inicia  SPI bus
  mfrc522.PCD_Init();   // Inicia MFRC522
  Serial.println("Aproxime o seu cartao do leitor...");
  Serial.println(); 
  lcd.begin(16, 2); // set up the LCD's number of columns and rows:

  Blynk.begin(auth);
  // You can also specify server:
  //Blynk.begin(auth, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8442);

  // Begin synchronizing time
  rtc.begin();

  // Other Time library functions can be used, like:
  //   timeStatus(), setSyncInterval(interval)...
  // Read more: http://www.pjrc.com/teensy/td_libs_Time.html

  // Display digital clock every 10 seconds
  timer.setInterval(10000L, clockDisplay);

 
  lcd.clear();
  lcd.setCursor(15,0);
  lcd.print("AUTOMACAO RESIDENCIAL");

  //Rolagem para a direita
  for (int posicao = 0; posicao < 35; posicao++)
  {
  lcd.scrollDisplayLeft();
  delay(300);
  }
  lcd.clear();
  lcd.setCursor(2,1);
  lcd.print("CLECIO SILVA");  
  delay(1000);

  
}

void loop()
{
  Blynk.run();
  timer.run();

  int estadoporta1 = digitalRead(porta1);
  int estadoporta2 = digitalRead(porta2);
  int estadoGasFumaca = digitalRead(GasFumaca); //Armazena o valor da entrada do sensor de Gás/Fumaça
  
  digitalWrite(buzzer,LOW); //Coloca a saĂ­da para a sirene em nĂ­vel baixo


  float h = dht.readHumidity(); //LĂŞ o valor da umidade
  float t = dht.readTemperature(); //LĂŞ o valor da temperatura
  lcd.clear();
  lcd.setCursor(3,0); // Print a message to the LCD.
  lcd.print("AUTOMACAO");
  lcd.setCursor(2,1);
  lcd.print("RESIDENCIAL");
  delay(2000);

  Blynk.run();
 
  lcd.clear();
  lcd.setCursor(0,0); // Print a message to the LCD.
  lcd.print("Temp : ");
  lcd.print(" ");
  lcd.setCursor(7,0);
  lcd.print(t,1);
  lcd.setCursor(12,0);
  lcd.print((char)223); // Mostra o sĂ­mbolo do grau quadrado
  lcd.setCursor(13,0);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Umid : ");
  lcd.print(" ");
  lcd.setCursor(7,1);
  lcd.print(h,1);
  lcd.setCursor(12,1);
  lcd.print("%");
  delay(2000); // Tempo para leitura do sensor

  }
1 Like