DHT 11 use to work with my Blynk App

Hello,

I just recently re-flashed my Particle Photon (last night); I have several connected to my 2.4 network. I finally realized last night I was only able to flash my Photons OTA when I set the board the Magenta Safe Mode. Every time I tried to flash (Saving firmware first) without Magenta Safe Mode, the console would show “Flash Started” but eventually showed “Flash Failed”. Only when I was in Safe Mode did I actually get to compile the firmware to the board.

This took several hours to figure out, no more flashing for me unless I’m in Safe Mode…

The Particle Console, after successfully flashing in Safe Mode only displays the “DHT11 - PLANT IT AND IT SHALL GROW” once, but never displays the Temperature or Humidity readings or displays them in the Blynk App like it use to.
image

I’m running two (2) Photons that have DHT11 hooked up. One board has been running for over two years, displaying both Humidity and Temperature both in the Particle Console and the Blynk App Gage Modules. But all of this effort has been erased now that I have updated my firmware as of yesterday - the other board with the same wiring never worked as I only recently started working on it.

My code is a bit jumbled, it was parsed with other examples and it worked for several years flawlessly but no longer does, does anyone see something obvious in my code? I can still control a relay etc from the App but I want my information to Publish again and show up in the Blynk App (Temp/Humidity) - Which it does not.

Any help would be great. I’m also running 0.7.0 on the boards because anything higher caused my Photons to FLASH SOS RED (I made a separate topic on this in 2019 and it was resolved)

My App was working before I flashed last night:

//11-27-2018
//     Version1: float temp = (float)DHT.getFahrenheit(); was (float)DHT.getCelcius();
//               Particle.publish("DHT11 - firmware version", VERSION, 60, PRIVATE); was Particle.publish("DHT22 - firmware version", VERSION, 60, PRIVATE);
//               Particle.publish("The temperature from the dht11 is:", tempInChar, 60, PRIVATE); was Particle.publish("The temperature from the dht22 is:", tempInChar, 60, PRIVATE);
//               Particle.publish("The humidity from the dht11 is:", tempInChar, 60, PRIVATE); was Particle.publish("The humidity from the dht22 is:", tempInChar, 60, PRIVATE);
//     Comments: App switches back and forth on reading and displays deciminal points.


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

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

// This #include statement was automatically added by the Particle IDE.   (07/31/2020 - NEW VERSION ADDED) 
#include <PietteTech_DHT.h>

// system defines
#define DHTTYPE  DHT11              // Sensor type DHT11/21/22/AM2301/AM2302
//#define DHTPIN   4         	    // Digital pin for communications
#define DHTPIN   5         	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   60000  // Sample every minute


//declaration
void dht_wrapper(); // must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;	      // Next time we want to start sample
bool bDHTstarted;		             // flag to indicate we started acquisition
int n;                              // counter

//this is coming from http://www.instructables.com/id/Datalogging-with-Spark-Core-Google-Drive/?ALLSTEPS
char resultstr[64]; //String to store the sensor data

//DANGER - DO NOT SHARE!!!!
char auth[] = "NOT FOR YOUR EYES"; // Put your blynk token here
//DANGER - DO NOT SHARE!!!!

char VERSION[64] = "0.04";
#define READ_INTERVAL 60000





void setup()
{
    
 System.disableUpdates();
 
 //STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));    
 
 Blynk.begin(auth);
 DHTnextSampleTime = 0;  // Start the first sample immediately
 Particle.variable("result", resultstr, STRING);
 Particle.publish("DHT11 - PLANT IT AND IT SHALL GROW", VERSION, 60, PRIVATE);
 
}
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() 
{
    DHT.isrCallback();
}

