When I flash my code Boron will turn solid white

Hello,

Im trying to run a tipping bucket rain gauge, Ds18b20, and monitor the power using fuel gauge all in the same time. When I run rain gauge and temp it works fine, when I run rain gauge and fuel it works fine. When I run all three, the boron turn solid white.

Side problem- for some reason once in a blue the rain gauge will log rain but there is no rain. For example it indoor right now and it will log 2 to 5 tip, sometimes more. For days it was running fine but when I power off and on sometime it acts up again. This could be a hardware issues. Im getting new rain gauges tomorrow. But it could be code issue and im just not seeing it.

Im new to coding so im sure I did something wrong. Im hoping someone smarter then me will see the issue and help get this running properly. Here is the code. Thank you very much for your time

// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>

// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

#include <math.h>

#ifndef TOKEN
#define TOKEN "A1E-"  // Put here your Ubidots TOKEN
#endif


FuelGauge fuel;
char data[64];


Ubidots ubidots(TOKEN, UBI_EDUCATIONAL, UBI_TCP); //Use "UBI_EDUCATIONAL" when using ubidots education



// Each time we loop through the main loop, we check to see if it's time to capture the sensor readings
unsigned int sensorCapturePeriod = 100;
unsigned int timeNextSensorReading;

// Each time we loop through the main loop, we check to see if it's time to publish the data we've collected
unsigned int publishPeriod = 60000;
unsigned int timeNextPublish; 

//STARTUP(WiFi.selectAntenna(ANT_AUTO)) //use exteral (WIFI ONLY) antenna if connected

DS18B20  ds18b20(D2, true); //Sets Pin D2 for Water Temp Sensor and 


void setup() {
    
    Serial.begin(115200);
    ubidots.setDebug(true);  // Comment this line for printing debug messages
    initializeRainGauge();
    
//Solar Power Managment     
    //PMIC pmic; //Initalize the PMIC class so you can call the Power Management functions below. 
    //pmic.setChargeCurrent(0,0,1,0,0,0); //Set charging current to 1024mA (512 + 512 offset)
    //pmic.setInputVoltageLimit(4840);   //Set the lowest input voltage to 4.84 volts. This keeps my 5v solar panel from operating below 4.84 volts.  

 
    // Schedule the next sensor reading and publish events
    timeNextSensorReading = millis() + sensorCapturePeriod;
    timeNextPublish = millis() + publishPeriod; 
}

void loop() {

    // Capture any sensors that need to be polled (temp, humidity, pressure, wind vane)
    // The rain and wind speed sensors use interrupts, and so data is collected "in the background"
    if(timeNextSensorReading <= millis()) {
        captureTemp();

        // Schedule the next sensor reading
        timeNextSensorReading = millis() + sensorCapturePeriod;
    }
    
    // Publish the data collected to Particle and to ThingSpeak
    if(timeNextPublish <= millis()) {
        
        // Get the data to be published
        
        float tempF = getAndResetTempF();
        float rainInches = getAndResetRainInches();
   

        float voltage = fuel.getVCell();
        float SoC = fuel.getSoC();
    
        // Publish the data                    
        publishToParticle(tempF,rainInches,voltage,SoC);
        // Schedule the next publish event
        timeNextPublish = millis() + publishPeriod;
    }
    
    delay(10);
}

void publishToParticle(float tempF, float rainInches,float voltage,float SoC) {
    //Particle.publish("Rain", String::format(" %0.2f in",rainInches),60 , PRIVATE);    


snprintf(data, sizeof(data), "%0.1f°F,%.2f in,%.2f V,%.2f %%",tempF,rainInches,voltage,SoC);
  Particle.publish("TP1", data, PRIVATE);
//Ubidots 
ubidots.add("Rain", rainInches);
ubidots.add("Temp", tempF);
ubidots.add("Volts", voltage);
ubidots.add("SoC", SoC);
ubidots.send();
  
}
//===========================================================================
// Temp DS18B20
//===========================================================================

    float tempFTotal = 0.0;
    unsigned int tempFReadingCount = 0;

void captureTemp() {
       
    float celsius =  ds18b20.getTemperature();
    float tempF = ds18b20.convertToFahrenheit(celsius);
  
  
 
  //If the result is reasonable, add it to the running mean
  if(tempF > -50 && tempF < 150)
  {
      
       // Add the observation to the running sum, and increment the number of observations
      tempFTotal += tempF;
      tempFReadingCount++;
      
  }

return;
}

float getAndResetTempF()
{
    if(tempFReadingCount == 0) {
        return 0;
    }
    float result = tempFTotal/float(tempFReadingCount);
    tempFTotal = 0.0;
    tempFReadingCount = 0;
    return result;
}
//===========================================================================
// Rain Guage
//===========================================================================
int RainPin = D4;
volatile unsigned int rainEventCount;
unsigned int lastRainEvent;
float RainScaleInches = 0.01; // Each pulse is .01 inches of rain

void initializeRainGauge() {
  pinMode(RainPin, INPUT_PULLUP);
  rainEventCount = 0;
  lastRainEvent = 0;
  attachInterrupt(RainPin, handleRainEvent, FALLING);
  return;
  }
  
void handleRainEvent() {
    // Count rain gauge bucket tips as they occur
    // Activated by the magnet and reed switch in the rain gauge, attached to input D2
    unsigned int timeRainEvent = millis(); // grab current time
    
    // ignore switch-bounce glitches less than 10mS after initial edge
    if(timeRainEvent - lastRainEvent < 10) {
      return;
    }
    
    rainEventCount++; //Increase this minute's amount of rain
    lastRainEvent = timeRainEvent; // set up for next event
}

float getAndResetRainInches()
{
    float result = RainScaleInches * float(rainEventCount);
    rainEventCount = 0;
    return result;
}

You can try the new official realeas 0.9.0 to see whether this changes anything.
Also what Boron are you using? (2G/3G or LTE)

With millis() timings it's always better to use (millis() - previousEvent > eventPeriod) instead of precalculating the next trigger time and check for (triggerTime <= millis())
Reasoning behind that can be found in this thread

Any solid colour typically indicates some kind of device OS deadlock which can be caused (amongst others) by ISRs, noInterrupt() calls (possibly in any of the used libraries), concurrent use of shared resources (e.g. HW interfaces) between application and device OS.

1 Like

Hey ScruffR, Thanks for your reply. I have LTE. I tried changing the millis() part but because Im new in coding I keep getting errors when I compile. Ill keep trying.

Thanks again

1 Like