rwaldron / johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
http://johnny-five.io
Other
13.3k stars 1.77k forks source link

DHT11 connected to GrovePi+ #1213

Closed rickysullivan closed 6 years ago

rickysullivan commented 8 years ago

I can't seem to get my app running:

var raspi = require('raspi-io');
var five = require('johnny-five');

var board = new five.Board({
    io: new raspi()
});

board.on("ready", function() {

  var temperature = new five.Thermometer({
    controller: "GROVEPI",
    pin: "A0"
  });

  temperature.on("data", function() {
    console.log("celsius: %d", this.C);
    console.log("fahrenheit: %d", this.F);
    console.log("kelvin: %d", this.K);
  });

});

Err: 

events.js:141 throw er; // Unhandled 'error' event ^

Error: EIO: i/o error, read at Error (native)

I've had success with the LCD, but none of the other sensors.

rwaldron commented 8 years ago

Thanks for filing! The DHT11 sensor requires an intermediary μC that we've dubbed a "backpack", inspired by Adafruit's products of a similar nature. Take a look at this example: http://johnny-five.io/examples/multi-DHT11_I2C_NANO_BACKPACK/

rickysullivan commented 8 years ago

Still getting error:

1471872406594 Device(s) RaspberryPi-IO  
1471872407444 Connected RaspberryPi-IO  
1471872407697 Repl Initialized  
>> ready
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: EIO: i/o error, read
    at Error (native)

I've plugged the DHT11 into I2C-1.

rwaldron commented 8 years ago

I'm not sure I understand what you mean by this:

I've plugged the DHT11 into I2C-1.

The DHT11 itself isn't an I2C device—you'd need to connect it to another microcontroller that itself has the provided firmware running on it:

Then, your code should be:

var temp = new five.Thermometer({
  controller: "DHT11_I2C_NANO_BACKPACK"
});

temp.on("change", function() {
  console.log("temperature");
  console.log("  celsius           : ", this.celsius);
  console.log("  fahrenheit        : ", this.fahrenheit);
  console.log("  kelvin            : ", this.kelvin);
  console.log("--------------------------------------");
});

The controller wouldn't be a GROVEPI, since the Grove Pi itself is just another I2C device on the bus. The controller is our own DHT11_I2C_NANO_BACKPACK, which knows how to speak to the provided firmware, which you upload to whatever intermediary microcontroller you choose to use (in the diagram, I've used a nano, which I highly recommend)

rwaldron commented 8 years ago

Have you had a chance to try the example shown above?

dtex commented 6 years ago

Hi @rickysullivan

I'm going to close this since we haven't heard back. Feel free to re-open if necessary.