You are reading a single comment by @Sestre and its replies. Click here to read the full conversation.
  • Ok, so i tried with the following code (the result is the same with your library now) but, in deed, it's seems that it doesn't work. The output is always "0" even when i put some light on the sensor. The output for manufacterID and deviceID seems ok and i tried to change the modul sensor with an other one without more success so i don't think the problem come from the hardware.

    Code :

    var REG = {
      RESULT: 0x00,
      CONFIG: 0x01,
      LOWLIMIT: 0x02,
      HIGHLIMIT: 0x03,
      MANUFACTURERID: 0x7E,
      DEVICEID: 0x7F
    };
    
    var adr = 0x44;
    
    var i2c = new I2C();
    i2c.setup({sda:B9,scl:B8});
    
    // Config (same as the library - maybe don't work)
    i2c.writeTo(adr, [REG.CONFIG, 0b1100110000010000]);
    
    i2c.writeTo(adr, REG.MANUFACTURERID);
    print(i2c.readFrom(adr, 1));
    
    i2c.writeTo(adr, REG.DEVICEID);
    print(i2c.readFrom(adr, 1));
    
    i2c.writeTo(adr, REG.RESULT);
    print(i2c.readFrom(adr, 2));
    

    Output :

    >new Uint8Array([84])
    >new Uint8Array([48])
    >new Uint8Array(2)
    

    I think the output is "uninitialized-like" because the values are "0" and "0". We can verifie that by reading 3 bytes (in place of two) with the following code

    Code :

    i2c.writeTo(adr, REG.RESULT);
    print(i2c.readFrom(adr, 3));
    

    Output :

    >new Uint8Array([0, 0, 255])
    

    There is maybe a problem with the configuration. I'm sorry, i don't have time now to more investigations but I'll let you know if I find something in the next few days.

    If it helps, here is the result of reading of all the registers

    Code :

    i2c.writeTo(adr, REG.RESULT);
    print(i2c.readFrom(adr, 2));
    
    i2c.writeTo(adr, REG.CONFIG);
    print(i2c.readFrom(adr, 2));
    
    i2c.writeTo(adr, REG.LOWLIMIT);
    print(i2c.readFrom(adr, 2));
    
    i2c.writeTo(adr, REG.HIGHLIMIT);
    print(i2c.readFrom(adr, 2));
    
    i2c.writeTo(adr, REG.MANUFACTURERID);
    print(i2c.readFrom(adr, 2));
    
    i2c.writeTo(adr, REG.DEVICEID);
    print(i2c.readFrom(adr, 2));
    

    Output :

    >new Uint8Array(2) // means "0"
    >new Uint8Array([200, 16])
    >new Uint8Array(2) // means "0"
    >new Uint8Array([191, 255])
    >new Uint8Array([84, 73])
    >new Uint8Array([48, 1])
    

    In addition, if i look in the OPT data sheet, the result value is, in deed, on 16 bits but divided as follow :
    12 bit (LSB) : real value data
    4 bit (MSB) : exposent

    Sadly, your library doesn't take care of that and just return the 16 bits value without treatment. It would be nice to have direct the value ready to be read :)

    datasheet i found : http://www.ti.com/lit/ds/symlink/opt3001­.pdf

About

Avatar for Sestre @Sestre started