GIGA board disconnects while trying to upload

Hey folks, I've been trying to upload a sketch with multiple .ino files but the board disconnects and the red led starts blinking (4 delayed flashes followed by 4 fast flashes). I tried to put it in bootloader mode and upload an example GIGA sketch (multiblink). which uploads fine. but when i try again with my code the same error repeats

In file included from G:\My Drive\Projects\Onion project\Code\Cloud Sketches\Control board\GIGA\Control_inHouse_wo_regen_GIGA\Variables.h:5:0,
                 from G:\My Drive\Projects\Onion project\Code\Cloud Sketches\Control board\GIGA\Control_inHouse_wo_regen_GIGA\Control_inHouse_wo_regen_GIGA.ino:4:
C:\Users\john\Documents\Arduino\libraries\ES135xx/ES135xx.h:41:16: warning: 'uint8_t crc8(const uint8_t*, int)' declared 'static' but never defined [-Wunused-function]
 static uint8_t crc8(const uint8_t *data, int len);

Compiling library "OneWire"
"C:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-g++" -c -Wall -Wextra -g3 -nostdlib "@C:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\variants\\GIGA/defines.txt" "@C:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\variants\\GIGA/cxxflags.txt" -MMD -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv5-d16 -DARDUINO=10607 -DARDUINO_GIGA -DARDUINO_ARCH_MBED_GIGA -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=0 "-IC:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\cores\\arduino" "-IC:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\variants\\GIGA" "-IC:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\libraries\\Wire" "-IC:\\Users\\john\\Documents\\Arduino\\libraries\\OneWire" "-IC:\\Users\\john\\Documents\\Arduino\\libraries\\DallasTemperature" "-IC:\\Users\\john\\Documents\\Arduino\\libraries\\ES135xx" -DCM4_BINARY_START=0x60000000 -DCM4_BINARY_END=0x60040000 -DCM4_RAM_END=0x60080000 "-IC:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\cores\\arduino/api/deprecated" "-IC:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\cores\\arduino/api/deprecated-avr-comp" "-iprefixC:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\cores\\arduino" "@C:\\Users\\john\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\mbed_giga\\4.1.1\\variants\\GIGA/../GIGA/includes.txt" "C:\\Users\\john\\Documents\\Arduino\\libraries\\OneWire\\OneWire.cpp" -o "C:\\Users\\john\\AppData\\Local\\Temp\\arduino\\sketches\\5AB1D001514B43500416D66CD0F9A32F\\libraries\\OneWire\\OneWire.cpp.o"
C:\Users\john\Documents\Arduino\libraries\OneWire\OneWire.cpp: In member function 'uint8_t OneWire::reset()':
C:\Users\john\Documents\Arduino\libraries\OneWire\OneWire.cpp:167:24: warning: unused variable 'reg' [-Wunused-variable]
  volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;
                        ^~~
C:\Users\john\Documents\Arduino\libraries\OneWire\OneWire.cpp: In member function 'void OneWire::write_bit(uint8_t)':
C:\Users\john\Documents\Arduino\libraries\OneWire\OneWire.cpp:201:24: warning: unused variable 'reg' [-Wunused-variable]
  volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;
                        ^~~
C:\Users\john\Documents\Arduino\libraries\OneWire\OneWire.cpp: In member function 'uint8_t OneWire::read_bit()':
C:\Users\john\Documents\Arduino\libraries\OneWire\OneWire.cpp:229:24: warning: unused variable 'reg' [-Wunused-variable]
  volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;
                        ^~~

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
Device ID 2341:0366
Device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash  2MB   "
Downloading element to address = 0x08040000, size = 134824

Erase   	[                         ]   0%            0 bytes
Erase   	[                         ]   0%            0 bytes
Erase   	[=                        ]   6%         8192 bytes
Erase   	[==                       ]   9%        12288 bytes
Erase   	[===                      ]  12%        16384 bytes
Erase   	[====                     ]  18%        24576 bytes
Erase   	[=====                    ]  21%        28672 bytes
Erase   	[======                   ]  24%        32768 bytes
Erase   	[=======                  ]  30%        40960 bytes
Erase   	[========                 ]  33%        45056 bytes
Erase   	[=========                ]  36%        49152 bytes
Erase   	[==========               ]  42%        57344 bytes
Erase   	[===========              ]  45%        61440 bytes
Erase   	[============             ]  48%        65536 bytes
Erase   	[=============            ]  54%        73728 bytes
Erase   	[==============           ]  57%        77824 bytes
Erase   	[===============          ]  60%        81920 bytes
Erase   	[================         ]  66%        90112 bytes
Erase   	[=================        ]  69%        94208 bytes
Erase   	[==================       ]  72%        98304 bytes
Erase   	[===================      ]  78%       106496 bytes
Erase   	[====================     ]  82%       110592 bytes
Erase   	[=====================    ]  85%       114688 bytes
Erase   	[======================   ]  88%       118784 bytes
Erase   	[=======================  ]  94%       126976 bytes
Erase   	[======================== ]  97%       131072 bytes
Erase   	[=========================] 100%       134824 bytes
Erase    done.

