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)
{
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.
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 …
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).