ESP 32 Problems

Hi Today I recived my ESP32 and I am having problems running my Arduino sketch. It used to work on the ESP8266 and the Arduino Uno when I changed the libraries. But with the ESP32 I am getting lots of errors. One error is that the ESP sometimes freezes at Connecting to “Wifi Name” and after lots of reboots it connects but the disconnectes with this error. I tought maybe the pin allocations are the problem?

[1045] Connected to WiFi
[1045] IP: 192.168.0.xxx
[1045] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.7 on ESP32

[5001] Connecting to blynk-cloud.com:8442
[5241] Ready (ping: 117ms).
[10242] Connecting to blynk-cloud.com:8442
[10442] Ready (ping: 80ms).
[10587] Time sync: OK
Guru Meditation Error of type IntegerDivideByZero occurred on core  1. Exception was unhandled.
Register dump:
PC      : 0x4011974b  PS      : 0x00060930  A0      : 0x800d1323  A1      : 0x3ffcce60  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000400  
A6      : 0xfffffcff  A7      : 0x3ffcbf80  A8      : 0x3ffc2f70  A9      : 0x3ffcce40  
A10     : 0x5932c3c8  A11     : 0x3ffc2f6c  A12     : 0x3ffcce60  A13     : 0x3ffc2e88  
A14     : 0x00000000  A15     : 0x3ffcbf80  SAR     : 0x0000001f  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x400d27c9  LEND    : 0x400d27e9  LCOUNT  : 0x00000006  

Backtrace: 0x4011974b:0x3ffcce60 0x400d1323:0x3ffcce80 0x400d262b:0x3ffccea0 0x400d1cb2:0x3ffccec0 0x40111e23:0x3ffccee0

CPU halted.

Here is the code

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space

#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire (22);

WidgetRTC rtc;

#define white 22
#define blue 21

#define SUNRISE 9*60 + 0
#define DAWN 10*60 + 0
#define DUSK 16*60 + 0
#define SUNSET 17*60 + 0

#define drain_bucket_full 34
#define fill_bucket_empty 35
#define aquarium_empty 36
#define aquarium_full 39

#define Fill_Pump 16
#define solenoid 17

#define watersensor 18

int sensor = 0;

WidgetLED Pump(V2);
WidgetLED Solenoid(V7);
WidgetLED Done(V8);
WidgetLED Auto(V9);
WidgetLED error(V10);

WidgetLED blueled(V12);
WidgetLED whiteled(V11);

BlynkTimer timer;

unsigned long previousMillis = 0;

int brightness;

boolean fill;
boolean drain;
boolean emergencystop = 0;
boolean automatic = 0;
boolean refilling = 0;
boolean draining = 0;
boolean start = 0;

char auth[] = "50107b8ccxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "Clxxxxxxxxxxxxxxxx";
char pass[] = "clxxxxxxxxxxxxxxxxxx";

DallasTemperature sensors(&oneWire);

BLYNK_WRITE(V0) // At global scope (not inside of the function)

{
  if ( param.asInt() == 1 )
  {
    fill = 1;
  }
  else
  {
    fill = 0;
  }

}

BLYNK_WRITE(V1) // At global scope (not inside of the function)

{
  if ( param.asInt() == 1 )
  {

    drain = 1;
  }
  else
  {
    drain = 0;
  }

}




BLYNK_WRITE(V5) // At global scope (not inside of the function)

{
  if ( param.asInt() == 1 )
  {
    automatic = 1;
    Auto.on();
    start = 0;

  }
  else
  {
    automatic = 0;
    Auto.off();
    Done.off();
  }

}

BLYNK_WRITE(V6) // At global scope (not inside of the function)

{
  if ( param.asInt() == 1 )
  {
    emergencystop = 1;

  }
  else
  {
    emergencystop = 0;

  }

}


BLYNK_WRITE(V3) // At global scope (not inside of the function)

