I have a gas sensor connected to my Raspberry Pi 2 (5V, GND, SDA, SCL) I use the Raspbian OS. I try to communicate with the sensor according to this manual:
http://co2meters.com/Documentation/AppNotes/AN142-RaspberryPi-K_series.pdf
i2cdetect delivers the following the right address : 0x68
I used the following test program: ( http://www.byvac.com/downloads/sws/notsmb_1_0.zip )
GNU nano 2.2.6 File: test.py
from notsmb import notSMB
bus = notSMB(I2CBUS)
resp = bus.i2c(0x68,[0x22,0x00,0x08,0x2A],4)
print(resp)
But I get write errors all the time:
pi@raspberrypi ~ $ sudo python test.py
Traceback (most recent call last):
File "test.py", line 5, in <module>
resp = bus.i2c(0x68,[0x22,0x00,0x08,0x2A],4)
EDIT to add:
The complete code I have used:
#!/usr/bin/python
import time
from notsmb import notSMB
I2CBUS = 1
CO2ADDR = 0x68
READ = 0x22
readBytes = [0x00,0x08,0x2A]
bus = notSMB(1)
while True:
try:
pi=bus.i2c(CO2ADDR,[0x22,0x00,0x08,0x2A],4)
time.sleep(0.1)
co2Val=(pi[1]*256+pi[2])
print(co2Val);
f=open("/var/www/bhm/K-30/co2wert.txt","w")
f.write(str(co2Val))
f.close
break
except:
blank=0;
And the error message:
pi@raspberrypi:~ $ sudo python /var/www/bhm/K-30/co2messung.py
Traceback (most recent call last):
File "/var/www/bhm/K-30/co2messung.py", line 12, in <module>
pi=bus.i2c(CO2ADDR,[0x22,0x00,0x08,0x2A],4)
KeyboardInterrupt