Multichannel gas sensor

Hi,



I have a seeeduino LoraWan with GPS and I added the Multichannel gas sensor to it using one of the outer Grove-connectors on the board.



From the Arduino-forum I got a program that scans the I2C-bus and reports. Here is the result:
</s>Scanning... I2C device found at address 0x04 ! done <e>

This looks good. Next step: I tried the program GetVersion from the Examples: it is hanging.

So I added some print-statements to the code and found that it is hanging in the getVersion()-function:
[code]unsigned int MutichannelGasSensor::get_addr_dta(unsigned char addr_reg, unsigned char __dta)
{

START:
//debugSerial.print("START: ");
Wire.beginTransmission(i2cAddress);
Wire.write(addr_reg);
Wire.write(__dta);
Wire.endTransmission(); // stop transmitting

//debugSerial.println( Wire.requestFrom(i2cAddress, 2) );
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;

[/code]

As cnt is always zero it jumps back to START.



What is wrong with my example? What do I have to do to make it work?



AugustQ



PS: when I switch to an Arduino UNO and connect the sensor to GND, 3.3V, A4 and A% the code works and I get values for the gases. So the sensor seems to be OK.

Hello,

I met the same problem as you, and I changed some of the code then data was read.

I do not know why, it sounds unbelievable, but it does work. Does anyone know why?

Here are my code and result:







Hi bestlux,



unbelievable, but something like this works. But is this solution reliable? And why does it work?



So, here is what I did:

your solution did not work for me. And you do the endTransmission() twice.

So I changed it and here is my code:
[code]unsigned int MutichannelGasSensor::get_addr_dta(unsigned char addr_reg, unsigned char __dta)
{

START:
debugSerial.print("START: ");
Wire.beginTransmission(i2cAddress);
// byte errorTrans = Wire.endTransmission(); // stop transmitting
//debugSerial.print("end Trans = ");
//debugSerial.println( errorTrans );
Wire.write(addr_reg);
Wire.write(__dta);
// Wire.endTransmission(); // stop transmitting
debugSerial.print("end Trans = ");
debugSerial.println( Wire.endTransmission() );
[/code]
and in my main-pgm (GetVersion) I changed this:
</s>void loop() { // nothing to do unsigned char version = gas.getVersion(); debugSerial.print("Version = "); debugSerial.println(version); <e>
and this is the result:
</s>START: end Trans = 0 Version = 2 getVersion() START: end Trans = 0 Version = 2 getVersion() START: end Trans = 0 Version = 2 getVersion() START: end Trans = 0 Version = 2 getVersion() START: end Trans = 0 Version = 2 <e>

I will continue playing with this solution and will inform you about my findings.



Thansk for tip.

AugustQ



PS: I don’t like solutions like this. Computers should be dumb and fast. Ans this something like moon-phase or earth-waves or …

Hi,



in the MultichannelGasSensor.cpp (coming for seeed) I found this hint:
</s> // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. <e>

So I changed every call of endTransmission() to this line:
</s> byte errorTrans = Wire.endTransmission(); // stop transmitting <e>

except for one case where something like this was already in the code (below the comment).



Now it seems to wrk even for me here.



Tanks for your reply!

AugustQ



PS: to me this still looks like magic.

Hi,



I’m abandoning this way and will continue with an Arduino-board.



The solution you posted works in about 50% of the tests so it’s not reliable (at least it did so in my tests).



So it looks like it’s a problem with the software.



Using an Arduino-board I did not encounter any problems with this sensor.



AugustQ