Cannot read I2C data from Sensair K30 CO2 sensor

local tem= K30CO2.write(Addr<<1,"\x22\x00\x08\x2A");

is giving me a result of -1 which corresponds to “Timeout waiting for bus to be released after sending start”.

After this when I try (which I know would not work)

local temp =<<1, “”, 4);

is giving me null result and

local err= K30CO2.readerror();

is giving me -12 which corresponds to same as first error. (Timeout waiting for bus to be released after sending start).

How do I resolve this issue and read data from the sensor?

Many thanks for help.

pull-ups connected?
default address right?
clock speed?
breakout board?
proper connection pins?

we need a little bit more informations to help you…

The sensair datasheet notes that pull-ups are required. Try 4k7 to 3.3v on both SCL and SDA.

Thanks Chrischi and Hugo for your prompt response. I really appreciate it.

When I first power on the sensor, I can get few readings (sometimes upto 10-15 of them) which appear to be correct. Then I start getting the timeout on write and of course no read. I tried waking up 10s and 2 mins, but nothing changes.

I have 10K pull up resistor (could not find 4.7k right now) on both SCL and SDA. With these few readings, I’m pretty sure the connections and addresses are correct. Clock speed is 100K. I’ using April breakout board and 8 V power supply to the sensor and VIN pin of the board.

this sensor has a well documented communication guide.
It should answer nearly every question. Take a look…

uhh and if your breakout is the april from sparkfun, try using

Pins 8 (SCL) + 9 (SDA)
instead of

Pins 1 (SCL) + 2 (SDA)

I’m using

i2c12 also has same issue. I have no problem using the sensor with Arduino. I have put 4.7k pullup on both SDA and SCL. I have checked their docs. The write and read commands are all it needs to get the data.

I’m getting data for sometime, around 10-15 readings after I power cycle the sensor and then sensor stops taking commands.

I have no idea if I need more tweaks on read and write on the bus. Or perhaps bit bang?

Many thanks.

Got a scope or logic analyzer that you can use to see what’s happening?

If initial requests are working fine, then that rather points to the sensor changing mode in some way (eg going into power save?)