Pixl.js + grove sensors

Posted on
  • Hello!

    We are beginners with javascript and are confused on how to interface the sensors with the Pixl.js.
    It doesn't seem too complicated, but there aren't many examples on how to use them together. We've looked at this, but are confused why certain parts of the code are commented out, or what we would put in the (...) sections.
    http://www.espruino.com/Grove

    Also, specifically for the temp + humidity sensor, we found the DHT11 module and tried using that as well:

    var dht = require("DHT22").connect(D3);
    dht.read(function (a) {console.log(JSON.stringify(a));});
    

    But this doesn't return any raw values.
    temp and humidity = -1

    The sensor should be connected to the right pin and we have also made sure to flash the Pixl.js with the most recent firmware 2v04. What could be the issue with this?

    Also, is there any sample code we could refer to in javascript for the other sensors?
    Thanks!

  • Change the DHT22to DHT11 in your code.

  • Hi!

    Using the Pixl should be almost the same as any other Espruino, pins are different, and different amount of peripherials, but most basic examples in most tutorials should work just fine.

    The DHT11 and DHT22 use different protocol. Are you using the right one?

  • Sat 2019.07.27

    Welcome to the world of Javascript @user98241 as I know you will enjoy many hours of discovery with your purchase of Pixl.

    'We are beginners with javascript'

    Excellent resource with a tryit window option:

    https://www.w3schools.com/js/js_operators.asp

    The language itself:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var

     

    'are confused why certain parts of the code are commented out'

    On the 'Grove' page, the code within the commented out sections just indicate an alternate way in which commands could be used. It's there to aid as a hint, and to avoid having to look up each command, which may be done at:

    http://www.espruino.com/Reference#Pin

    It also appears that the commented out sections may be a suggestion on how to set up the declarations section, and the viewable code lines show usage, for the specific section beneath the heading in blue.

     

    ' what we would put in the (...) sections'

    Is there a specific example? It would depend on which command, which sensor etc. A combination of command lookup in the above link, and searching the manufacturer data sheet would be a good idea.

     

    'there aren't many examples on how to use them together'

    On the device specific page, beneath the Tutorials heading there are at least fifty:

    http://www.espruino.com/Pixl.js

     

    'any sample code we could refer to in javascript for the other sensors'

    Has the tutorials and samples page been discovered yet? Tons there also:

    https://www.espruino.com/Tutorials

     
    A good overview of a complete code example with the Pixl:

    https://www.espruino.com/Freezer+Alarm

  • On http://www.espruino.com/Grove you've got some code up the top (under 'Software') that you can use pretty much as-is. For instance for Pixl.js you just do:

    var grove = require("arduino-grove").connect(); // for Pixl.js
    new (require("GroveButton"))(grove.D2, function(e) {
      if (e.state) console.log("Pressed");
      else console.log("Released");
    });
    

    However from Button onwards on the page, the code is explaining what functionality is available for you to use in the Grove libraries :

    • The commented out code on http://www.espruino.com/Grove actually contains examples of how to use the libraries.
    • The uncommented code (eg GroveRelay.prototype.on = function () { ... }) actually just describes the functions that are available for you to use.

    As it happens I don't believe there is a library for the DHT11 on Grove, but Grove itself is nothing special - it's just a connector, so what you were doing with:

    var dht = require("DHT22").connect(D3);
    dht.read(function (a) {console.log(JSON.stringify(a));});
    

    Sounds spot on - just as others have said you'll need to use the DHT11 module if you have a DHT11 - and ensure that you're using the right pin for it (as Grove connectors have two pins - a connector labelled D3 will probably use pins D3 and D4).

    Do you have a link to the exact arduino grove shield you're using? It might be that you're having issues because the shield is expecting power on the '5v' rail: http://www.espruino.com/Pixl.js#shield-power

  • Hi all,

    Thanks for all your help! Will definitely look through those links, and I've gotten a much better understanding of how everything works.
    Double checked, and I was using the correct DHT11 module after all, but even so, shouldn't it still be returning some kind of raw value? When doing analogRead(D3), a value is returned, although not sure if it's correct because doing analogRead() on any pin (even empty ones) seem to return a value around 0.9.

    This is the arduino shield and temperature + humidity sensor being used:
    http://wiki.seeedstudio.com/Grove_Smart_Plant_Care_Kit/

  • Is the PWR led on on that shield? For it to work you'd need the switch set to 3.3v OR for Vin and 5v to be shorted together (either with the Pixl's solder jumper, or just with a wire on the Arduino headers).

    And how are you powering the Pixl.js? via a 3v battery, or USB?

    http://www.espruino.com/DHT11 says:

    If no data received at all: {"temp": -1, "rh": -1, err : true, "checksumError": false}

    So that could be what you're getting? The DHT11 is a digital device, so Espruino can detect if it's working/connected correctly or not. If something goes wrong it'll report back -1 for the values.

  • Wed 2019.07.31

    'doing analogRead() on any pin (even empty ones)'

    Doesn't hurt to verify what mode the pins being checked actually are:

    http://www.espruino.com/Reference#t_l__global_getPinMode



    In addition to the comments in #7 concerning powering, how is the DHT11 grounded to the Pixl? A floating ground might be an issue with the randomness that is observed.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Pixl.js + grove sensors

Posted by Avatar for user98241 @user98241

Actions