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 ( with DHT22
Particle Photon ( 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 (
 * 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)
 *      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

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()
    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: ");

    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() {

void loop()
  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
	if (!bDHTstarted) {		// start the sample
	    Serial.print(": Retrieving information from sensor: ");
	    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("Error\n\r\tChecksum error");
		    Serial.println("Error\n\r\tISR time out error");
		    Serial.println("Error\n\r\tResponse time out error");
		    Serial.println("Error\n\r\tData time out error");
		    Serial.println("Error\n\r\tDelta time to small");
		    Serial.println("Error\n\r\tNot started");
		    Serial.println("Unknown error");

	    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.print("Dew Point Slow (oC): ");

	    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.