void loop()
{

  Blynk.run(); // all the Blynk magic happens here
 

  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
      
	if (!bDHTstarted) {		// start the sample
	    DHT.acquire();
	    bDHTstarted = true;
	}

 if (!DHT.acquiring()) {		// has sample completed?

  float temp = (float)DHT.getFahrenheit();
  int temp1 = (temp - (int)temp) * 100;

  char tempInChar[32];
  sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
  Particle.publish("The temperature from the dht11 is:", tempInChar, 60, PRIVATE);

  //virtual pin 1 will be the temperature
  Blynk.virtualWrite(V1, tempInChar);
  Blynk.virtualWrite(V3, tempInChar);
 
  //google docs can get this variable
  //sprintf(resultstr, "{\"t\":%s}", tempInChar);

  float humid = (float)DHT.getHumidity();
  int humid1 = (humid - (int)humid) * 100;

  sprintf(tempInChar,"%0d.%d", (int)humid, humid1);
  Particle.publish("The humidity from the dht11 is:", tempInChar, 60, PRIVATE);

  //virtual pin 2 will be the humidity
  Blynk.virtualWrite(V2, tempInChar);
  Blynk.virtualWrite(V4, tempInChar);
  
  n++;  // increment counter
  bDHTstarted = false;  // reset the sample flag so we can take another
  DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
 }
 
}

}

I'm not surprised and neither should you be :wink:

Your code features this line

To debug your DHT11 issue you may want to add some strategically useful logging to your code and see what your code can tell you about the possible causes.

I do have a log I created in the code (but didn’t copy and paste) where I log any new change, with the date etc. for record keeping. But I think you may be talking about a different kinda logging…

I did include the below so my Board would not update the DEVICE OS automatically to the latest revision, as I want to keep 0.7.0 on the board. Do I have the wrong mind set here? Before I put that code in, my other board was updating to a higher DEVICE OS that actually caused me to SOS.

System.disableUpdates();

I think what is also problematic is that maybe since I wasn’t aware of flashing in Safe Mode until last night, that all my last few weeks of trying to fix things may not have been actually being pushed to the board because I was never in safe mode… so, I was doing work for nothing and not making any progress.

This is what happens when I do not work day-in-day-out with the hardware…I tend work for days and weeks and when it works…“I SET IT AND FORGET IT” !

-Jason

System.disableUpdates() disables any firmware upload - including application.
As long your application is targeted at 0.7.0 the device OS will never be updated.
But when you build against anything past 0.7.0 your application requires a device OS update and won't run unless the device OS is upgraded too.

It is your responsibility to build your application against the correct device OS version. Select the wrong target any you will have to upgrade the device OS.

ScruffVR

Thanks for that information, I am eager to try this later and see if I can flash successfully and get the readings I am looking for. I will report back tonight on my findings.

You are right, I always make sure to check the DEVICE OS version before I do any flashing.

I hope removing that command System.disableUpdates() will bring clarity back into my life lol

Regards,

-Jason

Another thing you should change
instead of

  if (millis() > DHTnextSampleTime) {
    ...
    DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
  }

it’s better to do this

  if (millis() - dhtLastSampleTime >= DHT_SAMPLE_INTERFAL) {
    ...
    dhtLastSampleTime = millis();
  }

I will update my History Log with any new changes and apply accordingly.

I really would like to be more familiar with this - just need to keep working on it more often as to not forget all that has been learned etc.

Thanks!

-Jason

1 Like

Dangit. Updated in Safe Mode but no display of Temp/ Humidity in Blynk App or Console after the changes. Hmmm.

I feel like it’s very close.

Libraries:
image

Modified the code:

// 08-25-2020
//      System.disableUpdates() disables any firmware upload - including application.

//01-03-2020
//      Disabled STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));

//09-27-2019
//      Inserted System.disableUpdates(); in the Void setup()  

//09-24-2019
//     Removed and inserted updated Library for #include <PietteTech_DHT.h>;

