Problem in I2C communication with an opensource soilmoisture sensor.

Hi there, I am trying to read moisture data from this sensor. The sensor uses Attiny44A as the uC. The sensor comes with everything preinstalled. But I was not able to establish I2C communication. I have also tried the I2C scanner but didnt find any I2C device attached. I finally recompiled the main.c file from the src folder and uploaded using arduino as ISP to the sensor. Yet I am facing the same problem. Everything uploads fine.The author Mr Miceuz has also written a blog on the operation of sensor over here. He has mentioned that for proper working the sensor must buzz twice which my sensor does. So I am sure it is working fine. As I am a mechanical engineering I am having a very limited background on embedded electronics. So I have no clue on where to start the debugging.Any guidance will be deeply appreciated. Thanks.

This is the output after burning the bootloader to the chip.

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Nilesh\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.3/avrdude.conf"

         Using Port                    : COM10
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         Setting bit clk period        : 5.0
         AVR Part                      : ATtiny44
         Chip Erase delay              : 15000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        256    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      4096   64     64  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9207 (probably t44)
avrdude: erasing chip
avrdude: reading input file "0xFF"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFF:
avrdude: load data efuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0b11010111"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0b11010111:
avrdude: load data hfuse data from input file 0b11010111:
avrdude: input file 0b11010111 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xE2"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xE2:
avrdude: load data lfuse data from input file 0xE2:
avrdude: input file 0xE2 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "C:\Users\Nilesh\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.3/bootloaders/empty/empty_all.hex"
avrdude: writing flash (2 bytes):

Writing | ################################################## | 100% 0.09s

avrdude: 2 bytes of flash written
avrdude: verifying flash memory against C:\Users\Nilesh\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.3/bootloaders/empty/empty_all.hex:
avrdude: load data flash data from input file C:\Users\Nilesh\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.3/bootloaders/empty/empty_all.hex:
avrdude: input file C:\Users\Nilesh\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.3/bootloaders/empty/empty_all.hex contains 2 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.04s

avrdude: verifying ...
avrdude: 2 bytes of flash verified

avrdude done.  Thank you.

To read the data I used this code:

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void writeI2CRegister8bit(int addr, int value) {
  Wire.beginTransmission(addr);
  Wire.write(value);
  Wire.endTransmission();
}

unsigned int readI2CRegister16bit(int addr, int reg) {
  Wire.beginTransmission(addr);
  Wire.write(reg);
  Wire.endTransmission();
  delay(1100);
  Wire.requestFrom(addr, 2);
  unsigned int t = Wire.read() << 8;
  t = t | Wire.read();
  return t;
}

void loop() {
  Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register
  writeI2CRegister8bit(0x20, 3); //request light measurement 
  delay(9000);                   //this can take a while
  Serial.print(", ");
  Serial.println(readI2CRegister16bit(0x20, 4)); //read light register
  delay(500);
}

You may have a wiring error. Please post a wiring diagram and clear photos of the wiring.

Wire.enTransmission() returns a status code. Why are you ignoring it? It you were were to capture it in a variable and print it out, I'm betting you are getting an error.

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void writeI2CRegister8bit(int addr, int value) {
  int status;
  Wire.beginTransmission(addr);
  Wire.write(value);
  status = Wire.endTransmission();
  if (status) {
    Serial.print("i2c error writing ");
    Serial.println(status);
  }
}

unsigned int readI2CRegister16bit(int addr, int reg) {
  Wire.beginTransmission(addr);
  Wire.write(reg);
  Wire.endTransmission();
  delay(1100);
  Wire.requestFrom(addr, 2);
  unsigned int t = Wire.read() << 8;
  t = t | Wire.read();
  return t;
}

void loop() {
  Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register
  writeI2CRegister8bit(0x20, 3); //request light measurement
  delay(9000);                   //this can take a while
  Serial.print(", ");
  Serial.println(readI2CRegister16bit(0x20, 4)); //read light register
  delay(500);
}

Yeah, I had made a very dumb mistake in wiring. But now that I have got it working, the sensor values remain constant at 1023. What could be the problem?

Are you checking the return codes? 1023 on an A/D pin is the same as +5V which is always high which is what an I2C device will do if it is not responding correctly.

blh64:
Are you checking the return codes? 1023 on an A/D pin is the same as +5V which is always high which is what an I2C device will do if it is not responding correctly.

Yes the return code is 0 (int status).