BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

VL53L0X, ds18b20 and Blynk together


#1

I haven’t slept for several nights :wink:

I am using Arduino Uno R3 with ESP8266 software serial connection. Then I have VL53L0X distance sensor and DS18B20 temperature sensor.

My project code with DS182b20 sensor works fine, my code with VL53L0X works fine, but when I put these functions together, Blyk is connected, but stops after Ping and doesn’t continue timer functions. In Blynk app I can see that device connected, but no values updated.

Do you have any idea, why VL53L0X and DS18B20 doesn’t work together with Blynk?

This code with distance sensor and Blynk works:

//Blynk darbiibai
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "aasdasd";

// Your WiFi credentials.
char ssid[] = "asdasdasd";
char pass[] = "asdasdad";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(3, 4); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

//Blynk darbiibu izpildei
BlynkTimer timer;

//attalumam
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
int noinformets=0;
#define LONG_RANGE

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

  
//attaalumam
    Wire.begin();
    sensor.init();
    sensor.setTimeout(500);
#if defined LONG_RANGE
    // lower the return signal rate limit (default is 0.25 MCPS)
    sensor.setSignalRateLimit(0.1);
    // increase laser pulse periods (defaults are 14 and 10 PCLKs)
    sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
    sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

   // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(2000L, attalums);
  timer.setInterval(3000L, temperatura); // ik 5 sec
//  timer.setInterval(30000L, aratemper); // ik 5 minūtes
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, millis() / 1000);
}

void attalums()
{
int distance=0;
int granululimenis=0;
int counter=1;
const int tukss = 100;
distance=sensor.readRangeSingleMillimeters()/10;
if (distance>0 && distance<tukss+10){
  granululimenis=tukss-distance;
  Serial.print("Granulu līmenis: ");
  Serial.println(granululimenis);
  Blynk.virtualWrite(V5, granululimenis);
  }
}

void temperatura(){
  float katlatemp;
  katlatemp=88;
    Serial.print("Katla temperatūra: ");
    Serial.println(katlatemp); 
    Blynk.virtualWrite(V2, katlatemp);  
}

This code with Temperature sensor and Blynk works:

//Blynk darbiibai
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "sdasdad";

// Your WiFi credentials.
char ssid[] = "asdsad";
char pass[] = "sdsadad";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(3, 4); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

//Blynk darbiibu izpildei
BlynkTimer timer;

//Temperatūrai
#include <OneWire.h>
#include <DallasTemperature.h>
//Katla temp.
#define ONE_WIRE_BUS 6 //uz kura digitālā pin temp. lasītājs
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
  // Debug console
  Serial.begin(9600);
  
  //Temperatūrai
  sensors.begin();
  
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

   // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(2000L, attalums);
  timer.setInterval(3000L, temperatura); // ik 5 sec
//  timer.setInterval(30000L, aratemper); // ik 5 minūtes
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, millis() / 1000);
}

void attalums()
{
int distance=0;
int granululimenis=0;
int counter=1;
const int tukss = 100;
distance=55; //sensor.readRangeSingleMillimeters()/10;
if (distance>0 && distance<tukss+10){
  granululimenis=tukss-distance;
  Serial.print("Granulu līmenis: ");
  Serial.println(granululimenis);
  Blynk.virtualWrite(V5, granululimenis);
  }
}

void temperatura(){
  float katlatemp;
    sensors.requestTemperatures(); 
    katlatemp=sensors.getTempCByIndex(0);
    Serial.print("Katla temperatūra: ");
    Serial.println(katlatemp); 
    Blynk.virtualWrite(V2, katlatemp);  
}

Together doesnt work. Blynk connected, but timer functions not running

//attalumam
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
int noinformets=0;
#define LONG_RANGE

//Blynk darbiibai
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "sdcsdf";

// Your WiFi credentials.
char ssid[] = "scsdcsd";
char pass[] = "sdsdf";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(3, 4); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

//Blynk darbiibu izpildei
BlynkTimer timer;

//Temperatūrai
#include <OneWire.h>
#include <DallasTemperature.h>
//Katla temp.
#define ONE_WIRE_BUS 6 //uz kura digitālā pin temp. lasītājs
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

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

  //attaalumam
    Wire.begin();
    sensor.init();
    sensor.setTimeout(500);
#if defined LONG_RANGE
    // lower the return signal rate limit (default is 0.25 MCPS)
    sensor.setSignalRateLimit(0.1);
    // increase laser pulse periods (defaults are 14 and 10 PCLKs)
    sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
    sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif
  
  //Temperatūrai
  sensors.begin();
  
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

   // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(2000L, attalums);
  timer.setInterval(3000L, temperatura); // ik 5 sec
//  timer.setInterval(30000L, aratemper); // ik 5 minūtes
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, millis() / 1000);
}

void attalums()
{
int distance=0;
int granululimenis=0;
int counter=1;
const int tukss = 100;
distance=sensor.readRangeSingleMillimeters()/10;
if (distance>0 && distance<tukss+10){
  granululimenis=tukss-distance;
  Serial.print("Granulu līmenis: ");
  Serial.println(granululimenis);
  Blynk.virtualWrite(V5, granululimenis);
  }
}

void temperatura(){
  float katlatemp;
    sensors.requestTemperatures(); 
    katlatemp=sensors.getTempCByIndex(0);
    Serial.print("Katla temperatūra: ");
    Serial.println(katlatemp); 
    Blynk.virtualWrite(V2, katlatemp);  
}

#2

You appear to have posted the same code three times.

Pete.


#3

Code is not the same.
It seems that VL53L0X libraries uses more memory and for Arduino Uno + Blynk there is too less memory.
I did same tests with my Arduino Uno, and whenn sketch uses more than 73% of program storage space and more than 69% of dynamic memory, Blynk is connected, but timer functions are not running.
At the moment I devided my project to two Arduino Uno devices, one for VL53L0X distance sensor, other for temperatures and relays.
I tested also with Adafruit_VL53L0X library and Blynk. And I can’t send such sketch to my Arduino Uno, becouse it says Sketch too big.