Can't read sensor using I2C

Hi!

I just want to get data from a RGB sensor (MAX44005). Here is a link to its datasheet.
I tried to use the Wire library but it needs a Repeated Start condition which is not supported in the library. That or I just don’t know how to do it. So I found and used the SoftI2CMaster library.

Here is my test code:

#define SDA_PORT PORTD
#define SDA_PIN 4
#define SCL_PORT PORTD
#define SCL_PIN 5
#include <SoftI2CMaster.h>
#define I2C_FASTMODE 1 

byte sense[]={0,0,0};
byte a=68;
byte o=6;
  

void setup() {
  Serial.begin(9600);
  Serial.print("Sensing...");
  i2c_init;
}

void loop() {
  for (int i=0; i<3;i++){
    i2c_start(a|0);
    i2c_write(o);
    i2c_rep_start(a|1);
    sense[i]=i2c_read(true);
    i2c_stop();
    o+=2;
  }
  
  Serial.print(sense[0]);
  Serial.print("\t");
  Serial.print(sense[1]);
  Serial.print("\t");
  Serial.println(sense[2]);
  
  o=6;
  
  delay (10);
}

It suppose to show me the bytes from specific registers. It just say “Sensing…” and then nothing.

I tried to see if connections and circuitry is at fault but when I used a I2C Scanner using the Wire library it can find it. But when I used the I2C Scanner example from the SoftI2CMaster it says:

“Initialization error. SDA or SCL are low”

I don’t get any errors when I compile so I don’t know what is wrong. I really don’t know how to use the SoftI2CMaster Library. I am really kinda new to this. :stuck_out_tongue:

Any help would really be appreciated! Thanks!

I think this is supposed to be a function call.

  i2c_init;
// like this
  i2c_init();

The I2C bus requires pullup resistors on both the SDA and SCL lines. The hardware I2C bus has them in the processor, but this software version probably does not. You might be able to set the pinMode to activate the internal pullups.

Thanks for the reply!

But it still doesn't work. I tried using the internal pullups and also tried using external pullups.
Maybe I am using the library wrong? o.O