I am working to migrate my sketch into the Blynk environment as Blynk DOES make networking Arduino’s so much easier and reliable. My circuit is an Ethermega (Mega w/Ethernet), and 8 channel sainsmart relay, a DHT22 temp/humidity sensor and a Chronodot DS3231 real time clock. My project will one day control a greenhouse or indoor garden facility. The reason I do not wish to use Blynk’s RTC widget is because growing plants requires a schedule, and if for whatever reason the network were to fail, so too would the timing of events. With an RTC in the circuit, so long as there is power, the program will continue.
The current state of the sketch involves code for the DHT22, code to read the RTC, convert the time into 12 hour format, and code to output that format into a single pair of strings. One string handles the time, the other handles the date. I also have in the simple ethernet code for Blynk. The DHT22 data transmits flawlessly, and I can toggle the relays from Blynk easily as well.
My holdup now is my lack of understanding of how to use the Blynk functions, more particularly, I don’t really comprehend how to use either BLYNK_READ & Blynk.virtualWrite, or the other approach of WidgetLCD & lcd.clear();/lcd.print(); functions to produce the result that I seek. I hope someone can shed some added light as I have read, reread and rereread the language given on the DOCS page, and it is evident that I cannot wrap my brain around it.
So I guess my request is 2fold. Can someone adjust my code so that the RTC data will transmit to an LCD widget, and also can someone provide added insight and knowledge of how these 2 functions work and how they can be modified to fit into other people’s sketches?
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <Wire.h>
#include "DHT.h"
#include <SimpleTimer.h>
#include "RTClib.h" // RealTimeClock Library for DS1307 and DS3231
#define BLYNK_PRINT Serial
#include <SPI.h>
//*******Sensor Model********************************
#define DHTTYPE DHT22
#define DHTPIN 13
RTC_DS1307 RTC;
float UTCOffset = -5.0; // Your timezone relative to UTC (http://en.wikipedia.org/wiki/UTC_offset)
char auth[] = "authKey";
DHT dht(DHTPIN, DHTTYPE);
byte h;
byte f;
SimpleTimer timer;
//WidgetLCD lcdA(V2);
//WidgetLCD lcdB(V3);
void setup()
{
Serial.begin(9600);
//Serial2.begin() // For other baud rates
//Serial3.begin() // For other baud rates
Blynk.begin(auth);
pinMode(DHTPIN, OUTPUT);
dht.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
RTC.begin();
while (Blynk.connect() == false) {}
timer.setInterval(5000L, climateCheck); // 5 seconds between sensor readings
timer.setInterval(3000L, RTCdisplay); // 3 seconds between sensor readings
}
void loop()
{
Blynk.run();
timer.run();
}
void climateCheck()
{
h = dht.readHumidity();
f = dht.readTemperature(true);
Blynk.virtualWrite(V0, f); // Set Virtual Pin 0 frequency to PUSH in Blynk app
Blynk.virtualWrite(V1, h); // Set Virtual Pin 1 frequency to PUSH in Blynk app
//Serial.print(f);
//Serial.print(h);
}
void RTCdisplay()
{
DateTime now = RTC.now(); // reads time at beginning of loop
byte twelveHour = now.hour() - 12; // Variable used to display 13+ hours in 12 hour format
byte zeroHour = 12; // Variable use to convert "0" zero hour to display it as 12:00+
byte displayHour;
byte MIN = now.minute();
byte SEC = now.second();
char* meridian;
if (now.hour() == 0) // First we test if the hour reads "0"
{
displayHour = zeroHour;
meridian = "AM";
}
else if (now.hour() >= 13) // if no, Second we test if the hour reads "13 or more"
{
displayHour = twelveHour;
meridian = "PM";
}
else
{
displayHour = now.hour();
meridian = "AM";
}
char timeStamp[11];
char dateStamp[11];
sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
sprintf(dateStamp, "%02d/%02d/%04d", now.month(), now.day(), now.year());
BLYNK_READ(timeStamp);
Blynk.virtualWrite(V2, timeStamp);
BLYNK_READ(dateStamp);
Blynk.virtualWrite(V3, dateStamp);
//lcdA.clear();
//lcdA.print(4, 0, timeStamp);
//lcdB.clear();
//lcdB.print(4, 0, dateStamp);
}
Thank you in advance