root@beaglebone:~# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- 04 -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
class MutichannelGasSensor:
address = None
def __init__(self, mode=1, address=0x04, i2c=None, **kwargs):
i2c = Adafruit_I2C(0x04, busnum=2, debug=True)
self._device = i2c
self.address=0x04
self.adcValueR0_NH3_Buf = 0;
self.adcValueR0_CO_Buf = 0;
self.adcValueR0_NO2_Buf = 0;
#POWER ON
dta_test = [11,1]
self._device.writeList(self.address, dta_test)
self.calcGas()
def calcGas(self):
# how to calc ratio/123
#ledON
dta_test = [10, 1]
self._device.writeList(self.address, dta_test)
time.sleep(1)
A0_0 = self.get_addr_dta(6, 8)
time.sleep(1)
A0_1 = self.get_addr_dta(6, 10)
time.sleep(1)
A0_2 = self.get_addr_dta(6, 12)
print "A0_0: " + str(A0_0)
print "A0_1: " + str(A0_1)
print "A0_2: " + str(A0_2)
def get_addr_dta(self, addr_reg, __dta):
self._device.write8(0x04, addr_reg)
self._device.write8(0x04, __dta)
testArray = self._device.readList(self.address, 2)
dta=0
dta = testArray[0]
dta <<= 8
dta += testArray[1]
if addr_reg == 8: #CH_VALUE_NH3
self.adcValueR0_NH3_Buf = dta;
elif addr_reg == 10: #CH_VALUE_CO
self.adcValueR0_CO_Buf = dta;
elif addr_reg == 12: #CH_VALUE_NO2
self.adcValueR0_NO2_Buf = dta;
return dta
unsigned int MutichannelGasSensor::get_addr_dta(unsigned char addr_reg, unsigned char __dta){
START:
Wire.beginTransmission(i2cAddress);
Wire.write(addr_reg);
Wire.write(__dta);
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(i2cAddress, 2);
unsigned int dta = 0;
unsigned char raw[10];
int cnt = 0;
while(Wire.available())
{
raw[cnt++] = Wire.read();
}
if(cnt == 0)goto START;
dta = raw[0];
dta <<= 8;
dta += raw[1];
return dta;
}