Download	[                         ]   0%            0 bytes
Download	[=                        ]   6%         8192 bytes
Download	[==                       ]   9%        12288 bytes
Download	[===                      ]  12%        16384 bytes
Download	[====                     ]  18%        24576 bytes
Download	[=====                    ]  21%        28672 bytes
Download	[======                   ]  24%        32768 bytes
Download	[=======                  ]  30%        40960 bytes
Download	[========                 ]  33%        45056 bytes
Download	[=========                ]  36%        49152 bytes
Download	[==========               ]  42%        57344 bytes
Download	[===========              ]  45%        61440 bytes
Download	[============             ]  48%        65536 bytes
Download	[=============            ]  54%        73728 bytes
Download	[==============           ]  57%        77824 bytes
Download	[===============          ]  60%        81920 bytes
Download	[================         ]  66%        90112 bytes
Download	[=================        ]  69%        94208 bytes
Download	[==================       ]  72%        98304 bytes
Download	[===================      ]  78%       106496 bytes
Download	[====================     ]  82%       110592 bytes
Download	[=====================    ]  85%       114688 bytes
Download	[======================   ]  88%       118784 bytes
Download	[=======================  ]  94%       126976 bytes
Download	[======================== ]  97%       131072 bytesWarning: Invalid DFU suffix signature
A valid DFU suffix will be required in a future dfu-util release

Download	[=========================] 100%       134824 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state

i thought maybe the ES135xx and onewire libraries were not compatible with the board but when i tried to upload a sample code using those libraries they too upload and run well.

Here's my sketch.
main .ino file:

  #include <Wire.h>
  #include <math.h>
  #include "Variables.h"
  #include "PinAssign.h"
  #include "MyConstants.h"

// Interrupt Service Routines
 void flow1ISR() {
   flow1++;
 }
 void flow2ISR() {
   flow2++;
 }

//Function declaration
 void SensorReadings();
 void Dehumidification();
 void BoardReset();
 void CheckFloat();
 void Cooling();

 void select_channel(uint8_t channel){
  Wire.beginTransmission(PCA9548A);
  Wire.write(1 << channel);
  Wire.endTransmission();
 }

void setup(){
  Serial.begin(9600);

 //Float Pins
    pinMode(top1,INPUT);
    pinMode(bottom1,INPUT); 
 //DS18B20   
    pinMode(ONE_WIRE_BUS, INPUT_PULLUP);
 //Valve relays
    pinMode(t1d,OUTPUT);
    pinMode(t2d,OUTPUT);
    pinMode(t1r,OUTPUT);
    pinMode(t2r,OUTPUT);
    pinMode(dt1,OUTPUT);
    pinMode(dt2,OUTPUT);
    pinMode(rt1,OUTPUT);
    pinMode(rt2,OUTPUT);
    Serial.println("Valve relays defined\n");
  //12V Relays
    pinMode(h1,OUTPUT);
    pinMode(h2,OUTPUT);
    Serial.println("Heater relays defined\n");
  //Pump Relays
    pinMode(dsp,OUTPUT);
    pinMode(drp,OUTPUT);
    pinMode(rsp,OUTPUT);
    pinMode(rrp,OUTPUT);
    pinMode(dpc1,OUTPUT);
    pinMode(dpc2,OUTPUT);
    Serial.println("Pump relays defined\n");
  //Fan Relays
    pinMode(rf,OUTPUT);
    pinMode(df,OUTPUT);
    pinMode(fcu,OUTPUT);
    Serial.println("Fan relays defined\n");
  // Configure the interrupt pins
    pinMode(FLOW_SENSOR_1, INPUT_PULLUP);
    pinMode(FLOW_SENSOR_2, INPUT_PULLUP);  
 
    previousTime = millis();

 //SHT connection  
    //Precision setting
      Precision = PRECISION_HIGH;
      Heater = NO_HEATER;

    // Initialize first sensor
      select_channel(SENSOR1_CHANNEL);
      Serial.println("Initializing first ES13511 sensor");
      ES135xx_probe();
      delay (1000);

    // Initialize second sensor
      select_channel(SENSOR2_CHANNEL);
      Serial.println("Initializing second ES13511 sensor");
      ES135xx_probe();
      delay(1000);   

 //Temp sensor
    // Start up the library
      sensors.begin();      
 
 //Flow sensor interrupts  
  // Attach the interrupts
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_1), flow1ISR, RISING);
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_2), flow2ISR, RISING);        

 //Turn on fan at the start
  digitalWrite(df, HIGH);
  Serial.println("\nFan ON");
}

