Blynk Connectivity issues after adding OLED Screen (Adafruit_SSD1306.h)

A little overview of my project. I’m making a wireless thermometer for smoking meats on a Big Green Egg. I currently have an iGrill which only has Bluetooth connectivity, which presents range issues. Here is my hardware progress thus far.

Hardware
Arduino Nano ATmega328
ESP8266-12
(Note: The ESP came with the latest AT build installed. I did not have to flash backwards to legacy firmware versions like many others users here have suggested. I may have gotten lucky)

Problem

I recently added the OLED screen picture above, and I’ve lost connectivity to Blynk with the addition of the Adafruit libraries. I’ve come to a point where I’m not sure what else to troubleshoot, so I’m hoping for some direction. My sketch is approaching the flash limit at about 87% storage space used and it suggests there may be stability issues. I’m hoping that’s not the problem. Below are versions 1.3 which works perfectly, and version 1.4 where I have issues. I pinpointed that connectivity issues happen by removing all the Adafruit code to just when the screen is defined with

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

If all the screen code is commented out, but the Adafruit libraries are included it works as well. Does anyone have any thoughts or suggestions?

1.3
`/***************************************************************

  • VERSION Thermometer 1.3
    Arduino Nano connected to ESP8266-12 Hard Serial
    **************************************************************/
    //#define BLYNK_DEBUG
    //#define BLYNK_PRINT Serial
    #include <ESP8266_HardSer.h>
    #include <BlynkSimpleShieldEsp8266_HardSer.h>
    #include <SimpleTimer.h> //Simple Timer Library`

    // Set ESP8266 Serial object
    #define EspSerial Serial

    ESP8266 wifi(EspSerial);

    char auth[] = “xxxx”;

    WidgetLED led1(V4);
    WidgetLED led2(V5);
    WidgetLED led3(V6);
    WidgetLED led4(V7);

    int Probe[4] = {0,0,0,0};
    double Temp[4] = {0,0,0,0};
    int LED[4] = {0,0,0,0};
    int i = 0;

    SimpleTimer timer; //Create a Timer object called “timer”

    void setup()
    {
    // Set console baud rate
    Serial.begin(9600);
    delay(10);
    // Set ESP8266 baud rate
    EspSerial.begin(115200);
    delay(10);

    analogReference(EXTERNAL);

    Blynk.begin(auth, wifi, “xxx”, “xxxx”);

    timer.setInterval(2000, sendTemperatures);
    timer.setInterval(1333, sendLED);

    }

    void sendTemperatures()
    {
    Blynk.virtualWrite(V0, int(Temp[1]));
    Blynk.virtualWrite(V1, int(Temp[2]));
    Blynk.virtualWrite(V2, int(Temp[3]));
    Blynk.virtualWrite(V3, int(Temp[4]));

    }

    void sendLED()
    {
    led1.setValue(int(LED[1]));
    led2.setValue(int(LED[2]));
    led3.setValue(int(LED[3]));
    led4.setValue(int(LED[4]));
    }

    void loop()
    {
    Blynk.run();
    timer.run();

    Probe[1] = analogRead(A0);
    Probe[2] = analogRead(A1);
    Probe[3] = analogRead(A2);
    Probe[4] = analogRead(A3);

    for(int i =1; i < 5; i++)
    {

     if((Probe[i])<421)
     {
       Temp[i] = -61.3*log(Probe[i])+488.4;
       LED[i] = 255;
     }
    
     if(420<(Probe[i]) && (Probe[i]<1022))
     {
       Temp[i] = (-0.116*Probe[i])+168.8;
       LED[i] = 255;
     }
     
     if((Probe[i])>1022)
     {
       Temp[i] = 0;
       LED[i] = 0;
     }
    

    }

    }

1.4

 /**************************************************************
 * VERSION Thermometer 1.4
 Arduino Nano Connected to ESP8266-12 Hard Serial
 **************************************************************/
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <SimpleTimer.h> //Simple Timer Library
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);


// Set ESP8266 Serial object
#define EspSerial Serial

ESP8266 wifi(EspSerial);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";

WidgetLED led1(V4);
WidgetLED led2(V5);
WidgetLED led3(V6);
WidgetLED led4(V7);