//02-18-2019
//     Version2: STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));
//
//
//11-27-2018
//     Version1: float temp = (float)DHT.getFahrenheit(); ---WAS--- (float)DHT.getCelcius();
//               Particle.publish("DHT11 - firmware version", VERSION, 60, PRIVATE); ---WAS--- Particle.publish("DHT22 - firmware version", VERSION, 60, PRIVATE);
//               Particle.publish("The temperature from the dht11 is:", tempInChar, 60, PRIVATE); ---WAS--- Particle.publish("The temperature from the dht22 is:", tempInChar, 60, PRIVATE);
//               Particle.publish("The humidity from the dht11 is:", tempInChar, 60, PRIVATE); ---WAS--- Particle.publish("The humidity from the dht22 is:", tempInChar, 60, PRIVATE);
//     Comments: App switches back and forth on reading and displays deciminal points.


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

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

// system defines
#define DHTTYPE  DHT11              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   4         	    // Digital pin for communications
#define DHTPIN   5         	    // Digital pin for communications
#define DHTPIN   6         	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   60000  // Sample every minute


//declaration
void dht_wrapper(); // must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;	      // Next time we want to start sample
unsigned int dhtLastSampleTime;
bool bDHTstarted;		             // flag to indicate we started acquisition
int n;                              // counter

//this is coming from http://www.instructables.com/id/Datalogging-with-Spark-Core-Google-Drive/?ALLSTEPS
char resultstr[64]; //String to store the sensor data

//DANGER - DO NOT SHARE!!!!
char auth[] = "-----------------------------------"; // Put your blynk token here
//DANGER - DO NOT SHARE!!!!

char VERSION[64] = "0.04";
#define READ_INTERVAL 60000








void setup()
{
    
 //System.disableUpdates();
 
 //STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));    
 
 Blynk.begin(auth);
 DHTnextSampleTime = 0;  // Start the first sample immediately
 Particle.variable("result", resultstr, STRING);
 Particle.publish("PLANT IT AND IT SHALL GROW", VERSION, 60, PRIVATE);
 
}
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() 
{
    DHT.isrCallback();
}

void loop()
{

  Blynk.run(); // all the Blynk magic happens here
 

  // Check if we need to start the next sample
  if (millis() - dhtLastSampleTime >= DHT_SAMPLE_INTERVAL)  {
      }
	if (!bDHTstarted) {		// start the sample
	    DHT.acquire();
	    bDHTstarted = true;
	}

 if (!DHT.acquiring()) {		// has sample completed?

  float temp = (float)DHT.getFahrenheit();
  int temp1 = (temp - (int)temp) * 100;

  char tempInChar[32];
  sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
  Particle.publish("The temperature from the dht11 is:", tempInChar, 60, PRIVATE);

  //virtual pin 1 will be the temperature
  Blynk.virtualWrite(V1, tempInChar);
  Blynk.virtualWrite(V3, tempInChar);
 
  //google docs can get this variable
  //sprintf(resultstr, "{\"t\":%s}", tempInChar);

  float humid = (float)DHT.getHumidity();
  int humid1 = (humid - (int)humid) * 100;

  sprintf(tempInChar,"%0d.%d", (int)humid, humid1);
  Particle.publish("The humidity from the dht11 is:", tempInChar, 60, PRIVATE);

  //virtual pin 2 will be the humidity
  Blynk.virtualWrite(V2, tempInChar);
  Blynk.virtualWrite(V4, tempInChar);
  
  n++;  // increment counter
  bDHTstarted = false;              // reset the sample flag so we can take another
  dhtLastSampleTime = millis();     // set the time for next sample
 
 }
 
}

You should try the most recent version of the DHT library (0.0.12).
Also try the samples of that version to see whether you get any readings at all.

With that you may even be able to move away of this ancient 0.7.0 of the device OS. version

When I was talking about logging I didn’t mean a static change log but dynamic logging statements (e.g. Serial.println() or Log.xxx()) in your code that reveals the internal state (variables and code flow) of your code at interesting points.

Hi Scruff,

I will try the Library, I had added a few weeks back but If I was not pushing the Application/Firmware due to NOT being in Safe Mode. I don’t think any of that work mattered, since it was uploading the firmware.

I will give it a whirl.

I figured you meant an actual Serial Log - but I do the Static Manual Logging for my own personal understanding on the code - which helps me when I pick up from a few months ago etc.