void loop(){
  
  //On-board timer
   currentTime   = millis(); 

  SensorReadings();
  Dehumidification();
  Cooling();
  BoardReset();

 delay(1000);
}```


Void Sensorreadings:
```#include "PinAssign.h"
#include "MyConstants.h"
#include "Variables.h"
// #include "thingProperties.h"

void SensorReadings(){
  //CheckFloat
    //Assign float positions
    const int floatState1_1 = digitalRead(top1);
    const int floatState1_2 = digitalRead(bottom1);

    //Check Float level  
    if((floatState1_1 == LOW && floatState1_2 == HIGH) && !add_salt){
      lowTrig1 = true;
      //preferences.putBool("lowTrig1", lowTrig1); // Save lowTrig1 state
            
    }else if (floatState1_1 == HIGH && floatState1_2 == LOW){
      lowTrig1 = false;
      //preferences.putBool("lowTrig1", lowTrig1); // Save lowTrig1 state
      Serial.println("Weak solution...Turning OFF Dehumidifier\n");
      dehumidifier_status = false;
      add_salt = true;
      
    }/*else{
      lowTrig1 = preferences.getBool("lowTrig1", false);
    }*/
    Serial.println("\nFloat status: " + String(lowTrig1));
    
    delay(1000);

  extern float ES135xx_Temp;
  extern float ES135xx_Hum;
  //SHT reading  
    //Storage SHT
      //Storage room sensor
        select_channel(SENSOR1_CHANNEL);
        ES135xx_read_T_H();
        storage_hum = ES135xx_Hum;
        storage_temp = ES135xx_Temp;
        Serial.print("Storage Temp = " + String(ES135xx_Temp) + " C " + " Storage RH = " + String(ES135xx_Hum) + "% | ");  
      // Utility sensor
        select_channel(SENSOR2_CHANNEL);
        ES135xx_read_T_H();
        utility_hum = ES135xx_Hum;
        utility_temp = ES135xx_Temp;
        Serial.print("Utility Temp = " + String(ES135xx_Temp) + " C " + " Utility RH = " + String(ES135xx_Hum) + "% | ");
                       
  //DS18B20
    // call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
    sensors.requestTemperatures(); 
    //Calibration
    /*float rawTempC = sensors.getTempCByIndex(0);
    float calibratedTempC = rawTempC + CALIBRATION_OFFSET;
    
    if(rawTempC == -127.00) 
    {
      Serial.println("Error: Could not read temperature data");
    }
    else 
    {
      Serial.print("Temperature: ");
      Serial.println(calibratedTempC);
    }*/
   
    Serial.print("Temperature 1: ");
    Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one DS18B20 on the same bus. 0 refers to the first IC on the wire
    Serial.print(" Temperature 2: ");
    Serial.println(sensors.getTempCByIndex(1)); // Why "byIndex"? You can have more than one DS18B20 on the same bus. 1 refers to the second IC on the wire

  //Flow Sensor
    // Disable the interrupts
    detachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_1));
    detachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_2));

    // Calculate the flow rate in L/min
    float flowRate1 = (flow1 / 7.5); // Sensor 1 (FS300A outputs approximately 7.5 pulses per liter)
    float flowRate2 = (flow2 / 7.5); // Sensor 2

    // Print the flow rates
    Serial.println("Flow rate sensor 1: " + String(flowRate1) + " L/min |" + " Flow rate sensor 2: " + String(flowRate2) + " L/min");

    // Reset the pulse counters
    flow1 = 0;
    flow2 = 0;

    // Reattach the interrupts
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_1), flow1ISR, RISING);
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_2), flow2ISR, RISING);

  // Serial.print("Comma seperated string below:\n");

    // // Send the data to ESP32
    //   select_channel(SENSOR1_CHANNEL);
    //   ES135xx_read_T_H();
    //   Serial.print("Data: " + String(ES135xx_Temp) + "," + String(ES135xx_Hum) + ",");
    //   select_channel(SENSOR2_CHANNEL);
    //   ES135xx_read_T_H();
    //   Serial.print(String(ES135xx_Temp) + "," + String(ES135xx_Hum) + ",");
    //   Serial.print(String(sensors.getTempCByIndex(0)) + ",");   // 0 refers to the first IC on the wire
    //   Serial.println(String(sensors.getTempCByIndex(1)) + ","); //  1 refers to the second IC on the wire  

 delay(1000);
}