{
  if ( param.asInt() == 1 )
  {
    int D7 = digitalRead(drain_bucket_full);
    int D6 = digitalRead(aquarium_empty);
    int D5 = digitalRead(fill_bucket_empty);
    int D8 = digitalRead(aquarium_full);
    sensor = digitalRead(watersensor);
    BLYNK_LOG("drain bucket full (%d) = %d, aquarium_empty (%d) = %d, fill_bucket_empty (%d) = %d , aquarium_full (%d) = %d , watersensor = %d ", drain_bucket_full, D7, aquarium_empty, D6, fill_bucket_empty, D5, aquarium_full, D8, sensor);
    BLYNK_LOG("fill = %d , drain = %d, emergency Stop = %d, Automatic = %d, Refilling = %d, Draning = %d", fill, drain, emergencystop, automatic, refilling, draining);
  }


}
void water() {

  sensor = digitalRead(watersensor);

  //Aquarium Filling
  //---------------------------------------------------------------------------------------------------------------------

  if (sensor == 0 && automatic == 0 && fill == 1 && digitalRead(fill_bucket_empty) == HIGH && digitalRead(aquarium_full) == LOW)
  {
    digitalWrite(Fill_Pump, HIGH);
    Pump.on();
  }
  else if (automatic == 0 && fill == 0 || digitalRead(fill_bucket_empty) == LOW || digitalRead(aquarium_full) == HIGH)
  {
    digitalWrite(Fill_Pump, LOW);
    Pump.off();
  }
  //---------------------------------------------------------------------------------------------------------------------

  //Aquarium Draining
  //--------------------------------------------------------------------------------------------------------------------
  if (sensor == 0 && automatic == 0 && drain == 1 && digitalRead(drain_bucket_full) == LOW && digitalRead(aquarium_empty) == HIGH) {
    digitalWrite(solenoid, HIGH);
    Solenoid.on();
  }
  else if (automatic == 0 && drain == 0 || digitalRead(drain_bucket_full) == HIGH || digitalRead(aquarium_empty) == LOW) {
    digitalWrite(solenoid, LOW);
    Solenoid.off();
  }
  //------------------------------------------------------------------------------------------------------------------------


  if (sensor == 0 && start == 0 && automatic == 1 && digitalRead(drain_bucket_full) == LOW && digitalRead(aquarium_empty) == HIGH) {
    digitalWrite(solenoid, HIGH);
    Done.off();



    Solenoid.on();

  }

  else if (drain == 0  && automatic == 0 || digitalRead(drain_bucket_full) == HIGH || digitalRead(aquarium_empty) == LOW) {
    digitalWrite(solenoid, LOW);



    Solenoid.off();
    Done.off();
  }


  if (sensor == 0 && automatic == 1 && digitalRead(fill_bucket_empty) == HIGH && digitalRead(aquarium_empty) == LOW && digitalRead(aquarium_full) == LOW)
  {
    digitalWrite(Fill_Pump, HIGH);
    start = 1;


    Pump.on();

  }
  else if (fill == 0 && automatic == 0 || digitalRead(fill_bucket_empty) == LOW ||  digitalRead(aquarium_full) == HIGH)
  {
    digitalWrite(Fill_Pump, LOW);




  }


  if (automatic == 1 && digitalRead(aquarium_full) == HIGH && digitalRead(solenoid) == LOW && digitalRead(Fill_Pump) == LOW )
  {

    Done.on();
  }



  if (sensor == 1)
  {

    error.on();
    automatic = 0;
    fill = 0;
    drain = 0;

  }
  else
  {
    error.off();
  }

  if (emergencystop == 1)
  {
    automatic = 0;
    fill = 0;
    drain = 0;
    Pump.off();
    Solenoid.off();
    Auto.off();
    Done.off();


  }

}

