Hello.
I have a program on ESP8266 with a temperature sensor and an oled display. The program was always working correctly until the bridge was added. After adding the bridge, the program freezes at random intervals.
What can be a problem?
#include "MAX17043.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
MAX17043 batteryMonitor;
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Seeed_BME280.h"
#include <ESP8266WiFi.h>
#include "Adafruit_MCP9808.h"
// WIFI
const char* WIFI_SSID = "";
const char* WIFI_PWD = "";
char auth[] = "";
WidgetBridge bridge1(V5);
BLYNK_CONNECTED() {
//Place the AuthToken of the second hardware here
bridge1.setAuthToken("");
}
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
// Time to sleep (in seconds):
const int sleepTimeS = 1800;
// 'indeks', 16x8px
const unsigned char battery [] PROGMEM = {
0x3f, 0xff, 0x40, 0x01, 0x40, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0x40, 0x01, 0x40, 0x01, 0x3f, 0xff
};
// 'indeks', 16x13px
const unsigned char wifi [] PROGMEM = {
0x00, 0x00, 0x1f, 0xf8, 0x3e, 0x7c, 0xf0, 0x0e, 0xc3, 0xc3, 0x0f, 0xf0, 0x1c, 0x38, 0x18, 0x18,
0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x00, 0x00
};
Adafruit_SSD1306 display;
BME280 bme280; //GROVE
#define buildinled D4
BLYNK_WRITE(V4)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable (Button)
if (pinValue == 1) { // If value is 1 run this command
digitalWrite(buildinled, LOW); // D1 output from Wemos D1 mini
}
else { // If value is 0 run this command
digitalWrite(buildinled, HIGH); // D1 output from Wemos D1 mini
}
Serial.print("V4 Button value is: "); // Output the value "pinValue" in Serial Monitor
Serial.println(pinValue);
}
void setup() {
pinMode(buildinled, OUTPUT);
digitalWrite(buildinled, 1);
Wire.begin(D5,D6); //ZMIANA PINÓW MAGISTRALI I2C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Clear the buffer
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setTextColor(WHITE);
WiFi.begin(WIFI_SSID, WIFI_PWD);
Blynk.begin(auth, WIFI_SSID, WIFI_PWD);
Serial.begin(9600);
Serial.println("MAX17043 Example: reading voltage and SoC");
Serial.println();
if (!bme280.init()) { //GROVE
Serial.println("Device error!"); //GROVE
} //GROVE
if (!tempsensor.begin()) {
Serial.println("Couldn't find MCP9808!");
}
batteryMonitor.reset();
batteryMonitor.quickStart();
}
void loop() {
Blynk.run();
float humdh = bme280.getHumidity(); //GROVE
float temph = bme280.getTemperature(); //GROVE
temph = temph - 1;
float c = tempsensor.readTempC();
long rssi = WiFi.RSSI();
long rssiCalc;
delay(500);
if(rssi <= -100)
rssiCalc = 0;
else if(rssi >= -50)
rssiCalc = 100;
else
rssiCalc = 2 * (rssi + 100);
delay(1000);
rssi = WiFi.RSSI();
rssiCalc;
delay(500);
if(rssi <= -100)
rssiCalc = 0;
else if(rssi >= -50)
rssiCalc = 100;
else
rssiCalc = 2 * (rssi + 100);
float cellVoltage = batteryMonitor.getVCell();
Serial.print("Voltage:\t\t");
Serial.print(cellVoltage, 4);
Serial.println("V");
float stateOfCharge = batteryMonitor.getSoC();
Serial.print("State of charge:\t");
Serial.print(stateOfCharge);
Serial.println("%");
display.setFont();
display.drawRect(0, 23, 128, 18, WHITE);
display.setTextSize(2);
display.setCursor(5,25);
display.println(String("Temp:"));
//display.println(String("mcp"));
display.setCursor(64,25);
display.println(String(temph, 1) + "C");
//display.println(String(c, 1) + "C");
display.fillRect(0, 47, 128, 17, WHITE);
display.setTextColor(BLACK);
display.setCursor(5,48);
display.println(String("Hum:"));
//display.println(String("bme"));
display.setCursor(64,48);
display.println(String(humdh, 1) + "%");
//display.println(String(temph, 1) + "C");
display.drawBitmap(90, 0, battery, 16, 8, 1);
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(110,0);
display.println(String(stateOfCharge, 0) + "%");
display.drawBitmap(0, 0, wifi, 16, 13, 1);
display.setCursor(20,3);
display.println(String(rssiCalc) + "%");
display.display();
//display.clearDisplay();
Blynk.virtualWrite(V0, humdh); // virtual pin 0
delay(100);
Blynk.virtualWrite(V1, temph); // virtual pin 1
delay(100);
Blynk.virtualWrite(V2, rssiCalc); // virtual pin 2
delay(100);
Blynk.virtualWrite(V3, stateOfCharge); // virtual pin 3
delay(100);
bridge1.virtualWrite(V5, temph);
delay(100);
bridge1.virtualWrite(V6, humdh);
delay(100);
bridge1.virtualWrite(V7, stateOfCharge);
delay(100);
ESP.deepSleep(sleepTimeS * 333330); ///one minutes sleep
}