Hi,
I have a core from the origional kickstarter project, however only recently have I had the time to sit down and play with the unit.
I did a firmware update (including the depp firmware update) and setup with a basic breadboard and a DHT22 to capture temp/humidity, my code flashes fine and runs however it appears to never be able to display the data on either serial or the particle console, code is below;
#include "PietteTech_DHT/PietteTech_DHT.h" // Uncomment if building in IDE
// system defines
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN 3 // Digital pin for communications
#define DHT_SAMPLE_INTERVAL 2000 // Sample every two seconds
/*
* NOTE: Use of callback_wrapper has been deprecated but left in this example
* to confirm backwards compabibility. Look at DHT_2sensor for how
* to write code without the callback_wrapper
*/
double temperature;
double humidity;
// globals
unsigned int DHTnextSampleTime; // Next time we want to start sample
bool bDHTstarted; // flag to indicate we started acquisition
int n; // counter
void dht_wrapper(); // must be declared before the lib initialization
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
void dht_wrapper() {
DHT.isrCallback();
}
void setup()
{
WiFi.on();
Particle.connect();
// Variables Exposed to Cloud
Particle.variable("temperature", temperature);
Particle.variable("humidity", humidity);
Particle.variable("time", Time.now());
Particle.publish("message: ", "I'm alive!");
Serial.begin(9600);
DHTnextSampleTime = 0; // Start the first sample immediately
}
void loop()
{
// Check if we need to start the next sample
if (millis() > DHTnextSampleTime) {
if (!bDHTstarted) { // start the sample
Particle.publish("message: ", "In loop() and trying to acquire from sensor");
DHT.acquire();
bDHTstarted = true;
Particle.publish("message: ", "Finished getting data from sensor");
}
if (!DHT.acquiring()) { // has sample completed?
// get DHT status
Particle.publish("message: ", "Going to check the result");
int result = DHT.getStatus();
Serial.print("Read sensor: ");
Particle.publish("message: ", "Read sensor");
switch (result) {
case DHTLIB_OK:
Serial.println("OK");
Particle.publish("message: ", "Good Data");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Error\n\r\tChecksum error");
Particle.publish("message: ", "Checksum sensor");
break;
case DHTLIB_ERROR_ISR_TIMEOUT:
Serial.println("Error\n\r\tISR time out error");
Particle.publish("message: ", "ISR time out error");
break;
case DHTLIB_ERROR_RESPONSE_TIMEOUT:
Serial.println("Error\n\r\tResponse time out error");
Particle.publish("message: ", "Response time out error");
break;
case DHTLIB_ERROR_DATA_TIMEOUT:
Serial.println("Error\n\r\tData time out error");
Particle.publish("message: ", "Data time out error");
break;
case DHTLIB_ERROR_ACQUIRING:
Serial.println("Error\n\r\tAcquiring");
Particle.publish("message: ", "Error Acquiring from sensor");
break;
case DHTLIB_ERROR_DELTA:
Serial.println("Error\n\r\tDelta time to small");
Particle.publish("message: ", "Delta time to small");
break;
case DHTLIB_ERROR_NOTSTARTED:
Serial.println("Error\n\r\tNot started");
Particle.publish("message: ", "Not started");
break;
default:
Serial.println("Unknown error");
Particle.publish("message: ", "WTF");
break;
}
humidity = DHT.getHumidity();
temperature = DHT.getCelsius();
Serial.printlnf("Humidity\t: %.2f %%", humidity);
Serial.printlnf("Temperature\t: %.2f °C", temperature);
Particle.publish("Humidity", String(humidity) + "%");
Particle.publish("Temperature", String(temperature) + " °C");
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
}
}
}
The particle console displays the “Finished getting data from sensor” message but never moves on to displaying the actual data
Any help would be appreciated!
Rhys