Void Dehumidification and cooling:

#include "PinAssign.h"
#include "MyConstants.h"
#include "Variables.h"


void Dehumidification(){

//Loop when system on
   //FCU turned on every 60 minute interval or storage_hum > 75
   if((!FanisON && (currentTime - previousTime >= fan_OFF)) || ((storage_hum - avg_hum >= d_on_bypass) && bypass))  
     {
      if(currentTime - previousTime >= fan_OFF){
        Serial.println("Time>60min");
      }
      else{
        Serial.println("High humidity detected");
      }
      Serial.println("Fan ON");
      digitalWrite(df,HIGH);
      FanisON = true;
      bypass  = false;
      if(!add_salt){
        dehumidifier_status = true;
      }
      previousTime = currentTime;
      //EEPROM.put(rtcaddress,previousTime);
     }
   
   //FCU runs for 10 minutes. Check humidity reading next  
   else if(FanisON && (currentTime - previousTime >= fan_ON))  
     {
      if(currentTime - previousTime >= fan_ON){
        Serial.println("Time>10mins");
      }
      if(dehumidifier_status){
        //Humidity greater than or equal to 65
        if((storage_hum - avg_hum >= d_on))
          {
            Serial.println("Dehumidifier ON");
            Serial.println("Desiccant supply : Tank 1");
            digitalWrite(t1d,HIGH);
            digitalWrite(dt1,HIGH);
            delay (1000);
            digitalWrite(dsp, HIGH);
            digitalWrite(drp, HIGH);    
          }

        //Humidity less than or equal to 60   
        else if((storage_hum -avg_hum <= d_off))
          {
            Serial.println("Low Humidity");
            digitalWrite(df,  LOW);
            dehumidifier_status = false;
            previousTime = currentTime;
            //EEPROM.put(rtcaddress,previousTime);
          } 
      }
      else{
        digitalWrite(df,LOW);
        Serial.println("Fan OFF");
        previousTime = currentTime;
      }  
    }
     
   else if(!dehumidifier_status)
    {
      digitalWrite(dsp, LOW);
      digitalWrite(drp, LOW);
      delay(1000);
      digitalWrite(t1d, LOW);
      digitalWrite(dt1, LOW);
      Serial.println("Dehumidifier OFF");
      FanisON = false;
      bypass  = true;
      delay(2000);
      // EEPROM.update(fanaddress,false);
    }
}

void Cooling(){
  select_channel(SENSOR1_CHANNEL);
  ES135xx_read_T_H();
  if(storage_temp - avg_temp >= dpc_on){
    digitalWrite(fcu,HIGH);
    digitalWrite(df,HIGH);
    digitalWrite(dpc1,HIGH);
    digitalWrite(dpc2,HIGH);
    Serial.println("Dew point cooler ON");
  }
  else if(avg_temp - storage_temp >= dpc_off){
    digitalWrite(fcu,LOW);
    digitalWrite(dpc1,LOW);
    digitalWrite(dpc2,LOW);
    if(!dehumidifier_status){
      digitalWrite(df,LOW);
    }
    Serial.println("Dew point cooler OFF");
  }
}

Void board reset:

#include "PinAssign.h"
#include "Variables.h"

//reset function
void (* resetFunc) (void) = 0;

void BoardReset(){
  /*Board reset*/
   //Reset board if in operation for 24 hours
 if(currentTime - resetMillis >= sys_reset){  
        digitalWrite(dsp, LOW);
        digitalWrite(drp, LOW);
        digitalWrite(t1d, LOW);
        digitalWrite(dt1, LOW);
        digitalWrite(df , LOW);    
      // digitalWrite(rf , LOW)
        Serial.println("Reset Board");
        delay(2000);
        resetMillis = currentMillis;
        resetFunc();  
    }
}

any help would be appreciated

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.


I'm not familiar with the Giga so can't advise further.

