Hello,
I am using a CCS811 VOC and CO2 sensor, a BMP Pressure and Temperature sensor and an Adafruit SSD1306 OLED display with an Adafruit ESP32 Huzzah. All the sensors and display use i2c communications. If I run my code in the âstand aloneâ mode, i.e. not using Blynk, everything works fine. If I use Blynk, after some minutes up to several hours of operation, I get the following i2c errors:
[esp32-hal-i2c.c:161] i2cWrite():Busy Timeout! Addr:5b.
[esp32-hal-i2c.c:161] i2cWrite():Busy Timeout! Addr:40.
[esp32-hal-i2c.c:161] i2cWrite():Busy Timeout! Addr:5b.
I tried removing the display â same result.
I removed one sensor and removed the display â same result with Blynk.
I have read in other forums that the i2c on the ESP32 has some problems with timing but the fact that it works without Blynk leads me to believe that I must be doing something wrong with Blynk.
My code is below. I cleaned it up a bit by removing some of the functions to make it easier to read and this code works without Blynk and fails with Blynk.
/******************************************************************************
Read the TVOC and CO2 values from the SparkFun CSS811 breakout board
Originally derived from Sparkfun ESP32 Thing example
******************************************************************************/
#include <arduino.h>
#include "SparkFunCCS811.h"
#include <SPI.h>
#include <Wire.h> //Classes for I2C
#include <Adafruit_GFX.h> //Classes for display
#include <Adafruit_SSD1306.h> //Classes for OLED display
/*******************************************************************
*
* The following lines are for connecting to Blynk
*
*******************************************************************/
#include <WiFi.h> //
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// This is my authorization code for Blynk
char auth[] = âxxxxxxxxxâ;
//Put router info here
char ssid[] = âxxxxxxxxxâ;
char pass[] = âxxxxxxxxxxâ;
BlynkTimer timer;
/**********************************************************************************************/
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define CCS811_ADDR 0x5B //Default I2C Address for the CCS811
//#define CCS811_ADDR 0x5A //Alternate in case I have a conflict with others
CCS811 SensorOBJ(CCS811_ADDR); //Sensor object of class CCS811
long chipid; //used if I want to display chip identification code
long NewTime = 0; //upddated millisecond count
int GoofOff = 50; //delay time in milliseconds
void oledDisplay(); //function prototype declaration
void sendSensor(); //function prototype declaration
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
Serial.begin(115200);
CCS811Core::status returnCode = SensorOBJ.begin(); // used for error codes
Serial.print("begin exited with: ");
Serial.println();
display.clearDisplay();
Blynk.begin(auth, ssid, pass); // start up Blynk
// this uploads data from sensor to Blynk at 1 second intervals
timer.setInterval(1000L, sendSensor);
//timer.setInterval(2307L, oledDisplay); // skew timer interval to stop i2c issues
}
void loop()
{
Blynk.run();
timer.run();
//call function if Blynk is disabled
//oledDisplay();
//delay(1000);
}
void oledDisplay(){
SensorOBJ.readAlgorithmResults(); //get data from Sensor
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("TVOC: ");
display.println( SensorOBJ.getTVOC());
display.print("CO2: ");
display.println( SensorOBJ.getCO2());
display.display(); //Write data to oled
//display.clearDisplay();
}
void sendSensor(){
if (SensorOBJ.dataAvailable()){
Serial.println("Sending Data");
SensorOBJ.readAlgorithmResults();
int C = SensorOBJ.getCO2();
int V = SensorOBJ.getTVOC();
Blynk.virtualWrite(V0, C);
Blynk.virtualWrite(V1, V);
}
}
Could someone give me an idea as to what I should do?
Thank you