Hi everyone.
I'm trying to read my Seed Grove Multichannel gas sensor. 
(http://wiki.seeed.cc/Grove-Multichannel_Gas_Sensor/) 
I now, in the webpage the're a red X on Beaglebone, but I thought It was 
due to lack of python library.

So I started coding from the Arduino cpp library (that 
works): 
https://github.com/Seeed-Studio/Mutichannel_Gas_Sensor/blob/master/MutichannelGasSensor.cpp

If I plug the groove, I see it with i2cdetect -r 2:

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: -- -- -- -- -- -- -- --                         



At the moment I'm using Adafruit_I2C library to write/read.

This is my Class:

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

The problem is when I call calcGas() and get_addr_dta(6, 8) , 
get_addr_dta(6, 10) and get_addr_dta(6, 12):

I wrote in three different registers, but I read always the same value from 
it (A0_0, A0_1 and A0_2) while they're differente on an Arduino.

Why?

The same function in Arduino is:

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;
}


The sensor datasheet is 
useless: 
https://raw.githubusercontent.com/SeeedDocument/Grove-Multichannel_Gas_Sensor/master/res/MiCS-6814_Datasheet.pdf

Thank you for the support :)

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/97e1cd24-8f52-472f-9603-f26f295511f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to