• Hi guys.
    This following post refers to the "Chirp" soil moisture sensor (tindie.com/products/miceuz/i­2c-soil-moisture-sensor/).

    I just successfully integrate this sensor into Espruino. As far as I know, nobody did it yet (or did not publish a basic example code), so I decided to post it here.

    You will notice that this piece of hardware integrate a capacitive sensor, as well as a luminosity & temperature sensor.
    The temperature result is in [°c/10] : if result is 226, temperature is 22.6°c.
    The capacitive & luminosity sensor are both relative.

    If you try it, do not forget to add two ~10k Pull-ups on both SDA and SCL.

    // Soil Moisture Sensor Example | JRY | 26.06.2015
    var Temp;
    var Lumi;
    var Capa;
    I2C1.setup({scl:B6,sda:B7});
    
    function getLuminosity(){//takes ~2 sec. to acquire
      I2C1.writeTo(0x20,0x03);
      setTimeout(function(){
        I2C1.writeTo(0x20,0x04);
        Lumi=I2C1.readFrom(0x20,2);
        print("Lumi:"+(Lumi[0]*256+Lumi[1]));
      },2000);
    }
    
    function getCapacitance(){
      var Res;
      I2C1.writeTo(0x20,0x00);
      Res=I2C1.readFrom(0x20,2);
      Capa=Res[0]*256+Res[1];
      print("Capa: "+Capa);
    }
    
    function getTemperature(){
      var Res;
      I2C1.writeTo(0x20,0x05);
      Res=I2C1.readFrom(0x20,2);
      Temp=Res[0]*256+Res[1];
      print("Temp: "+Temp);
    }
    I2C1.writeTo(0x20,0x06);//reset the sensor
    //setInterval(getTemperature,10000);
    //setInterval(getLuminosity,4600);
    setInterval(getCapacitance,1000);
    

    If anyone has a better code or a dedicated .js class, do not hesitate to publish it! :-)


    1 Attachment

    • 2015-06-27 00.07.35.jpg
  • What chip is that on it? Tiny 84?

  • I don't know the Tiny family, but it is written "ATTINY 441" on the chip

  • Oooh, someone's fancy!

    The tiny x41 series is the second gen of the tiny x4 (where x is 2/4/8, the size of the flash in kb); nice chip - 3 hardware timers and 2 uarts, fancier than I'd have guessed. I got the x41 series working with arduino a few months back, and use them a lot in projects.

  • That's great, thanks! I'll have to have a play with one of those :)

    Looks like it's just that board that implements the protocol, but I guess we could still do a module to make it easy to interface to?

  • @Jean-Philippe_Rey Hello how is it gooing with the chirp? Anyhing new? Can you provide a closeup on the chirp and the pico so i can do the same?

  • Can i use this chirp with puckjs? I was wondering if I could send MQTT signals to node-red?

  • @furuskog if you have access to I2C on the puck, you probably will succeed in integrating this chirp sensor.
    I2C1.setup({scl:B6,sda:B7}); You just have to change the name of SCL and SDA lines and it should just work.

  • If I use a pico/wifi could I in theory have several Chirps connected? And even have a I2C screen connected att the same time? The idea is to have several flower pots connected near each other.

  • I2C is an addressed bus. This means you can have multiple slaves communicating with (usaually) a single master. Often, different kind of I2C devices have different addresses. Your I2C lcd is not likely to have the same address as your Chirp.
    The difficulty comes with multiples devices of same kind, such as two or more Chirps. In some way you have to differentiate them on the I2C bus. Fortunately, Chirp seems to provide a way of doing it: github.com/Miceuz/i2c-moisture-s­ensor/blob/master/README.md#address-chan­ge-example

    I never tried. Please share your thoughts on this method if you try it! :-)

  • Thank you @Jean-Philippe_Rey maybe I will! ;-)

  • Worth nothing that Espruino also has software I2C support now, so you can have lots and lots of different I2C ports, one for each sensor.

  • Nice that is grate news

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

Example code for the "Chirp" soil moisture sensor

Posted by Avatar for Jean-Philippe_Rey @Jean-Philippe_Rey

Actions