Hi @temperate. Please share the other files of the sketch. To get started, I need to know the values of FLOW_SENSOR_1 and FLOW_SENSOR_2.

main .ino

//Libraries 
  #include <Wire.h>
  #include <math.h>
  #include "Variables.h"
  #include "PinAssign.h"
  #include "MyConstants.h"

// Interrupt Service Routines
 void flow1ISR() {
   flow1++;
 }
 void flow2ISR() {
   flow2++;
 }

//Function declaration
 void SensorReadings();
 void Dehumidification();
 void BoardReset();
 void CheckFloat();
 void Cooling();

 void select_channel(uint8_t channel){
  Wire.beginTransmission(PCA9548A);
  Wire.write(1 << channel);
  Wire.endTransmission();
 }

void setup(){
  Serial.begin(9600);

 //Float Pins
    pinMode(top1,INPUT);
    pinMode(bottom1,INPUT); 
 //DS18B20   
    pinMode(ONE_WIRE_BUS, INPUT_PULLUP);
 //Valve relays
    pinMode(t1d,OUTPUT);
    pinMode(t2d,OUTPUT);
    pinMode(t1r,OUTPUT);
    pinMode(t2r,OUTPUT);
    pinMode(dt1,OUTPUT);
    pinMode(dt2,OUTPUT);
    pinMode(rt1,OUTPUT);
    pinMode(rt2,OUTPUT);
    Serial.println("Valve relays defined\n");
  //12V Relays
    pinMode(h1,OUTPUT);
    pinMode(h2,OUTPUT);
    Serial.println("Heater relays defined\n");
  //Pump Relays
    pinMode(dsp,OUTPUT);
    pinMode(drp,OUTPUT);
    pinMode(rsp,OUTPUT);
    pinMode(rrp,OUTPUT);
    pinMode(dpc1,OUTPUT);
    pinMode(dpc2,OUTPUT);
    Serial.println("Pump relays defined\n");
  //Fan Relays
    pinMode(rf,OUTPUT);
    pinMode(df,OUTPUT);
    pinMode(fcu,OUTPUT);
    Serial.println("Fan relays defined\n");
  // Configure the interrupt pins
    pinMode(FLOW_SENSOR_1, INPUT_PULLUP);
    pinMode(FLOW_SENSOR_2, INPUT_PULLUP);  
 
    previousTime = millis();

 //SHT connection  
    //Precision setting
      Precision = PRECISION_HIGH;
      Heater = NO_HEATER;

    // Initialize first sensor
      select_channel(SENSOR1_CHANNEL);
      Serial.println("Initializing first ES13511 sensor");
      ES135xx_probe();
      delay (1000);

    // Initialize second sensor
      select_channel(SENSOR2_CHANNEL);
      Serial.println("Initializing second ES13511 sensor");
      ES135xx_probe();
      delay(1000);   

 //Temp sensor
    // Start up the library
      sensors.begin();      
 
 //Flow sensor interrupts  
  // Attach the interrupts
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_1), flow1ISR, RISING);
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_2), flow2ISR, RISING);        

 //Turn on fan at the start
  digitalWrite(df, HIGH);
  Serial.println("\nFan ON");
}

void loop(){
  
  //On-board timer
   currentTime   = millis(); 

  SensorReadings();
  Dehumidification();
  Cooling();
  BoardReset();

 delay(1000);
}

SensorReadings

#include "PinAssign.h"
#include "MyConstants.h"
#include "Variables.h"
// #include "thingProperties.h"

