johnny-five icon indicating copy to clipboard operation
johnny-five copied to clipboard

Adding DHT11 or DHT22 sensor support

Open piotrfalba opened this issue 13 years ago • 53 comments

It would be great to have DHT11 humidity, temperature sensor support.

piotrfalba avatar Apr 13 '13 18:04 piotrfalba

I agree!

I just ordered one of each, when they arrive I will work on support :)

rwaldron avatar Apr 14 '13 18:04 rwaldron

Adding as a reference

http://learn.adafruit.com/dht

rwaldron avatar Apr 14 '13 18:04 rwaldron

DHT11 datasheet in english http://www.svet-el.si/download/Datasheet_DHT11.pdf

piotrfalba avatar Apr 14 '13 20:04 piotrfalba

Thanks!

rwaldron avatar Apr 14 '13 20:04 rwaldron

The code required to make this work requires too many process blocking delays https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp#L78-L139

rwaldron avatar Jul 03 '13 19:07 rwaldron

Looks like support for this has landed https://github.com/firmata/arduino/pull/44#issuecomment-22074620 so we can probably revisit this now :)

rwaldron avatar Aug 07 '13 15:08 rwaldron

Did something happen about this? I would need this too, but have no idea if/how i can use ConfigurableFirmata with Johnny-Five and Stepper-support

ottes avatar Apr 01 '14 04:04 ottes

@xFragger I haven't looked at this in a very long time, I will try to make some time this week :)

rwaldron avatar Apr 01 '14 14:04 rwaldron

yeah would be nice... i'm wondering.... johnnyfive checks for Firmata name (==AdvancedFirmata), but this would differ, when i use ConfigurableFirmate, right? Do i have to set the name myself so Advanced to use the steppersupport of five?

ottes avatar Apr 01 '14 19:04 ottes

Sorry, but I'm not sure I understand what you're asking. If you need ConfigurableFirmata, then test for that name and throw if it's not present—that part is easy. The hard part is knowing whether or not ConfigurableFirmata was compiled with the right support. Things like this are usually too much work for the average user. I'm not really sure how to approach this, so I'm open to whatever ideas you may have.

rwaldron avatar Apr 01 '14 21:04 rwaldron

Okay.... again :) Johnny-five checks in its code for the stepper for the io.firmata.name (to be Advanced), but if i install ConfigurableFirmata on my Arduino, then this check would fail, and propably the stepper won't work, i guess.... so: is it possible to use the ConfigurableFirmata with DHT11 AND stepper support, without "hacking" the johnny-five/stepper.js ?

ottes avatar Apr 02 '14 05:04 ottes

As a temporary work around, you could if you rename ConfigurableFirmata to AdvancedFirmata. The name of the Firmata doesn't matter. Take ConfigurableFirmata.ino, add the DHT11 code (from the example) by adding the includes... make sure the DHT11 files are in the same directory as your sketch and name that AdvancedFirmata.ino. Also remove (don't include) features you may not be using such as OneWire or you risk running out of RAM if you're using an Arduino Uno, Leonardo or other board with limited SRAM.