void temp() {
  sensors.requestTemperatures();
  float currentTemp;
  currentTemp = sensors.getTempCByIndex(0);
  Blynk.virtualWrite(V4, currentTemp); // Virtual 0

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 14400000 ) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    if (currentTemp > 30)
    {
      Blynk.notify("Temperature Exceeded 30°C");
    }
    else if (currentTemp < 26)
    {
      Blynk.notify("Temerature is Below 26°C");
    }
  }
}
/*
  // Digital clock display of the time
  void clockDisplay()
  {

  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details
  BLYNK_LOG("Current time: %02d:%02d:%02d %02d %02d %d",
            hour(), minute(), second(),
            day(), month(), year());
  }
*/

void turn_on() {
  int value = 0;
  int msm = hour() * 60 + minute(); //minutes since midnight

  if ( msm < SUNRISE ) {
    value = 0;
  } else if (msm < DAWN) {
    value = map(msm, SUNRISE, DAWN, 0, 1024);
  } else if (msm < DUSK ) {
    value = 1024;
  } else if (msm < SUNSET ) {
    value = map(msm, DUSK, SUNSET, 1024, 0);
  } else {
    value = 0;
  }

  brightness = map(brightness, 0, 0, 1024, 255);

  whiteled.setValue(brightness);
  blueled.setValue(brightness);


  BLYNK_LOG("Time: %d %d - setting lights to %d", hour(), minute(), value);
  digitalWrite(blue, value);
  digitalWrite(white, value);

}


void setup() {
  //WiFi.mode(WIFI_STA);
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);


  while (Blynk.connect() == false) {}
  pinMode(white, OUTPUT);
  pinMode(blue, OUTPUT);


  pinMode(drain_bucket_full, INPUT_PULLUP);
  pinMode(fill_bucket_empty, INPUT_PULLUP);
  pinMode(aquarium_empty, INPUT_PULLUP);
  pinMode(watersensor, INPUT_PULLUP);
  pinMode(aquarium_full, INPUT_PULLUP);

  // Begin synchronizing time
  rtc.begin();

  pinMode(Fill_Pump, OUTPUT);
  pinMode(drain, OUTPUT);

  fill = 0;
  drain = 0;

  timer.setInterval(10000L, turn_on);
  //  timer.setInterval(1000L, clockDisplay);
  timer.setInterval(10000L, temp);
  timer.setInterval(300L, water);

}

void loop() {
  Blynk.run();

  timer.run();


}

Sounds like an ESP issue, not necessarily Blynk related

Have you tried Googling your error? There are some suggestions for debugging.

https://www.google.com/search?q=Guru+Meditation+Error+of+type+IntegerDivideByZero+occurred+on+core+1.+Exception+was+unhandled.&oq=Guru+Meditation+Error+of+type+IntegerDivideByZero+occurred+on+core++1.+Exception+was+unhandled.&aqs=chrome..69i57&sourceid=chrome&ie=UTF-8

Thanks I will try this tomorrow to maybe find the problem. Next week I should get the Wemos Lolin board so I will know if my Esp board is the problem.

When I said ESP problem, I wasn’t meaning the hardware was faulty, per se, rather how the ESP (firmware) handles just about anything that it doesn’t understand. It could very well be a pinout issue, a corrupted library, bad code (for the ESP32 vs ESP8266), etc.

That is where the ESP based debugging will help.

This link seems to have some good pointers… at least to a guy that has only Arduinos :slight_smile:

https://www.esp32.com/viewtopic.php?t=263

HI again these past days I have been experimenting with the Esp and didn`t get any crashes but some times the Esp will get stuck in Connecting to “WiFi Name” and I have to reset the board with the reset button several times and some times unplugging from the computer and back in. Then later I found that the Widget Leds are the problem. (I have 7 in my dashboard) When I add them back to the sketch I sometimes get flood error but then reconnects and getting stuck at connecting to “WiFi Name” happens more often. Can this be the problem or another on that I haven’t discovered?

Thanks

Yes, a flood error (sending too much and/or too fast) effectively interrupts the ESP’s WiFi communication loop… which as I understand can be picky about such things, and you lose the connection.

This is where using timers to spread out commands and data streams can help.

But the flood errors are not that of a problem I mean they only occur when sending a lot of data. My concern is when booting up the module why does it get stuck at Connecting to Wifi?