void SensorReadings(){
  //CheckFloat
    //Assign float positions
    const int floatState1_1 = digitalRead(top1);
    const int floatState1_2 = digitalRead(bottom1);

    //Check Float level  
    if((floatState1_1 == LOW && floatState1_2 == HIGH) && !add_salt){
      lowTrig1 = true;
      //preferences.putBool("lowTrig1", lowTrig1); // Save lowTrig1 state
            
    }else if (floatState1_1 == HIGH && floatState1_2 == LOW){
      lowTrig1 = false;
      //preferences.putBool("lowTrig1", lowTrig1); // Save lowTrig1 state
      Serial.println("Weak solution...Turning OFF Dehumidifier\n");
      dehumidifier_status = false;
      add_salt = true;
      
    }/*else{
      lowTrig1 = preferences.getBool("lowTrig1", false);
    }*/
    Serial.println("\nFloat status: " + String(lowTrig1));
    
    delay(1000);

  extern float ES135xx_Temp;
  extern float ES135xx_Hum;
  //SHT reading  
    //Storage SHT
      //Storage room sensor
        select_channel(SENSOR1_CHANNEL);
        ES135xx_read_T_H();
        storage_hum = ES135xx_Hum;
        storage_temp = ES135xx_Temp;
        Serial.print("Storage Temp = " + String(ES135xx_Temp) + " C " + " Storage RH = " + String(ES135xx_Hum) + "% | ");  
      // Utility sensor
        select_channel(SENSOR2_CHANNEL);
        ES135xx_read_T_H();
        utility_hum = ES135xx_Hum;
        utility_temp = ES135xx_Temp;
        Serial.print("Utility Temp = " + String(ES135xx_Temp) + " C " + " Utility RH = " + String(ES135xx_Hum) + "% | ");
                       
  //DS18B20
    // call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
    sensors.requestTemperatures(); 
    //Calibration
    /*float rawTempC = sensors.getTempCByIndex(0);
    float calibratedTempC = rawTempC + CALIBRATION_OFFSET;
    
    if(rawTempC == -127.00) 
    {
      Serial.println("Error: Could not read temperature data");
    }
    else 
    {
      Serial.print("Temperature: ");
      Serial.println(calibratedTempC);
    }*/
   
    Serial.print("Temperature 1: ");
    Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one DS18B20 on the same bus. 0 refers to the first IC on the wire
    Serial.print(" Temperature 2: ");
    Serial.println(sensors.getTempCByIndex(1)); // Why "byIndex"? You can have more than one DS18B20 on the same bus. 1 refers to the second IC on the wire

  //Flow Sensor
    // Disable the interrupts
    detachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_1));
    detachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_2));

    // Calculate the flow rate in L/min
    float flowRate1 = (flow1 / 7.5); // Sensor 1 (FS300A outputs approximately 7.5 pulses per liter)
    float flowRate2 = (flow2 / 7.5); // Sensor 2

    // Print the flow rates
    Serial.println("Flow rate sensor 1: " + String(flowRate1) + " L/min |" + " Flow rate sensor 2: " + String(flowRate2) + " L/min");

    // Reset the pulse counters
    flow1 = 0;
    flow2 = 0;

    // Reattach the interrupts
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_1), flow1ISR, RISING);
    attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_2), flow2ISR, RISING);



 delay(1000);
}

Dehumidifier & Cooling

#include "PinAssign.h"
#include "MyConstants.h"
#include "Variables.h"


void Dehumidification(){

//Loop when system on
   //FCU turned on every 60 minute interval or storage_hum > 75
   if((!FanisON && (currentTime - previousTime >= fan_OFF)) || ((storage_hum - avg_hum >= d_on_bypass) && bypass))  
     {
      if(currentTime - previousTime >= fan_OFF){
        Serial.println("Time>60min");
      }
      else{
        Serial.println("High humidity detected");
      }
      Serial.println("Fan ON");
      digitalWrite(df,HIGH);
      FanisON = true;
      bypass  = false;
      if(!add_salt){
        dehumidifier_status = true;
      }
      previousTime = currentTime;
      //EEPROM.put(rtcaddress,previousTime);
     }
   
   //FCU runs for 10 minutes. Check humidity reading next  
   else if(FanisON && (currentTime - previousTime >= fan_ON))  
     {
      if(currentTime - previousTime >= fan_ON){
        Serial.println("Time>10mins");
      }
      if(dehumidifier_status){
        //Humidity greater than or equal to 65
        if((storage_hum - avg_hum >= d_on))
          {
            Serial.println("Dehumidifier ON");
            Serial.println("Desiccant supply : Tank 1");
            digitalWrite(t1d,HIGH);
            digitalWrite(dt1,HIGH);
            delay (1000);
            digitalWrite(dsp, HIGH);
            digitalWrite(drp, HIGH);    
          }

        //Humidity less than or equal to 60   
        else if((storage_hum -avg_hum <= d_off))
          {
            Serial.println("Low Humidity");
            digitalWrite(df,  LOW);
            dehumidifier_status = false;
            previousTime = currentTime;
            //EEPROM.put(rtcaddress,previousTime);
          } 
      }
      else{
        digitalWrite(df,LOW);
        Serial.println("Fan OFF");
        previousTime = currentTime;
      }  
    }
     
   else if(!dehumidifier_status)
    {
      digitalWrite(dsp, LOW);
      digitalWrite(drp, LOW);
      delay(1000);
      digitalWrite(t1d, LOW);
      digitalWrite(dt1, LOW);
      Serial.println("Dehumidifier OFF");
      FanisON = false;
      bypass  = true;
      delay(2000);
      // EEPROM.update(fanaddress,false);
    }
}