int Probe[4] = {0,0,0,0};
double Temp[4] = {0,0,0,0};
int LED[4] = {0,0,0,0};
int i = 0;
int j = 0;

SimpleTimer timer; //Create a Timer object called "timer"


void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  analogReference(EXTERNAL);

  Blynk.begin(auth, wifi, "xxx", "xxx");

  timer.setInterval(2000, sendTemperatures);
  timer.setInterval(1333, sendLED);
  //timer.setInterval(3667, sendOLED);

  delay(50);

  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.display();
  delay(2000);
  display.clearDisplay();

  /*
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Blynk.begin");
  display.println("Connecting");
  display.display();
  delay(1000);
  display.clearDisplay();
  */

}


void sendTemperatures()
{
  
  Blynk.virtualWrite(V0, int(Temp[1]));
  Blynk.virtualWrite(V1, int(Temp[2]));
  Blynk.virtualWrite(V2, int(Temp[3]));
  Blynk.virtualWrite(V3, int(Temp[4]));
  
}

void sendLED()
{
  led1.setValue(int(LED[1]));
  led2.setValue(int(LED[2]));
  led3.setValue(int(LED[3]));
  led4.setValue(int(LED[4]));  
}

/*
void sendOLED()
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.clearDisplay();
  display.print("AMB: ");
  display.print(Temp[1]);
  display.println(" F");
  display.print("P1: ");
  display.print(Temp[2]);
  display.println(" F");
  display.print("P2: ");
  display.print(Temp[3]);
  display.println(" F");
  display.print("P3: ");
  display.print(Temp[4]);
  display.println(" F");
  display.display();
  delay(5000);

  display.startscrollright(0x00, 0x0F);
  delay(5000);
  display.clearDisplay();

}
*/




void loop()
{
  Blynk.run();
  timer.run();

  Probe[1] = analogRead(A0);
  Probe[2] = analogRead(A1);
  Probe[3] = analogRead(A2);
  Probe[4] = analogRead(A3);

  for(int i =1; i < 5; i++)
  {

    if((Probe[i])<421)
    {
      Temp[i] = -61.3*log(Probe[i])+488.4;
      LED[i] = 255;
    }

    if(420<(Probe[i]) && (Probe[i]<1022))
    {
      Temp[i] = (-0.116*Probe[i])+168.8;
      LED[i] = 255;
    }
    
    if((Probe[i])>1022)
    {
      Temp[i] = 0;
      LED[i] = 0;
    }
         
  }
    
}

You can’t have delay(5000);
And BTW I have sketch which fills ROM up to 100% and it’s perfectly stable😜

Glad to hear its probably not size limitations. Btw that delay is commented out for now. I was experimenting.

So you say with those delays removed it still doesn’t work?

Correct. I simplified version 1.4 so the commented sections aren’t confusing. I’m guessing there might be something in the new Adafruit libraries conflicting with Blynk?

//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial    
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <SimpleTimer.h> //Simple Timer Library
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);


// Set ESP8266 Serial object
#define EspSerial Serial

ESP8266 wifi(EspSerial);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxx";

WidgetLED led1(V4);
WidgetLED led2(V5);
WidgetLED led3(V6);
WidgetLED led4(V7);

int Probe[4] = {0,0,0,0};
double Temp[4] = {0,0,0,0};
int LED[4] = {0,0,0,0};
int i = 0;
int j = 0;

SimpleTimer timer; //Create a Timer object called "timer"

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  analogReference(EXTERNAL);

  Blynk.begin(auth, wifi, "Searching...", "3e1bb774fe");

  timer.setInterval(2000, sendTemperatures);
  timer.setInterval(1333, sendLED);

  delay(50);
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.display();
  delay(2000);
  display.clearDisplay();
}


void sendTemperatures()
{
  
  Blynk.virtualWrite(V0, int(Temp[1]));
  Blynk.virtualWrite(V1, int(Temp[2]));
  Blynk.virtualWrite(V2, int(Temp[3]));
  Blynk.virtualWrite(V3, int(Temp[4]));
  
}

