GrovePi+ Multichannel Gas Sensor

Hi everyone!

I am using a Raspberry Pi 3 B model with a Grove Pi+ (1.2.2 firmware), and Raspbian for Robots Image.
I am plug-in the Multichannel Gas Sensor in I2C-1 port, and I am trying to execute the code that is available in Dexter´s Github (https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_i2c_multichannel_gas_sensor/multichannel_gas_sensor.py). I am getting the following issues:

Traceback (most recent call last): File “/home/pi/Desktop/GrovePi/Software/Python/grove_i2c_multichannel_gas_sensor/multichannel_gas_sensor.py”, line 85, in m= MutichannelGasSensor() File “/home/pi/Desktop/GrovePi/Software/Python/grove_i2c_multichannel_gas_sensor/multichannel_gas_sensor.py”, line 39, in init if self.readR0() >= 0: File “/home/pi/Desktop/GrovePi/Software/Python/grove_i2c_multichannel_gas_sensor/multichannel_gas_sensor.py”, line 45, in readR0 rtnData = self.readData(0x11) File “/home/pi/Desktop/GrovePi/Software/Python/grove_i2c_multichannel_gas_sensor/multichannel_gas_sensor.py”, line 70, in readData buffer=bus.read_i2c_block_data(self.address, cmd, 4)IOError: [Errno 110] Connection timed out

When I was running the old firmware of GrovePi+, this error was not appearing, but it was not working, nothing appears on screen.

Checking the code line by line, I realize that in line 71 is print(data), after the buffer=bus.read_i2c_block_data(self.address, cmd, 4), but “data” variable is not defined in the code. Something is strange in this code.

Can someone help me with this grove pi sensor?Can someone give me any hint?

thanks in advance

Hello!
I can not understand what I need to do to make the Multichannel Gas Sensor work in Rpi with GrovePi+. Can someone explain it to me steep by steep?

When I run this code (https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_i2c_multichannel_gas_sensor/multichannel_gas_sensor.py), nothing appears in console:

#!/usr/bin/env python
#NOTE:
# This sensor is on port 0x04, so not compatible with grovepi unless you load an alternate firmware
# This is work in progress, would need logic analyzer and arduino to get working
# Error:
#   Traceback (most recent call last):
#  File "multichannel_gas_sensor.py", line 67, in <module>
#    m= MutichannelGasSensor()
#  File "multichannel_gas_sensor.py", line 21, in __init__
#    if self.readR0() >= 0:
#  File "multichannel_gas_sensor.py", line 27, in readR0
#    rtnData = self.readData(0x11)
#  File "multichannel_gas_sensor.py", line 52, in readData
#    buffer=bus.read_i2c_block_data(self.address, cmd, 4)
#IOError: [Errno 5] Input/output error
#
# LINKS
# http://www.seeedstudio.com/wiki/Grove_-_Multichannel_Gas_Sensor
# https://github.com/Seeed-Studio/Mutichannel_Gas_Sensor
import time,sys
import RPi.GPIO as GPIO
import smbus

# use the bus that matches your raspi version
rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
    bus = smbus.SMBus(1)
else:
    bus = smbus.SMBus(0)

class MutichannelGasSensor:
    address = None
    is_connected = 0
    res=[0]*3

    def __init__(self,address=0x04):
        self.address=address
        is_connected = 0
        if self.readR0() >= 0:
            self.is_connected = 1
    
    def readR0(self):
        rtnData = 0
        
        rtnData = self.readData(0x11)
        if(rtnData >= 0):
            self.res0[0] = rtnData
        else:
            return rtnData
            
        rtnData = self.readData(0x12)
        if(rtnData >= 0):
            self.res0[0] = rtnData
        else:
            return rtnData
            
        rtnData = self.readData(0x13)
        if(rtnData >= 0):
            self.res0[0] = rtnData
        else:
            return rtnData
        return 0    
        
    def readData(self,cmd):
        timeout = 0
        buffer=[0]*4
        checksum = 0
        rtnData = 0
        
        buffer=bus.read_i2c_block_data(self.address, cmd, 4)
        print(data)
        
        checksum = buffer[0] + buffer[1] + buffer[2]
        if checksum != buffer[3]:
            return -4
        rtnData = ((buffer[1] << 8) + buffer[2])
        
        return rtnData
   
    def sendI2C(self,cmd):
        bus.write_byte(self.address, cmd)


if __name__ == "__main__":        
m= MutichannelGasSensor()

In line 71 the code has “print(data)” but “data” does not exist. If I comment this variable nothing appears in terminal, any erro.

Can anyone help em to get data from this sensor?

Thanks in advance,

Hi @aitor,

This example doesn’t work for now because the sensor does not return good values. We were unable to get it working properly the last time we tried working on it and it might take some time before it works with the GrovePi.
-Shoban

Hi @Shoban thanks for your replay, let me know when it is working