maarten-pennings / CCS811

Arduino library for the CCS811 gas sensor for monitoring indoor air quality.
MIT License
165 stars 46 forks source link

CCS811: I2C error #7

Closed MagTun closed 5 years ago

MagTun commented 5 years ago

Hi,

I am following the basic example from your library and running it on this NodeMCU with this CCS811.

I have made the 2 edits in the Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266.

But I am getting the error: CCS811: I2C error. This is my first complex project (I've only done LED ones before) with NodeMCU, so I not sure how to solved it.

I don't know if it matters but this is the errstat:

errstat=  16283
ccs811.errstat_str(errstat)=  1073675076

I looked at this link , and I replaced SDA and SCL with shorter cable (10 cm instead of 30cm), twisting SCL with GND and SDA with VCC, using 10k pull-ups resistor on both SDA and SCL (I didn't know how to do it, so I followed what is done on this circuit, I hope this is how it should be done), but I am still getting the same error and errstat code.

Here is my circuit (I followed you color code for the wire): nodemcu sensor

I am powering the NoceMCU via a USB charger (not a computer)

Thanks a lot for your help!

maarten-pennings commented 5 years ago

Hi

I'm not sure where to start.

The NodeMCU and CCS811 board are ok.

The library changes improve stability, but without them, it should also work more or less.

The error you mention is half way the program. Could you send the exact output of the basic example from startup; that would make it easier to see where it goes wrong.

The pull up resistors are good for stability, but it should also work without. When I could the mail from this issue, you had a different photo than what is now in this issue. Now they are no resistors, that is ok. In the old photo the resistors where in series, not as pull-up, that is NOT good. The link 'circuit' above has the correct wiring for pull-ups. Short cables is wise, I believe nobody does twisting.

So, let's start with the exact output of the basic example.

MagTun commented 5 years ago

Thank you very much for your time Marteen !

Yes the first pictures were a mistake. I then used the correct pullups circuit and I still got the same error.

I don't have access to the ouput from the startup as I am not powering the NodeMcu from my computer so I don't have access to the Serial.print(). I use a remote debug over telnet with putty (I am still a beginner and I am afraid that powering my NodeMCU with my computer may break something in my computer).

I couldn't make de debug print the things from the startup, instead I moved all these lines in the loop (cf my sketch below):

Here is what I got (I didn't convert the version's values from hex, I simply printed them):

init: CCS811 begin  FAILED
init: hardware    version: 4294967295
init: bootloader  version: 4294967295
init: application version: 4294967295
init: CCS811 start measuring FAILED

And for the cs811.read():

eco2=  65535  ppm
etvoc=  65535 ppb
raw 65535
errstat 16283
decode errstat=   1073675156

I tried several times and I always got the same values.

If the CCS811 doesn't start, does it mean that it's broken ?

I verified the continuity of all my connection and everything is fine.

My sketch with the outputing right at the begining of the loop (look for the parts between ***)

Thanks again for your help!

maarten-pennings commented 5 years ago

If I were you, I would first concentrate on begin.

The very first line says begin FAILED and that means the begin, well, failed. This means the CCS811 could not be put in "application mode", hence all next commands fail. I think the problem is very early since even the versions come out wrong. The number 4294967295 (decimal) is FFFF FFFF in hex, which means the SDA line is always hi, which means the CCS811 is not responding. The other numbers you show are all-1 in binary.

I would suggest you hook the NodeMCU+CCS811 to your PC. You need to find out where the problem is, so keep the setup simple.

I am afraid that powering my NodeMCU with my computer may break something in my computer

I understand that. I bought a 2 euro USB hub to isolate my NodeMCU from my PC. By the way, the worst that can happen is a short circuit (between 5V and GND), and I know from experience that my Dell laptop can handle that :-) it shuts down the USB port, and it is back the next boot.

Also, start with just the CCS811 basic script. Again, keep the setup simple.

Please note that I made the CCS811::begin() in such a way that it should help you diagnose the problem. By default it checks many things (12 diagnostics), and prints out the problem. It would be helpful, if we have this print-out, it explains why begin() fails.

So, NodeMCU with CCS811 via USB hub to PC, run the standard CCS811 basic script, and capture the serial output.

maarten-pennings commented 5 years ago

It could be as simple as the wrong I2C slave address. To make the setup even simpler, you could ground nWAKE instead of wiring it to the ESP8266 (then the CCS811 is always woken up)

maarten-pennings commented 5 years ago

If you connect the nWAKE pin of the CCS811 to a GND pin directly, the CCS811 is always awake. As a result, the driver no longer has to wakeup the CCS811. You tell the driver that by passing -1 for the nwake pin. The ccs811.h file tries to explain that (documentation in comments):

CCS811(int nwake=-1, int slaveaddr=CCS811_SLAVEADDR_0); // Pin number connected to nWAKE (nWAKE can also be bound to GND, then pass -1), slave address (5A or 5B)

But this is only a small step to simplify setup. I'm much more interested in the prints of begin() :-)

Good luck!

MagTun commented 5 years ago

To connect the nWAKE to ground, should I modify this line? CCS811 ccs811(D3); // nWAKE on D3

I tried to do this:

CCS811 ccs811(GND);

But I am getting, this error in Arduino IDE: 'GND' was not declared in this scope

I looked into ccs811.cpp and apparently I could do this (I don't get an error, but I am not sure, it's the right way to do it): CCS811 ccs811(-1);

I connected the nWake to the GND and I am getting the same errors:

CCS811 begin  FAILED
hardware    version: 4294967295
bootloader  version: 4294967295
application version: 4294967295
CCS811 start measuring FAILED

+++++

This is the output in the serial monitor (I connected my nodemcu to my laptop usb) for the basic example with nwake connected to ground:

Starting CCS811 basic demo
ccs811: begin: ping failed (VDD/GNF connected? SDA/SCL connected?)
init: CCS811 begin FAILED
init: hardware    version: FFFFFFFF
init: bootloader  version: FFFFFFFF
init: application version: FFFFFFFF
init: CCS811 start FAILED
maarten-pennings commented 5 years ago

The crucial line here (with a typo: GNF=GND): ccs811: begin: ping failed (VDD/GNF connected? SDA/SCL connected?)

This means there was no reaction on the used I2C slave address. Note that begin() even tries the other I2C slave address, but also there was no reply.

This starts to sound like a hardware problem.

What scenarios do we have?

What other hardware do you have? Do you have a scope, logic analyser, Saleae to check if there is signal on the I2C wires? Do you have another I2C slave to check if your ESP8266 generates I2C signals on the wires? Do you have another Arduino (another ESP8266 or even another micro) to check if the first ESP is broken? [Note, some Arduino's are 5V and that is not good for the CCS811]

MagTun commented 5 years ago

Thanks for taking the time to explain every steps of the debug process.

I have change several times the cables and checked the continuity of the cables so I don't think the problem comes one there. I followed to pin out on the pictures, so apparently, the problem isn't from there either. I used a another NodeCMU (the same one as the one on the picture) and I get the same output:

ccs811: begin: ping failed (VDD/GNF connected? SDA/SCL connected?)
init: CCS811 begin FAILED
init: hardware    version: FFFFFFFF
init: bootloader  version: FFFFFFFF
init: application version: FFFFFFFF
init: CCS811 start FAILED

I tested the I2C connection of my two nodemcus with a LCD and they work. I use the I2C connections on the D1-D2 but also on the D3-D4(using SDA on D3 and SCL on D4).

Also when using a I2C scanner I got this output: I2C device found at address 0x27 // (using SDA on D3 and SCL on D4) I only have a basic multimeter.

Does all this mean that it's likely my CCS811 sensor that is broken?

maarten-pennings commented 5 years ago

I'm back ...

This intrigued me:

Also when using a I2C scanner I got this output: I2C device found at address 0x27 // (using SDA on D3 and SCL on D4)

Does this mean you have an I2C scanner? Is this a sketch running on ESP8266? Using I2C on D1 and D2? With an LCD hooked to this bus (D1/D2)?

That would be good - a firm basis.

Did you then do these steps?

This does not report a device on address on 5A or 5B?

Then ... we might have a broken CCS811 board ...

MagTun commented 5 years ago

The I2C scanner is part of a library that I used for the LCD.

With the LCD the I2C address on pin D1-D2 still 0x27.

I replaced the LCD with the CCS811 and I am getting mix result The first scanning gave me this:

Scanning...
I2C device found at address 0x01  !
Unknow error at address 0x02
Unknow error at address 0x03
Unknow error at address ⸮HpY>$(⸮⸮D:h⸮1⸮
I2C Scanner
Scanning...
No I2C devices found
Scanning...
No I2C devices found  

Then I move a bit the connections (I didn't soldered the CCS811) and I go a mix of this :

Scanning...
No I2C devices found
Scanning...
I2C device found at address 0x5A  !
done
Scanning...
No I2C devices found

But 95%, if the time I get No I2C devices found. But I never succeeded in having more than 2-3 I2C device found at address 0x5A in a row. It's also not dependent on the position of the pin. Iguess, it maybe thus be a faulty connection in my circuit or in the CSS811.

maarten-pennings commented 5 years ago

The I2C device found at address 0x5A ! is a good sign. But the 95% of the time getting No I2C devices found. is not good. Loose contact? Do pull-ups help?

I bought the same board as you have:

20181203_113354

And I hooked it up in the most simple way:

20181203_115748

Zoom-in on the NodeMCU side:

20181203_115811

Zoom in on the CCS811 side:

20181203_115827

And then I ran the ccs811basic sketch.

Starting CCS811 basic demo
ccs811: begin: ping failed (VDD/GNF connected? SDA/SCL connected?)
init: CCS811 begin FAILED
init: hardware    version: FFFFFFFF
init: bootloader  version: FFFFFFFF
init: application version: FFFFFFFF
init: CCS811 start FAILED
CCS811: I2C error
CCS811: I2C error
CCS811: I2C error
CCS811: I2C error
CCS811: I2C error

... reset ...

Starting CCS811 basic demo
ccs811: begin: ping failed (VDD/GNF connected? SDA/SCL connected?)
init: CCS811 begin FAILED
init: hardware    version: FFFFFFFF
init: bootloader  version: FFFFFFFF
init: application version: FFFFFFFF
init: CCS811 start FAILED
CCS811: I2C error
CCS811: I2C error
CCS811: I2C error
CCS811: I2C error
CCS811: I2C error

... reset ...

Starting CCS811 basic demo                                                      
init: hardware    version: 12                                                   
init: bootloader  version: 1000                                                 
init: application version: 1100                                                 
CCS811: errstat=0=--vhxmrwf--ad-ie                                              
CCS811: errstat=0=--vhxmrwf--ad-ie                                              
CCS811: waiting for (new) data                                                  
CCS811: waiting for (new) data                                                  
CCS811: waiting for (new) data                                                  
CCS811: waiting for (new) data                                                  
CCS811: waiting for (new) data                                                  

So, also instabilities. I do have the two // Maarten: added Clock stretching lines added in si2c.c. Hmm.

One difference is, of course, in the versions of the application: 1.1 on the Chinese board versus 2.0 on my ams board.

init: hardware    version: 12                                                   
init: bootloader  version: 1000                                                 
init: application version: 1100                                                 

init: hardware    version: 12
init: bootloader  version: 1000
init: application version: 2000
maarten-pennings commented 5 years ago

I have run the script several times today. And actually only the very first time it failed. All other runs where successful.

But successful means: the begin() works, so there is i2c communication, but the measurements fail. I debugged this, somehow the STATUS field in register ALG_RESULT_DATA differs from the standalone STATUS register...

But this is different from your problems, you don't have a stable i2c connection.

MagTun commented 5 years ago

Hi Marteen,

You are amazing! Your dedication is just incredible!

I had try the I2C scanner with the pullups and it change nothing (still getting 95% "not device found), but then I try again without the pull-up an that time, I could get a stable I2C connection in a special angle so maybe soldering the pins might help. I will let you know once I do it.

And again, thanks so much for your time!

maarten-pennings commented 5 years ago

Good luck, let me know!

maarten-pennings commented 5 years ago

I made an update of the library; it now also supports "old" CCS811s, with firmware before 2.0.0. Probably you have that in your "chinese board" (mine had).

MagTun commented 5 years ago

You are just amazing!

I didn't have the time to solder today, I will let you know when I will do it.

maarten-pennings commented 5 years ago

I made an update to the library, you can now flash the CCS811 with 2.0.0 firmware (replacing the 1.1.0). Use at your own risk...

MagTun commented 5 years ago

I have seen your flash example, you are simply incredible! Thanks a lot for your time!

On my side, I am still unable to get a stable communication with the CCS811 (I am waiting to get a good solder iron).