Arduino nano with data logging shield collision with Blynk

  • 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();   
}
}

Is your Nano connected to a thermonuclear reactor?

1 Like

Thermonuclear reactor ??? Noooooooo :joy: it’s just laying on my kitchen table…
:smile: But to be really sure I checked all wires…no thermonuclear reactor fund…
So this can’t be the problem.

Oh, where to start…

USB link, but using SoftSerial on same USB pins as primary Serial port

A void loop chock full of stuff

Multiple timers set for exact same time

You mean reactors?

@Geo I don’t even know where to start… remove everything in your main loop except

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

Read thru docs.blynk.cc.
Read one of my billion posts about DS18B20 and delay.
Search the forum.

1 Like

So why 100ms temperature readings that DS18B20 can’t do unless you set the lowest resolution.

You need a complete re-write of your loop() so it has just 2 lines of code.

Needs a complete re-write of the entire thing :stuck_out_tongue_winking_eye: I can’t see how it even connects to the server.

Without the sd card part it connects to the server just fine. I can read the temperatures on Blynk just fine and switch on and off additional LEDs at the Arduino Nano over Blynk. So the sensors DS18b20 work perfectly. Because of the timing to readout, I can increase the timer to 1000ms. But that’s not the problem.

No they do not.

You MUST re-write your sketch completely using BlynkTimer correctly.

Minimum of 1000ms but after testing real world is normally 60000ms or higher.

Each time you run sensors.requestTemperatures(); your program will stop for about 750 ms. Each sensors.getTempCByIndex() takes about 30-35 ms, and you have 4 in your loop. That’s close to 1000 ms!

Then you have 2 timers running at 100 ms interval doing another getTempCByIndex().

I don’t want to sound pompous, but you’ll have to trust us on this one - it will not work when your loop looks like that!

Well what can I say…they work…I can see them on Blynk and the show correct moving values when I head or chill them. I am connected to the server…that’s all ok. It’s the part of the sd card which I can’t get to work. Separately form Blynk the code or the sd card works also fine. Just the integration doesn’t work. I will try to get this part out of the loop. I set the timer for the DS18b20 to 1000ms. For a 12 bit resolution they need 750ms.

Distans I will check this !

That must be pure luck! :rofl:

It’s not, the OP only thinks he is seeing readings at 100ms intervals from the sensor.

1 Like

And speaking of luck… SoftwareSerial on the same default USB ports with USB link… thankfully the OP hasn’t also enabled Blynk print… :slight_smile:

1 Like

Yea I know, I ment that he manages to keep the connection alive somehow. I’ve been disconnected by far less delays :yum:

@distans the OP probably isn’t keeping the connection alive and that’s why they think there is an issue with the SD card code and Blynk, whereas it’s simply a dreadful sketch.

2 Likes