void Cooling(){
  select_channel(SENSOR1_CHANNEL);
  ES135xx_read_T_H();
  if(storage_temp - avg_temp >= dpc_on){
    digitalWrite(fcu,HIGH);
    digitalWrite(df,HIGH);
    digitalWrite(dpc1,HIGH);
    digitalWrite(dpc2,HIGH);
    Serial.println("Dew point cooler ON");
  }
  else if(avg_temp - storage_temp >= dpc_off){
    digitalWrite(fcu,LOW);
    digitalWrite(dpc1,LOW);
    digitalWrite(dpc2,LOW);
    if(!dehumidifier_status){
      digitalWrite(df,LOW);
    }
    Serial.println("Dew point cooler OFF");
  }
}

BoardReset

#include "PinAssign.h"
#include "Variables.h"

//reset function
void (* resetFunc) (void) = 0;

void BoardReset(){
  /*Board reset*/
   //Reset board if in operation for 24 hours
 if(currentTime - resetMillis >= sys_reset){  
        digitalWrite(dsp, LOW);
        digitalWrite(drp, LOW);
        digitalWrite(t1d, LOW);
        digitalWrite(dt1, LOW);
        digitalWrite(df , LOW);    
      // digitalWrite(rf , LOW)
        Serial.println("Reset Board");
        delay(2000);
        resetMillis = currentMillis;
        resetFunc();  
    }
}

MyConstants.h

#ifndef MY_CONSTANTS_H
#define MY_CONSTANTS_H

//Humidity  constants
 const float d_on_bypass   =    10.00;    //Humidity difference to by pass turn OFF duration of FCU
 const float d_on          =    5.00 ;    //Humidity difference to turn on  dehumidification
 const float d_off         =    0.00 ;    //Humidity difference to turn off dehumidification
 const float avg_hum       =    60.00;    //Humidity ideal (against which the difference is to be measured)
//Temperature constants
  const float dpc_on       =     5.00; //Temperature difference to turn on DPC    
  const float avg_temp     =    28.00; //Temperature to be maintained
  const float dpc_off      =     1.00; //Temperature difference to turn off DPC  
//Time  constants
 const long int fan_ON     =   600000;    //turn ON  duration of FCU (10mins) 
 const long int fan_OFF    =  3600000;    //turn OFF duration of FCU (60mins)
 const long int sys_reset  = 86400000;    //Reset board after 24 hours  

#endif  

PinAssign.h

#ifndef RELAY_PINS_H
#define RELAY_PINS_H
#include <OneWire.h>
#include <DallasTemperature.h>

//Set i2c address for i2c multiplexer
 #define PCA9548A 0x70 //Add coressponding address 

//Assign one Wire Pin
  #define ONE_WIRE_BUS 6

//Assign address to i2c devices for communication with multiplexer
 #define SENSOR2_CHANNEL 1  //Storage side sensor
 #define SENSOR1_CHANNEL 0  //utility side sensor

//Flow Sensor Pins
  #define FLOW_SENSOR_1 4
  #define FLOW_SENSOR_2 5

// //Float pins 
  const int top1     =  5; //float 1
  const int bottom1  =  4;
//  const int top2     =  2; //float 2
//  const int bottom2  =  7;
//  const int ovr      = 11; //overflow protect*/

//5V Relay pins 
 const int dsp      = 22; //Dehumidifier Supply pump
 const int drp      = 23; //Dehumidifier Return pump
 const int rsp      = 24; //Regenerator Supply pump
 const int rrp      = 25; //Regenerator Return pump
 const int t1d      = 26; //tank 1 to Dehumidifier 
 const int dt1      = 27; //Dehumidifier to tank 1
 const int t2d      = 29; //tank 2 to Dehumidifier 
 const int dt2      = 28; //Dehumidifier to tank 2
 const int t1r      = 30; //tank 1 to Regenerator 
 const int rt1      = 31; //Regenerator to tank 1
 const int t2r      = 32; //tank 2 to Regenerator 
 const int rt2      = 33; //Regenerator to tank 2
 const int rf       = 34; //Regenerator fan
 const int df       = 35; //Dehumidifier fan
 const int fcu      = 36; //FCU for dpc
 const int dpc2     = 37; //Dew point cooler (old) 2
 const int dpc1     = 38; //Dew point cooler (old) 1