void sendLED()
{
  led1.setValue(int(LED[1]));
  led2.setValue(int(LED[2]));
  led3.setValue(int(LED[3]));
  led4.setValue(int(LED[4]));  
}


void loop()
{
  Blynk.run();
  timer.run();

  Probe[1] = analogRead(A0);
  Probe[2] = analogRead(A1);
  Probe[3] = analogRead(A2);
  Probe[4] = analogRead(A3);

  for(int i =1; i < 5; i++)
  {

    if((Probe[i])<421)
    {
      Temp[i] = -61.3*log(Probe[i])+488.4;
      LED[i] = 255;
    }

    if(420<(Probe[i]) && (Probe[i]<1022))
    {
      Temp[i] = (-0.116*Probe[i])+168.8;
      LED[i] = 255;
    }
    
    if((Probe[i])>1022)
    {
      Temp[i] = 0;
      LED[i] = 0;
    }
         
  }
    
}

Ok get rid of Serial.begin(9600) at the beginning and make sure you use 115200 for communication with ESP what I mean is that it talks to you on this baud rate if not reconfigure it to talk on 115200. Otherwise it should work. Despite the fact that Adafruit makes so so libs sometimes they are messy this one seems to be ok.

I removed Serial.begin(9600), but the connection to Blynk is still not being made. I also verified that the ESP is configured for a baud rate of 115200. I’m going to try and dig into the Adafruit libraries a little bit more. There is a very direct cause and effect relationship to including the code to operate the screen.

Use blynk debug you should have enough space.

Hi @hemming1,

May be i’ve the same problem. I’ve added 0,96 oled to my project (mega+cc3000+dh11+mq2+strinity sensor). I’ve used both u8glib and sd1306 libraries in both cases with stability problems.
Have you solved your problem?
Suggestion?
Rgds

Hi @zetalif

It’s quite possible that we are experiencing the same problem. I did switch to the u8glib, and I saw some promising results. I’m not a very strong coder, and the u8glib is not as user friendly as the Adafruit library. I haven’t had a lot of time to troubleshoot further, but I was able to connect to Blynk and print values. I did notice that depending on how I was sending values to the oled screen, Blynk would kick out occasionally like when you try to send too many values.

As for the sd1306 library, I started digging through some of the .h files and it seemed like it was checking to see what device it was running on. I’m not sure why it would need to do that, and I think I saw some code that would mess up my esp8266.

Perhaps you could post your code and I could try to run it on my setup with the u8glib library. If it works, it could help you narrow the problem to the cc3000.

Cheers

There is nothing messing up ESP in those header files, obviously different devices have different GPIO config and other stuff not getting deep into this topic: it has to be done period. ESP has bit banged I2C which means it’s BAAAD but it’s how it is… In general it might cause problems but shouldn’t. I was running some day: SSD1306, MPU6050 on I2C bus, HTTP server and some other stuff in general there was a lot of things and ESP ran it without any issues.

You need to simply get through your code 10 times and figure out what might be wrong.

Does this sound like your issue or something you’d like to try (tweaking the Adafruit code)? https://github.com/adafruit/Adafruit_SSD1306/issues/54

Hi,

following my code. In any case it is confirmed (at least in my case) removing g8lig or SD1306 libraries no problem at all.

define ADAFRUIT_CC3000_IRQ 3
define ADAFRUIT_CC3000_VBAT 5
define ADAFRUIT_CC3000_CS 10

include “SPI.h”
include “Adafruit_CC3000.h”
include “BlynkSimpleCC3000.h”
include “SimpleTimer.h”

include “Wire.h”
include “Adafruit_BMP085.h”
include “DHT.h”
include “TSL2561.h”
include “U8glib.h”

char auth = “xxxxxx”;

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI

const int gasPin = A8;
const int Led = 12;
const int PIR_pin = 30;

// Pin for DHT11
define DHTPIN 31
DHT dht(DHTPIN, DHT11);

// Strinity Sensor
Adafruit_BMP085 bmp;
TSL2561 tsl(TSL2561_ADDR_FLOAT);
int Altitude;
float Pressure;
int Temperature;
int ir, full;
float Humidity;
float DHT_Temp;
float Gas;

SimpleTimer timer;

