Photon is restaring over and over

I try to send 4 sensor data to Particle.io cloud. I use cds, gas sensors and DHT11.
Cds and Gas sensor combo works OK, but after I connect DHT11 problem sterts. Photon is restarting over and over. LED on Photon is switching magenta to green over and over. So I cannot update firmware to the photon.

I am wondering it is code problem or hardware problem. Here is my code.
Please please let me know. THank you people.

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

#include "thingspeak/thingspeak.h"
ThingSpeakLibrary::ThingSpeak thingspeak ("DAB3KTRWFUCAI7RX");

#define DHTPIN 6
#define DHTTYPE DHT11    
DHT dht(DHTPIN, DHTTYPE);

int led1 = D0;
int led2 = D7;
int cdsInput = A0;
int gasInput = A1;

int cdsValue = 0;
int gasValue = 0;
int humidValue = 0;
int tempValue = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);

  //Particle.function("led",ledToggle);
  Particle.variable("cdsRead", &cdsValue, INT);
  Particle.variable("gasRead", &gasValue, INT);
  //Particle.variable("humidRead", &humidValue, INT);
  //Particle.variable("tempRead", &tempValue, INT);

  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
}

void loop() {
    
  Serial.println("Loop start"); 
  
  
    float humidValue = dht.getHumidity();
    float tempValue = dht.getTempCelcius();
    float faren = dht.getTempFarenheit();
  /*
      if (isnan(humidValue) || isnan(tempValue) || isnan(faren)) {
        Serial.println("Failed to read from DHT sensor!");
        humidValue = -5000;
        tempValue  = -5000;
        return;
    }
  */

  cdsValue = analogRead(cdsInput);
  gasValue = analogRead(gasInput);
  
  
  
//Sending data to Particle.io cloud Server;  
  
  Particle.publish("cdsRead", String(cdsValue));
  Particle.publish("gasRead", String(gasValue));
  //Particle.publish("humidRead", String(humidValue));
  //Particle.publish("tempRead", String(tempValue));



// Sending data to Thingspeak
    bool valSet1 = thingspeak.recordValue(1, String(gasValue, DEC));
    bool valsSent1 = thingspeak.sendValues();
    
    bool valSet2 = thingspeak.recordValue(2, String(cdsValue, DEC));
    bool valsSent2 = thingspeak.sendValues();
    
    bool valSet3 = thingspeak.recordValue(3, String(humidValue, DEC));
    bool valsSent3 = thingspeak.sendValues();
    
    bool valSet4 = thingspeak.recordValue(4, String(tempValue, DEC));
    bool valsSent4 = thingspeak.sendValues();
    
      if(valSet1) {
        Serial.println("Value set to field 1 : " + String(gasValue, DEC));
    } else {
        Serial.println("Value not set successfully");
    }
    
    
       if(valsSent1) {
       Serial.println("Value successfully sent to thingspeak");
   } else {
       Serial.println("Sending to thingspeak failed");
   }
   
    
     if(valSet2) {
        Serial.println("cdsValue set to field 2 : " + String(cdsValue, DEC));
    } else {
        Serial.println("cdsValue not set successfully");
    }
    
     if(valsSent2) {
       Serial.println("gasValue successfully sent to thingspeak");
   } else {
       Serial.println("gasSending to thingspeak failed");
   } 
    
delay(5000);
}

A common tip for this on the forum is to use the PietteTech_DHT library instead, since the Adafruit one causes blocking.

2 Likes

Thanks for the answer… I feel great about it. However I haver another problem with my photon, now. I finish coding and start flashing firmware, but I cannot successfully upload the new firmware because of restarting.
So I tried to reset photon over and over but I cannot reset the photon.

Hmmmmmm Please help me how to reset and erase previous firmware.

You’d have to elaborate a bit more what kind of restarting you experience.

Could it be the auto update that uploads three parts of firmware with restarts in between? If so you’d have to let it finish and not reset in between.
Otherwise what kind of color pattern do you see?

2 Likes

What I do is Hold down the setup button while inserting the power , release when you see the led power .
Use the web ide and install blink , if a firmware upgrade as happened .
Now install the real code .

1 Like

Here’s a quick vine showing how to get into safe mode. That’ll stop your app from running so you can flash a new one:

https://docs.particle.io/guide/getting-started/modes/photon/#safe-mode

Thanks!
David

I have a bad new. I just Changed library, but it’s not working. Same thing happens. Funny thing is when I use only 2 variables it works, but when I put 4 variables the photon is restarting over and over again. So I will try couple more tests to go. the first assumption is power. I will try to add extra 3.3v instead of usb cable. So wish me luck.

I understand how to reflashing the device. Pressing setup btn and reset btn fast then purple( I mean red and blue). Then purple LED is flashing. That is the time for the flashing new code.

So I solve one part of the problem. I tried PietteTech_DHT library, but same thing happens. So is there other ways to solve this problem? I know I can use 2 photons for a project. Also I learn a lot about it. but I still want to use 1 photon to send 4 data at once. Thanks a lot.

Just to clarify: Your Particle.variable() instances have nothing to do with Particle.publish().
So I’m convinced that you can have all four Particle.variable()s set up.

About the Particle.publish() it’s a different story.
Your device has got a rate limit of one publish per second with a burst of four which your code seems to offend without you knowing.
The thing is that Particles publish two system events upon connect and with your immediately following four publishes you hit the limit.
This should not kill the cloud connection, but it might contribute.
Try putting your delay(5000) to the top of loop() to have a gap between the system events and your own.

It works in a way. It seems like there are conflicts between analog sensor data and DHT11’s data. When I turn on Analog Data DHT11’s data is not logging in thingspeak.

Thanks again. so far, I understand how to reset Photon and DHT11’s data is logging on Thingspeak.