require("CCS811").connectI2C(i2c);

Posted on
  • Good day everyone! The problem with the sensor CCS811. Why is it not read CO2 readings and other data. What could be the matter?

    var i2c = new I2C();
    i2c.setup({ scl : D5, sda: D4 });
    var gas = require("CCS811").connectI2C(i2c);
    // wait for the sensor to be ready
    setInterval(function() {
     print(gas.get);
    }, 3000);
    
    

    that's all I see

    function () {var e=0!=(this.r(a.STATUS,1)[0]&a.STATUS_DAT­A_READY),c=this.r(a.ALG_RESULT_DATA,4);r­eturn{eCO2:c[0]<<8|c[1],TVOC:c[2]<<8|c[3­],"new":e}}
    

    https://github.com/hzxi0/foto/blob/maste­r/20190620_132418.jpg

  • Can you try using the code from the examples on http://www.espruino.com/CCS811 ?

    print(gas.get); is very different from gas.get(print); - which is what's in the examples.

  • If you write that there is absolutely nothing in the console. gas.get(print);

  • Nothing in return.

    var i2c = new I2C();
    i2c.setup({ scl : D5, sda: D4 });
    var gas = require("CCS811").connectI2C(i2c);
    setInterval(function() {
      gas.get(print);
       //print(gas.get);
      //gas.on('data', print);
    }, 3000);
    
    var wifi = require("Wifi");
    
    function onInit() {
       wifi.stopAP();
       wifi.connect("INGRIFABSR", {password: "B73vFeX6se2"}, function(err) {
            if(err)console.log(err);else {
               print(wifi.getIP().ip);//33
            }
         });
    }
    
    
  • Just gas.get() should print out the result on the console.

    @Gordon just checked, gas.get(print) does work. But (was puzzled about the "why does it work at all?") that snippet is "wrong". It's working as intended, but the print is not needed / used by the code. The REPL just prints out the result. Or is there some magic in the background?

  • Oh, there is a difference. If you type gas.get() in the REPL, it prints out the result of the last statement. But if you call it somewhere in your code, it does not.
    So it should be print(gas.get()); in the interval:

    var i2c = new I2C();
    i2c.setup({ scl : D5, sda: D4 });
    var gas = require("CCS811").connectI2C(i2c);
    setInterval(function() {
      //gas.get(print);
      print(gas.get());
      //gas.on('data', print);
    }, 3000);
    
  • Thanks @AkosLukacs - I'll update the example code on that page - not sure how but it doesn't seem to match the module at all.

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

require("CCS811").connectI2C(i2c);

Posted by Avatar for user79559 @user79559

Actions