Thanks for all the help so far - I really want to get this connected, more work to do!

Thanks,

Hatch

Updated with newest Library:
image

Unfortunately, no change yet on the readings. I don’t have any readings coming through or displaying any bit of information (even if it was wrong information), as if the DHT 11 is not even connected! I also swapped the DHT11 with three (3) other ones on my bench, but it’s not a hardware related issue. I checked the voltage on the pins and they are where they should be, so connections points are solid.

I will have to try some of the examples as you mentioned. After I flash the Photon, I get a one time display of “Plant It” - it is however, the only thing that publishes properly and that is all I see.

void setup()
{
    
 //System.disableUpdates();
 
 //STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));    
 
 Blynk.begin(auth);
 DHTnextSampleTime = 0;  // Start the first sample immediately
 Particle.variable("result", resultstr, STRING);
 Particle.publish("PLANT IT", VERSION, 60, PRIVATE);
 
}

image

Still no luck, couldn’t even get the examples to register anything!

I’m at a loss here.

-Jason

I took the example, changed the DHTPIN from D3 to D2 (as you’ve got it) and the DHTTYPE to DHT11 and got this

So my only assumptions can be

  • you wiring is off
  • your GPIO pin is dead
  • all your sensors are bunk

Hi Scruff,

Assuming the assumptions are correct (wiring, GPIO, Bunk sensors), shouldn't my original code at least publish to the console the following? (Not even talking about displaying in the Blynk App, but the Particle Console alone is "waiting for events"

Particle.publish("The Temperature from the dht11 is:", tempInChar, 60, PRIVATE);
Particle.publish("The humidity from the dht11 is:", tempInChar, 60, PRIVATE);

You also mentioned changing from D3 to D2 (Like I have it) - where do I have D2 defined?

Thanks,

-Jason

Sorry, there I had a different user/thread in mind - I can try again with D5 as in your original code.
However, these redefinitions are definitely not recommended

About the not published events, I'd first focus on getting the sensor(s) to work and then see why that is.


Update:

D5 works just the same (built against 1.5.2)
Have you tried my sample to see whether your sensors work with it (on the correct pin - a mod that should not have been to difficult, even when I was wrong about D2)?


On a side note (as the code line is commented out anyway):

The STARTUP() macro is not ment to be placed inside any other function.
https://docs.particle.io/reference/device-os/firmware/photon/#startup-

Also this could be refined

to

  float temp = DHT.getFahrenheit();

  char tempInChar[32];
  sprintf(tempInChar,"%.2f", temp);
  Particle.publish("The temperature from the dht11 is:", tempInChar, PRIVATE);

or even further into a single event

  float temp  = DHT.getFahrenheit();
  float humid = DHT.getHumidity();
  char  data[64];
  snprintf(data, sizeof(data),"Temperature: %4.1f °F, Humidity %3.1f %%", temp, humid);
  Particle.publish("DHT11 reports:", data, PRIVATE);

Thanks for posting, made some modifications - no change.

Going to continue to chip away at this. I doubt my custom breakoutboard has anything to do with it, but I will revert to a breadboard to eliminate any of that (though, I don’t expect any difference).

Gotta keep chipping away - might be a long night!

-Jason

Have you tried the sample?

I have got your code posting valid data, but I’m not yet revealing the solution (a single line) since I still want you to try my example code and if that works spot the difference.

Insight will stick better when found after some effort rather than getting it provided free :wink:

I will work on the example tonight.

lol - OH MAN! A single line solution!!! ? lol

Well, I will certainly keep trying to find the solution and may come begging lol. It’s probably pretty obvious or straightforward , but I’m missing it.

-Jason

One hint: it’s a single line in setup() you are missing (at least I hope that’s it - if not, I’ll post you a SHARE THIS REVISION link to a slightly overhauled version of your code)

You are talking about the original code missing from setup() right?

LOL - Okay, let me put on my thinking cap, my glasses and turn on my eyes/brain.

Thanks,

-Jason