Particle Photon

Particle Photon and DHT22

Particle Photon and DHT22

The Particle Photon is a Cloud connected IoT device.
It has:

  • Broadcom BCM43362 Wi-Fi chip
  • STM32F205 120Mhz ARM Cortex M3 with 1MB flash, 128KB RAM
  • USB connection

More details can be found on Particle’s data sheet.

Particle Photon
Particle Photon
Particle Photon (Spark.io) with DHT22
Particle Photon (Spark.io) with DHT22

After initial setup which can be non smooth one can set up the Photon with a DHT22.

Sadly the supplied dht library from   Adafruit fails with an error in the online Arduino software mimicking  environment.

One has to use a library called PietteTech_DHT.

And use it with the following code:

/*
 * FILE:        DHT_example.ino
 * VERSION:     0.3
 * PURPOSE:     Example that uses DHT library with two sensors
 * LICENSE:     GPL v3 (http://www.gnu.org/licenses/gpl.html)
 *
 * Example that start acquisition of DHT sensor and allows the
 * loop to continue until the acquisition has completed
 * It uses DHT.acquire and DHT.acquiring
 *
 * Change DHT_SAMPLE_TIME to vary the frequency of samples
 *
 * Scott Piette (Piette Technologies) scott.piette@gmail.com
 *      January 2014        Original Spark Port
 *      October 2014        Added support for DHT21/22 sensors
 *                          Improved timing, moved FP math out of ISR
 */

#include "PietteTech_DHT/PietteTech_DHT.h"

// system defines
#define DHTTYPE  DHT22              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   5         	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   2000  // Sample every two seconds

//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

void setup()
{
    Serial.begin(9600);
    while (!Serial.available()) {
        Serial.println("Press any key to start.");
        delay (1000);
    }
    Serial.println("DHT Example program using DHT.acquire and DHT.aquiring");
    Serial.print("LIB version: ");
    Serial.println(DHTLIB_VERSION);
    Serial.println("---------------");

    DHTnextSampleTime = 0;  // Start the first sample immediately
}


// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht_wrapper() {
    DHT.isrCallback();
}

void loop()
{
  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
	if (!bDHTstarted) {		// start the sample
	    Serial.print("\n");
	    Serial.print(n);
	    Serial.print(": Retrieving information from sensor: ");
	    DHT.acquire();
	    bDHTstarted = true;
	}

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

	    // get DHT status
	    int result = DHT.getStatus();

	    Serial.print("Read sensor: ");
	    switch (result) {
		case DHTLIB_OK:
		    Serial.println("OK");
		    break;
		case DHTLIB_ERROR_CHECKSUM:
		    Serial.println("Error\n\r\tChecksum error");
		    break;
		case DHTLIB_ERROR_ISR_TIMEOUT:
		    Serial.println("Error\n\r\tISR time out error");
		    break;
		case DHTLIB_ERROR_RESPONSE_TIMEOUT:
		    Serial.println("Error\n\r\tResponse time out error");
		    break;
		case DHTLIB_ERROR_DATA_TIMEOUT:
		    Serial.println("Error\n\r\tData time out error");
		    break;
		case DHTLIB_ERROR_ACQUIRING:
		    Serial.println("Error\n\r\tAcquiring");
		    break;
		case DHTLIB_ERROR_DELTA:
		    Serial.println("Error\n\r\tDelta time to small");
		    break;
		case DHTLIB_ERROR_NOTSTARTED:
		    Serial.println("Error\n\r\tNot started");
		    break;
		default:
		    Serial.println("Unknown error");
		    break;
	    }

	    Serial.print("Humidity (%): ");
	    Serial.println(DHT.getHumidity(), 2);

	    Serial.print("Temperature (oC): ");
	    Serial.println(DHT.getCelsius(), 2);

	    Serial.print("Temperature (oF): ");
	    Serial.println(DHT.getFahrenheit(), 2);

	    Serial.print("Temperature (K): ");
	    Serial.println(DHT.getKelvin(), 2);

	    Serial.print("Dew Point (oC): ");
	    Serial.println(DHT.getDewPoint());

	    Serial.print("Dew Point Slow (oC): ");
	    Serial.println(DHT.getDewPointSlow());

	    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
	}
    }
}

When attaching the DHT in the usual setup to the Photon, one uses the clearly labelled. 3.3v, GND and D5 pin on the Photon from the DHT22.

Photon Pin Markings
Photon Pin Markings

More info can be found on Particles website.

Sadly the Photon keeps disconnecting the Computers Wifi, when one connects Serial Tools on MacOS El Capitan on my Late 2014 MacBook Pro 16 GB + Nvidia 750M.

After I managed to play up this sketch all readings were -2 and an error was thrown with several DHT22 in my possession.

I connected the USB of the Photon then to my i5, 8GB Palit Jetstream Geforce 970 running Ubuntu 14.04 LTS (USB 3.0) and after several minutes I finally got valid results in GTK Stream. Switching then back to Mac OS X El Capitan showed then suddenly with an unchanged setup  results in SerialTools.

Serial Output pf the DHT22 test sketch on my Photon
Serial Output pf the DHT22 test sketch on my Photon

Since I have setup now the DHT22 on an Arduino Uno, a Duemilanove Clone, Sparkfun Fio, Arduino Nano, and Ciseco (Wireless things) rfu328 and a teensy the whole setup is in my opinion over complicated. Every reboot is accompanied with a lengthy wait until the Photon connects to the cloud and this is equally annoying as Microsoft reboots before SSDs were wide spread. Prepare to be annoyed.

This whole webinterface, cloud thing just adds unnecessary complicity, time and failure points.

There is a local tool, but it seems to maintain cloud connectedness.

So any project use on the Photon, needs to offset this cloud connectedness trade off and the interference of several companies in your data collection. Also remember if your internet is down, your data collection may be down.

Over the air programming and Wifi and many things more can be easier, faster and cheaper achieved with the usual existing Arduino’s, Pi’s and so on.

Querying your serial port or intranet is not so difficult in XCode, .Net or whatever you use. Is the advertised Mobile easy app integration worth the trade off?

If you buy an arduino, teensy, rfu 328 it is yours. This Photon is only yours as long as Particle Sparks is up and your ISP allows it.

An experience with a Swann Security Cam with Cloud connection showed me how fickle this cloud can be. First suddenly they charged money and then their cloud was down.  Additionally all Android app reviews of slightly older models complained about non updated apps.

The cloud might have uses, but I am not sure if really everything needs to be on it.