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

BME280 sensor crashes Blynk.begin() with virtualWrite when on 0.6.X

Arduino Nano (old bootloader) with ESP8266 (AT version:0.51.0.0(Nov 27 2015 13:37:21) SDK version:1.5.0, compile time:Nov 27 2015 13:57:56 and AT version:1.3.0.0(Jul 14 2016 18:54:01) SDK version:2.0.0(5a875ba) Farylink Technology Co., Ltd. v1.0.0.2 May 11 2017 22:23:58) as a shield via softwareSerial.

AVR boards 1.16.21. Blynk 0.6.0. and 0.6.1.

Blynk library version 0.6.X. seems to break BME280 sensor in some way. If there are any virtualWrites and BME280 sensor is initialized, the program hangs after [9521] Connected to WiFi [19868] Ready (ping: 25ms). being unable to connect to Blynk servers. When commenting out the virtualWrites, the program works. I’m not sure why. It works fine on 0.5.4.

It seems that it hangs on while(this->connect() != true) {} in Arduino\libraries\Blynk\src\BlynkSimpleShieldEsp8266.h

Topic with disscussion: VirtualWrite crashes the execution of sketch

Example code that doesn’t work.


#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>


#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define DEBUGMODE 1

#define SERIALDATRATE 9600
#define ESP8266_BAUD 9600

Adafruit_BME280 bmeInside;

SoftwareSerial EspSerial(2, 3); // RX, TX

ESP8266 wifi(&EspSerial);

char auth[] = "";
char ssid[] = "";
char pass[] = "";

/*	blynk pinout
 *	LCD0 - V5,
*/

typedef const uint8_t pin;

struct blynkPins {
	pin LCD0 = V5;
} pinBlynk;

// how often to update the data in ms
struct updateRateStruct {
	const uint16_t sensor = 1 * 1000;
	const uint16_t blynk = 1 * 60000;
} updateRate;

struct sensorData {
	float inTemperature;
	float inHumidity;
	float inPressure;
} sensor;

WidgetLCD lcd0(pinBlynk.LCD0);

// -------------------------------------------------------------------

void sendBlynk(void);

void updateSensors(void);

void pollBmeInside(void);


uint32_t currentMillis = 0;

// -------------------------------------------------------------------

void setup() {

	#if DEBUGMODE
		Serial.begin(SERIALDATRATE);
		Serial.println("Starting in debug mode");
		Serial.println("----------------------------\n");
	#endif
	
	EspSerial.begin(ESP8266_BAUD);

	Blynk.begin(auth, wifi, ssid, pass);
	
	bmeInside.begin(0x76);
}

void loop() {
	currentMillis = millis();

	Blynk.run();
	
	updateSensors();
	
	sendBlynk();
}


void updateSensors(){
	static uint32_t previousMillis = 0;

	if ((currentMillis - previousMillis) >= updateRate.sensor){
		previousMillis = currentMillis;
		pollBmeInside();
	}
}

void pollBmeInside(){

	sensor.inHumidity = bmeInside.readHumidity();
	sensor.inTemperature = bmeInside.readTemperature();
	sensor.inPressure = bmeInside.readPressure() / 100.0F;
  
	#if DEBUGMODE
		Serial.println("bmeInside data:");
		Serial.println("t °C:\th %:\tp hPa:");
		Serial.print(sensor.inTemperature);
		Serial.print("\t");
		Serial.print(sensor.inHumidity);
		Serial.print("\t");
		Serial.println(sensor.inPressure);
	#endif
}


void sendBlynk(){
	static uint32_t previousMillis = 0;
	
	if ((currentMillis - previousMillis) >= updateRate.blynk){
		previousMillis = currentMillis;
		
		lcd0.clear();
    
		lcd0.print(0, 0, "T: ");
		lcd0.print(3, 0, sensor.inTemperature);
		lcd0.print(9, 0, "H:");
		lcd0.print(11, 0, sensor.inHumidity);

		lcd0.print(0, 1, "Pres:");
		lcd0.print(7, 1, sensor.inPressure);
		
		#if DEBUGMODE
			Serial.println("blynk trig\n");
		#endif
	}
}