Is there any way to support the hdс1080 sensor?

Posted on
  • Shouldn't be too hard, just I guess no one has that particular sensor.
    Send me one :)

  • Thr 2019.06.20

    Please add link to product datasheet

  • Looks like a straightforward I2C device, creating a module for it shouldn't be particularly hard.

  • Thr 2019.06.20

    Are you able to interface at this time? (no?) e.g. As the link is to the supplier page, has the purchase been made, or are we still speculating at this point?

    If yes, what are the results of just trying the snippet for the common temp/humid sensor:

    If no, use the source and modify as needed, as @AkosLukacs points out. It appears that @DrAzzy and I agree, after I viewed that source.­

  • DHT11 is not the best starting point, because the HDC1080 has I2C interface, but the DHT11 has a one-wire interface.
    One sensor listed on the I2C page would be a better starting point.

  • Fri 2019.06.21

    Ahhh, . . . hadn't realized the interface difference. Thanks for that tidbit, @AkosLukacs

    Maybe the BMP280 Environment sensor code snippet would better assist here:

  • var i2c = new I2C();
    i2c.setup({ scl : D5, sda: D4 });
    var b = new ArrayBuffer(4);
    var v = new DataView(b);
    setInterval( function() {
       var d = i2c.readFrom(0x40, 4);
        var temp =(v.getUint16(1)/65536)*165-40;
        var hum =(v.getUint16(3)/65536)*100;
      i2c.writeTo(0x40, 0);
    }, 1000 );
  • Thr 2019.08.22

    Nice compact little snippet @Alexandr

    Would you mind posting some output so that we may better visualize the solution while sampling please.

  • I wasn't able to get @Alexandr 's code give the correct values so I tried doing it differently.

    I tested the sensor with an Arduino and a library for the HDC1080 and then transferred the whole shield over to the Pixl.js for testing.

    var exports={};
    var C = {
      I2C_ADDRESS : 0x40,
    function HDC1080(i2c, deviceAddress) {
      this.i2c = i2c;
      this.deviceAddress = deviceAddress;
    } = function() {
      this.i2c.writeTo(this.deviceAddress, 0);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          const data = this.i2c.readFrom(this.deviceAddress, 4);
          const temp = data[1] | data[0] << 8;
          const hum = data[3] | data[2] << 8;
            temp: (temp / 65536) * 165.0 - 40.0,
            humidity: (hum / 65536) * 100.0,
        }, 25);
    exports.connect = function (i2c, deviceAddress) {
      return new HDC1080(i2c, deviceAddress || C.I2C_ADDRESS);
    I2C1.setup({sda:SDA, scl:SCL});
    var hdc = exports.connect(I2C1);
    setInterval(() => { => {print(e);});
    }, 1000);

    It's a bit raw for now but that's how it looks like right now, ready to be done as a module.

    I do have a question for @Gordon , I had to use promises because I needed to wait a few ms for the sensor to be ready after setting the pointer for the read (otherwise I get an I2C exception). There isn't any ready pin for this sensor.

    Would promises be the way to go, or is there some other way to "delay" the I2C read but still maintain a somewhat sychronous flow?

    Edit: obligatory screenshot'

    1 Attachment

    • Annotation 2020-10-04 000704.png
  • @parasquid What about a callback implementation?

  • Callbacks are an option, but I tend to like promises more :P But still, that makes the actual call "nested" in a sense.

    I'm looking for a possible way to just do

    var data =;

    and it "just works." This would be possible with async/await but from what I can see it's not yet available in Espruino (yet).

    If Espruino had a delay I can do away with the setTimeout and just delay for a few ms at that point and everything should work (this is actually how the Arduino libraries do it) but delay doesn't sound like the Espruino way of doing things.

  • Well there is no wait, but you can use digitalPulse instead.

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

Is there any way to support the hdс1080 sensor?

Posted by Avatar for Alexandr @Alexandr