- Arduino Nano —plugged onto— data logging shield
- logging shield with sd micro card and RTC_DS1307 clock
- two DS18b20 temp. sensors connected to Arduino Nano pin2
- one LED to pin9, indicator of writing to sd card
- Connection to Blynk over USB
- two temp sensors readouts at Blynk display
- refresh interval on Blynk by PUSH
TEST 1. uncommenting lines in void setup():
Blynk.begin(Serial, auth);
while (Blynk.connect() == false) {} — So Blynk connection is OFF = Sd card logs data.
TEST 2. uncommenting lines in void loop():
DateTime now = RTC.now(); all the way down — So sd card is OFF = Blynk is working.
Problem: It does not work together !
Even if I uncomment the line “if(now.second()==00){}” so the sd card is running without any sampling settings, it’s not working. Without this line approximately 38/39 values with time stamp are written to the card.
The delay of 20 milliseconds in “void ledBlink()” to run an LED as logging indicator, doesn’t influence the connection to Blynk.
So where is the problem ? Is there a collision between sd card and USB connection to Blynk ?
/*
used pins
SDA = pin18 / A4 - clock
SCL = pin19 / A5 - clock
CS / SS = pin10 / D10 - sd card
Mosi = pin11 / D11 - sd card
Miso = pin12 / D12 - sd card
SCK = pin13 / D13 - sd card
RX = pin0
TX = pin1
LED as logging indicator = pin9
two DS18b20 sensors = pin2
*/
#define I2C_ADDRESS 0x3C //Oled display
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
SSD1306AsciiWire oled;
#include "RTClib.h"
#include <SPI.h>
#include <SdFat.h>
#define LED_PIN 9 //Logging indicator
RTC_DS1307 RTC; //Real Time Clock
const int chipSelect = 10; //CS pin
SdFat sd;
File Logfile; //Name of log file on sd card
//#define BLYNK_PRINT Serial //Comment this out to disable prints and save space
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(0, 1); // RX, TX
#include <BlynkSimpleStream.h>
BlynkTimer timer;
char auth[] = "--------------------";
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS 2 //DS18B20 sensors on pin 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
pinMode(LED_PIN, OUTPUT);
sd.begin(chipSelect);
RTC.begin();
Wire.begin();
oled.begin(&Adafruit128x64, I2C_ADDRESS);
oled.setFont(System5x7); //oled.setFont(Adafruit5x7); -- different font
oled.clear(); //oled.set2X(); -- font double size
oled.println("Well Temp"); //oled.println("2X demo");
oled.print("To limit");
oled.println();
oled.print("Well vol");
oled.println();
oled.print("2nd fl Temp");
oled.println();
oled.print("1st fl Temp");
oled.println();
oled.print("Basement Temp");
oled.println();
oled.print("Outside Temp");
SwSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(Serial, auth);
while (Blynk.connect() == false) {} //Wait until connected
sensors.begin();
//sensors.setResolution(tempSensor1, 9); //resolution of sensors
//sensors.setResolution(tempSensor2, 9);
timer.setInterval(100L, sendSensor1); //timer to readout DS18B20
timer.setInterval(100L, sendSensor2);
/*
timer.setTimeout(2, []() { // stag timer
timer.setInterval(100L, sendSensor1);
});
timer.setTimeout(20, []() {
timer.setInterval(100L, sendSensor2);
}); */
}
void ledBlink() {
digitalWrite(LED_PIN, HIGH);
delay(20);
digitalWrite(LED_PIN, LOW);
}
void sendSensor1() {
Blynk.virtualWrite(V1, sensors.getTempCByIndex(0)); //Send to Blynk virtual V1 "pin"
}
void sendSensor2() {
Blynk.virtualWrite(V2, sensors.getTempCByIndex(1)); //Send to Blynk virtual V2 "pin"
}
void loop() {
Blynk.run();
timer.run();
sensors.requestTemperatures();
oled.setCursor(90,0);
oled.print(sensors.getTempCByIndex(0)); //getTempCByIndex(0),1); -- XX.X
oled.setCursor(90,3);
oled.println(sensors.getTempCByIndex(1)); //getTempCByIndex(1),1); -- XX.X
DateTime now = RTC.now(); //Clock call
if(now.second()==00){ //Sample every minute
now = RTC.now();
Logfile=sd.open("Logfile.csv",FILE_WRITE); //Open sd card
Logfile.println();
Logfile.print(now.day(), DEC);
Logfile.print(".");
Logfile.print(now.month(), DEC);
Logfile.print(".");
Logfile.print(now.year(), DEC);
Logfile.print(" ");
Logfile.print(now.hour(), DEC);
Logfile.print(":");
Logfile.print(now.minute(), DEC);
//Logfile.print(":");
//Logfile.print(now.second(), DEC);
Logfile.print(" ");
Logfile.close(); //Close sd card
ledBlink();
sensors.requestTemperatures();
Logfile=sd.open("Logfile.csv",FILE_WRITE);
ledBlink();
Logfile.print(" ");
Logfile.print(sensors.getTempCByIndex(0)); //Fahrenheit use(sensors.getTempFByIndex(0));
Logfile.print(" ");
Logfile.print(sensors.getTempCByIndex(1));
Logfile.println();
Logfile.close();
}
}