void setup()
{

// OLED inizialization & first page
u8g.setFont(u8g_font_unifont);
u8g.firstPage();
do {
u8g.setPrintPos(0, 20);
u8g.print(“- WiFi CC3000 -”);
u8g.setPrintPos(0, 40);
u8g.print(“Weather & Alarm”);
u8g.setPrintPos(0, 60);
u8g.print(“Station - 2016”);
} while( u8g.nextPage() );
// ********************************

Blynk.begin(auth, “xxxxxxxxxxxxxx”, “xx”, WLAN_SEC_WPA2);

while (Blynk.connect() == false) {
// Wait until connected
}

Blynk.email(“xxx@xxx”, “Subject”, “My Blynk project is online.”);

// Setup a function to be called every second
timer.setInterval(1000L, sendUptime);

pinMode(PIR_pin, INPUT);

// Sensors set-up

dht.begin();
bmp.begin();
tsl.begin();
tsl.setGain(TSL2561_GAIN_16X);
tsl.setTiming(TSL2561_INTEGRATIONTIME_13MS);
}

void loop(){

Blynk.run();
timer.run(); // Initiates SimpleTimer
}

void sendUptime() {

if (digitalRead(PIR_pin)){
// Blynk.email(“xxxx@xxx”, “Alarm”, “Alarm_Detected”);
Blynk.notify(“PIR detection”);
}

// Sensor readings

Altitude = bmp.readAltitude(101500);
Pressure = bmp.readPressure()/100;
Temperature = bmp.readTemperature();

Humidity = dht.readHumidity();
// DHT_Temp = dht.readTemperature();

Gas = analogRead(gasPin);

uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE);
uint32_t lum = tsl.getFullLuminosity();
ir = lum >> 16;
full = lum & 0xFFFF;

// picture loop
u8g.setFont(u8g_font_profont15);
u8g.firstPage();
do {
u8g.setPrintPos(0, 10);
u8g.print("Temp = ");
u8g.print(Temperature);

u8g.setPrintPos(0, 25);
u8g.print("Press = ");
u8g.print(Pressure);

u8g.setPrintPos(0, 40);
u8g.print("Humidity = ");
u8g.print(Humidity);

u8g.setPrintPos(0, 55);
u8g.print("Lux = ");
u8g.print(full);
} while( u8g.nextPage() );
delay(500);

// No more that 10 values per second.
Blynk.virtualWrite(V1, Temperature);
Blynk.virtualWrite(V2, Pressure);
Blynk.virtualWrite(V3, full);
Blynk.virtualWrite(V4, Humidity);
Blynk.virtualWrite(V5, Gas);
}

Next week I’ll work on sth that will solve your issue and many others and most likely will get rid off all those connection issues on ESP.

I think you have hit the problem on its head. I gave that walk through a go and the cpp file would not compile with the suggested modifications. The ssd1306_data function is no longer present, so there is likely a newer version out. I’m going to look into it further to see if I can change the new cpp file. Thanks for the suggestion!

Try removing all of your OLED prints and everything related to u8g except for the initialization:
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI

If this works, slowly start adding your code, beginning with something simple in your loop.

Hi @hemming1,

i’ve followed your indication. Its enough the include g8lib for continous resets of Arduino Mega + CC3000 with Blynk.

Hi @zetalif,

I noticed that I started getting g8lib resets when my sketch sizes went over 85%. Have you made any progress?

Hi @hemming1,

After a lot of experiments and trials (PIR, SSD1306, g8lib, Mega and Uno shield) my conclusion is that my CC3000 has very hard stability problems. In any case around topics in the web I’ve discovered that there are many topics on CC3000 stability. What i’ve observed was that randomly (may be min or hours) CC3000 lost the communication and freeze and only by reset it starts to work again. I’ve tried also to include reset software (i.e. Watchdog) in my code but sometime it is not enough (may be someone can suggest me a good code).
This is my experience. Now I’m working on Esp8266-07 that it seems (at least up to now) more stable. I’ll report my results I hope good this time.

Hi @zetalif, did you have a conclusion after all this time?

I’m going to include an SPI OLED like yours in my project and I’m wondering if this problem is finally solved.

Thanks!