//12V Relay pins 
 const int h1       = 45; //Heater 1
 const int h2       = 46; //Heater 2

#endif

Variable.h

#ifndef VAR_H
#define VAR_H

#include "PinAssign.h"
#include <ES135xx.h>
// #include <RTClib.h>

// //Setup rtc instance
//  RTC_DS3231 rtc;

// Setup a oneWire instance to communicate with any OneWire devices
  OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor 
  DallasTemperature sensors(&oneWire);  

//Variables to calibrate ds18b20
  /*extern float RawHigh;
  extern float RawLow;
  extern float ReferenceHigh;
  extern float ReferenceLow;
  extern float RawRange;
  extern float ReferenceRange;*/
  extern float CALIBRATION_OFFSET;
//Variables to store Sensor Data
 extern uint8_t Precision, Heater;
 extern float storage_temp; 
 extern float storage_hum;
 extern float utility_temp;
 extern float utility_hum;
//Time variables
 extern unsigned long currentMillis;
 extern unsigned long previousTime;
 extern unsigned long currentTime; 
 extern unsigned long  resetMillis;  //Time variable for board reset
//extern boolean variables for valve control
 extern bool  lowTrig1;
//system status (Dehumidifier and Regenerator)
 extern bool dehumidifier_status;
 extern bool add_salt;
//extern boolean variables for FCU control
 extern bool FanisON;  //To check previous state of the fan
 extern bool bypass;   //To bypass 60 min interval if RH too high
//variables for Flow sensor 
 extern volatile int flow1; // Variable to store the pulse count from sensor 1
 extern volatile int flow2; // Variable to store the pulse count from sensor 2

#endif

Varialbles initialization.ino

#include "Variables.h" 
 

//Variables to calibrate DS18B20
  /*float RawHigh = 99.6;
  float RawLow = 0.5;
  float ReferenceHigh = 99.9;
  float ReferenceLow = 0;
  float RawRange = RawHigh - RawLow;
  float ReferenceRange = ReferenceHigh - ReferenceLow; 
  float CALIBRATION_OFFSET = (((RawValue - RawLow) * ReferenceRange) / RawRange) + ReferenceLow;*/
  float CALIBRATION_OFFSET = 0.00;
//Variables to store Sensor data
 float storage_hum;
 float storage_temp;
 float utility_hum;
 float utility_temp;
//Time variables
 unsigned long previousTime;
 unsigned long resetMillis = 0; //Time variable for board reset
 unsigned long currentMillis;
 unsigned long currentTime;
//boolean variables for valve control
 bool  lowTrig1;
 bool  lowTrig2;
 bool highTrig1;
 bool highTrig2;
//system status (Dehumidifier and Regenerator)
 bool dehumidifier_status = true;
 bool add_salt = false;
//boolean variables for FCU control
 bool FanisON  = true;  //To check previous state of the fan
 bool bypass   = true;  //To bypass 60 min interval if RH too high
//Variables for flow sensors
 volatile int flow1 = 0; // Variable to store the pulse count from sensor 1
 volatile int flow2 = 0; // Variable to store the pulse count from sensor 2 

I had a hypothesis that the Mbed OS crash might have been caused by attaching interrupts to mutually incompatible pins, but now that you have provided the pin numbers I can see that they are fine.

I did a little bit of looking at the rest of your code but didn't unfortunately spot anything that would cause a crash.


Where did you get the "ES135xx" library? When I search for that keyword on Google, the only relevant result I get is this forum topic.


I'm going to ask you to post the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to fail.
  6. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  7. Open a forum reply here by clicking the "Reply" button.
  8. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  9. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  10. Move the cursor outside of the code block markup before you add any additional text to your reply.
  11. Click the "Reply" button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:
    Upload icon on toolbar
    The "Open" dialog will open.
  6. Select the .txt file you saved from the "Open" dialog.
  7. Click the "Open" button.
    The dialog will close.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

i got it from here: Buy ES-13525 - 7Semi | SHT40 Humidity and Temperature Sensor Probe | Evelta

Scroll down to "Resources", you'll find the library there. It's not necessary to use this particular library as the sensor is also compatible with the Adafruit sht4x libraries.

These are locally manufactured SHT sensors. Maybe that's why you weren't able to find it on google.

as for the crashing issue i forgot to add Wire.begin(); in the setup. This was most likely the reason for the crash. The code uploads well after I made this correction.

Great job on tracking down the cause of the crash! Thanks for taking the time to post an update with your findings.

1 Like