@rwaldron The stepper code in johnny-five should be updated to not specifically look for a specific firmata name (https://github.com/rwaldron/johnny-five/blob/master/lib/stepper.js#L117). It should instead look for the Stepper pin mode to be set when performing a capability query. Pin modes are used in configurable Firmata as indicators of which features are supported in the particular build.

soundanalogous avatar Apr 02 '14 16:04 soundanalogous

So the stepper support in advancedfirmata does work the same way as in configurable? Then i will give it a try...

I think i've got enough memory on the nano v3

ottes avatar Apr 02 '14 16:04 ottes

okay, managed to compile the ConfigurableFirmata with Stepper + DHT11 from examples..... but my stepper won't move anymore, with same js code, as for AdvancedFirmata....

How do i call the dht11 device (ext) ?

var stepper = new five.Stepper({
        type: five.Stepper.TYPE.FOUR_WIRE,
        stepsPerRev: 64,
        pins: {
            motor1: 9,
            motor2: 11,
            motor3: 10,
            motor4: 12
        }
    });
    stepper.step({ steps: 500, direction: 0, accel: 3500, decel: 3500 }, function() { /*....*/ });
#include <Firmata.h>

#include <utility/DigitalInputFirmata.h>
DigitalInputFirmata digitalInput;

#include <utility/DigitalOutputFirmata.h>
DigitalOutputFirmata digitalOutput;

#include <utility/AnalogInputFirmata.h>
AnalogInputFirmata analogInput;

#include <utility/AnalogOutputFirmata.h>
AnalogOutputFirmata analogOutput;

#include <utility/StepperFirmata.h>
StepperFirmata stepper;

#include <utility/FirmataExt.h>
FirmataExt firmataExt;

#include <utility/FirmataScheduler.h>
FirmataScheduler scheduler;

#include <utility/AnalogWrite.h>

#include <utility/FirmataReporting.h>
FirmataReporting reporting;

#include "dht11.h"
#include "DHT11Feature.h"
DHT11Feature dht11;


/*==============================================================================
 * FUNCTIONS
 *============================================================================*/

void systemResetCallback()
{
  // initialize a defalt state

  // pins with analog capability default to analog input
  // otherwise, pins default to digital output
  for (byte i=0; i < TOTAL_PINS; i++) {
    if (IS_PIN_ANALOG(i)) {
      Firmata.setPinMode(i, ANALOG);
    } else if (IS_PIN_DIGITAL(i)) {
      Firmata.setPinMode(i, OUTPUT);
    }
  }

  firmataExt.reset();
}

/*==============================================================================
 * SETUP()
 *============================================================================*/

void setup() 
{
  Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
  firmataExt.addFeature(digitalInput);
  firmataExt.addFeature(digitalOutput);
  firmataExt.addFeature(analogInput);
  firmataExt.addFeature(analogOutput);
  firmataExt.addFeature(stepper);
  firmataExt.addFeature(reporting);
  firmataExt.addFeature(scheduler);

  /* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
  Firmata.attach(SYSTEM_RESET, systemResetCallback);

  // start up the default Firmata using Serial interface:
  Firmata.begin(57600);

  systemResetCallback();  // reset to default config
}

/*==============================================================================
 * LOOP()
 *============================================================================*/
void loop() 
{
  digitalInput.report();
  while(Firmata.available()) {
    Firmata.processInput();
    if (!Firmata.isParsingMessage()) {
      goto runtasks;
    }
  }
  if (!Firmata.isParsingMessage()) {
runtasks: scheduler.runTasks();
  }

  if (reporting.elapsed()) {
    analogInput.report();
    dht11.report();
  }
  stepper.update();

}

ottes avatar Apr 02 '14 19:04 ottes

The stepper code in johnny-five should be updated to not specifically look for a specific firmata name (https://github.com/rwaldron/johnny-five/blob/master/lib/stepper.js#L117). It should instead look for the Stepper pin mode to be set when performing a capability query. Pin modes are used in configurable Firmata as indicators of which features are supported in the particular build.

@soundanalogous heh, I actually didn't write that module, but this makes sense. I'll file a bug and maybe the original author can patch it or someone else here?

rwaldron avatar Apr 02 '14 22:04 rwaldron

@xFragger you need to add this line to setup: firmataExt.addFeature(dht11);

soundanalogous avatar Apr 06 '14 18:04 soundanalogous

any update on this?

felixsanz avatar Aug 04 '14 08:08 felixsanz

my real life eats all the time... could not work on this these days, next for the next weeks..... so i'm out for the moment, sorry

ottes avatar Aug 04 '14 10:08 ottes

real life first np! thx

felixsanz avatar Aug 04 '14 17:08 felixsanz

Hi, I'm trying to add DHT11 measurements to my project. I am using ConfigurableFirmata with the DHT11Feature.

Copied DHT11Feature.h, DHT11Feature.cpp, dht11.cpp and dht11.h to libraries/Firmata/utility.

Then added these lines to my ConfigurableFirmata.ino

#include <utility/DHT11Feature.h>
DHT11Feature dht11;

in setup()

#ifdef DHT11Feature_h
  firmataExt.addFeature(dht11);
#endif

in loop()

#ifdef DHT11Feature_h
    // report dht11 values
    dht11.report();
#endif

Full gist here EDIT: The sketch doesn't even work with firmata clients (yet to figure out why)

I have seen that using a custom sysex and setting the pin mode to 0x7e I could poll for DHT measurements, but haven't found a way to do it with Johnny-Five.

Any ideas?

davoclavo avatar Sep 15 '14 19:09 davoclavo