ESP32+bmp280+ST7735+MCP2301 + Blynk

English is not my mother’s language, so pardon me for that, probably I was tired too. None of my messages were intended to offend anyone here. I feel grateful for any help I get here, just to make that clear.

I appologize especially to Gunner if any of my messages were disrespectful in any way. All I meant to say was that I don’t expect anyone to do any research for me. I only expected some help from someone who did something similar and has already some experience to share.

I used the BMP280(later BME) sensors on I2C and it works fine. I only use an extra pin after all(comparing to SPI+ 1 aditional pin for chip select_ and hopefully, I can make the mcp23017 work correctly so I can add some buttons. As soon as everything works fine I will connect the device to Blynk.

I corrected my previous messages. Again, I am sorry about that.
At the moment, the display(the only one on spi), the bmp280 and the mcp23017 work fine all together without Blynk.

BUT, here is the Blynk part of this project. As soon as it gets connected to the Blynk server, the display gets white and it won’t display anything anymore.

What bigger(than the 0.96" ssd1306) displays have you managed to use with ESP32 and Blynk?

#define NAMEandVERSION "OfflineTask_Reconnect_V1.0"
/*
  This sketch is based on an example posted by Gunner with some modifications added in place to make it able to reconnect after Wifi or Server connection failures.
  It is able to check if it is a Wifi or a server connection issue and recover it when it is possible
  The MCU runs the task every second - It turns the builtin led on and off (allways) and post the millis/1000 to blynk server (only when a connection is available).
*/

#define BLYNK_DEBUG
#define BLYNK_TIMEOUT_MS  500  // must be BEFORE BlynkSimpleEsp8266.h doesn't work !!!
#define BLYNK_HEARTBEAT   17   // must be BEFORE BlynkSimpleEsp8266.h works OK as 17s

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_PRINT Serial    
#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789



char ssid[]            = "xxxx";
char pass[]            = "xxxxx";
char auth[]            = "xxxxxxxxxx";
//char server[]          = "blynk-cloud.com";
//char server[]          = IPAddress(192,168,1,xxx);
unsigned int port      = xxxx; //use your own port of the server

bool on = 0;
bool online = 0;

bool theLEDState = 0;

 // for ESP32 I2C 22 scl - 21 sda
  #define TFT_MOSI 23  // SDA 
  #define TFT_SCLK  18  // SCL
  #define TFT_CS   15  // CS
  *#define TFT_RST  5   // reset*
  #define TFT_DC   4   // a0
  //

// If you dont want to use DHCP 
IPAddress arduino_ip ( 192,  168,   1,  xx);
IPAddress dns_ip     ( 192,  168,   1,   1);
IPAddress gateway_ip ( 192,  168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

BlynkTimer timer;
WidgetTerminal terminal(V1);
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;


void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  Serial.begin(115200);
  Serial.println();
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab
  tft.setRotation(2);
  WiFi.setHostname(NAMEandVERSION);
  WiFi.mode(WIFI_STA);
  Blynk.config(auth, IPAddress(192,168,1,3), port);  // I am using the local Server

  
  CheckConnection();// It needs to run first to initiate the connection.Same function works for checking the connection!
  timer.setInterval(5000L, CheckConnection); 
  timer.setInterval(1000L, myTimerEvent); 
  timer.setInterval(10000L, tftPrintTest); 
}

void loop() {
  if(Blynk.connected()){
    Blynk.run();
  }
  timer.run();
}


void CheckConnection(){    // check every 11s if connected to Blynk server
  if(!Blynk.connected()){
    online = 0;
    yield();
    if (WiFi.status() != WL_CONNECTED)
    {
      Serial.println("Not connected to Wifi! Connect...");
      //Blynk.connectWiFi(ssid, pass); // used with Blynk.connect() in place of Blynk.begin(auth, ssid, pass, server, port);
      WiFi.config(arduino_ip, gateway_ip, subnet_mask);
      WiFi.begin(ssid, pass);
      delay(400); //give it some time to connect
      if (WiFi.status() != WL_CONNECTED)
      {
        Serial.println("Cannot connect to WIFI!");
        online = 0;
      }
      else
      {
        Serial.println("Connected to wifi!");
      }
    }
    
    if ( WiFi.status() == WL_CONNECTED && !Blynk.connected() )
    {
      Serial.println("Not connected to Blynk Server! Connecting..."); 
      Blynk.connect();  // // It has 3 attempts of the defined BLYNK_TIMEOUT_MS to connect to the server, otherwise it goes to the enxt line 
      if(!Blynk.connected()){
        Serial.println("Connection failed!"); 
        online = 0;
      }
      else
      {
        online = 1;
      }
    }
  }
  else{
    Serial.println("Connected to Blynk server!"); 
    online = 1;    
  }
}


void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  if (online == 1)
  {
    Blynk.virtualWrite(V5, millis() / 1000);    
  }
  else 
  {
    Serial.println("Working Offline!");  
  }
  
  if (on == 0)
  {
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)    
    on = 1;
  }
  else
  {
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW                  
    on = 0;
  }
  Serial.println(millis() / 1000);
}


void tftPrintTest() {
  Serial.println("TestDisplay");
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  delay(2000);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.print(" seconds.");
  Serial.println("Display END");
  delay(2000);
}

LE: replaced gpio2 with gpio5 for the display reset. GPIO2 was used by the builtin led. the display is fully working now with blynk. proceeding

1 Like