Skip to content

I2C fails with CircuitPython 2.2.0 and Feather Huzzah #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tdstranger opened this issue Jan 4, 2018 · 11 comments
Closed

I2C fails with CircuitPython 2.2.0 and Feather Huzzah #9

tdstranger opened this issue Jan 4, 2018 · 11 comments

Comments

@tdstranger
Copy link

Connecting CCS811 to a Feather HUZZAH ESP8266 using bitbangio and adafruit_ccs811.mpy.
Example typed into REPL:

Adafruit CircuitPython 2.2.0 on 2018-01-02; ESP module with ESP8266
from board import *
import bitbangio
import adafruit_ccs811
i2c=bitbangio.I2C(SCL, SDA)
ccs=adafruit_ccs811.CCS811(i2c)
Traceback (most recent call last):
File "", line 1, in
File "adafruit_ccs811.py", line 113, in init
File "adafruit_register/i2c_bit.py", line 40, in get
File "adafruit_register/i2c_bit.py", line 39, in get
File "adafruit_bus_device/i2c_device.py", line 94, in write
OSError: [Errno 5] EIO

Talked to jerryn on the Adafruit Discord and after some troubleshooting, they suggested that I post an issue.

@jerryneedell
Copy link
Contributor

I am able to reproduce this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ccs811_example.py", line 10, in <module>
  File "adafruit_ccs811.py", line 113, in __init__
  File "adafruit_register/i2c_bit.py", line 40, in __get__
  File "adafruit_register/i2c_bit.py", line 39, in __get__
  File "adafruit_bus_device/i2c_device.py", line 102, in write
OSError: [Errno 5] EIO
>>> 

Note: On my first power up, the device actually worked! All subsequent test have failed. I went through a lot of testing with this sensor and problems with it on the esp8266, It works well under the Arduino environment but not with the esp8266 bitbangio I2c interface. The following link is to the forum post I had regarding this. https://forums.adafruit.com/viewtopic.php?f=19&t=121816

I have been trying this with and without a 100microfarad capacitor across the power/ground.

@jerryneedell
Copy link
Contributor

interesting I tried connecting the sensor to a feather M0 express (actually supersized) board and first tried the bitbangio code it failed the same as above. I then modified it to use busio and it works normally.


Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 2.2.0 on 2018-01-03; Hacked Feather M0 Express with 8Mbyte SPI flash with samd21g18
>>>
>>>
>>> import ccs811_example
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ccs811_example.py", line 10, in <module>
  File "adafruit_ccs811.py", line 113, in __init__
  File "adafruit_register/i2c_bit.py", line 40, in __get__
  File "adafruit_register/i2c_bit.py", line 39, in __get__
  File "adafruit_bus_device/i2c_device.py", line 102, in write
OSError: 5
>>>
>>>
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.



Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 2.2.0 on 2018-01-03; Hacked Feather M0 Express with 8Mbyte SPI flash with samd21g18
>>> import ccs811_busio
CO2:  None  TVOC: 0  temp: 25.0
CO2:  0  TVOC: 0  temp: 25.0
CO2:  0  TVOC: 0  temp: 25.3355
CO2:  0  TVOC: 0  temp: 25.3355
CO2:  0  TVOC: 0  temp: 25.3355
CO2:  0  TVOC: 0  temp: 25.3355
CO2:  0  TVOC: 0  temp: 25.3355
CO2:  400  TVOC: 0  temp: 25.3355
CO2:  400  TVOC: 0  temp: 25.3355
CO2:  400  TVOC: 0  temp: 25.3355
CO2:  400  TVOC: 0  temp: 25.7893
CO2:  400  TVOC: 0  temp: 25.7893
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ccs811_busio.py", line 20, in <module>
KeyboardInterrupt: 
>>> 

@jerryneedell
Copy link
Contributor

the code being used it the example from the repo with bitbangio replacing busio for the esp8266


from board import SCL, SDA
import bitbangio

import adafruit_CCS811

i2c_bus = bitbangio.I2C(SCL, SDA)

ccs = adafruit_CCS811.CCS811(i2c_bus)

#wait for the sensor to be ready and calibrate the thermistor
while not ccs.data_ready:
    pass
temp = ccs.temperature
ccs.temp_offset = temp - 25.0

while True:
    print("CO2: ", ccs.eCO2, " TVOC:", ccs.TVOC, " temp:", ccs.temperature)
    time.sleep(.5)

@jerryneedell
Copy link
Contributor

some additional information:
I conencted the ccs811 and an mcp9808 temp/hum sensor to both the esp8266 and then to the feather m0.
On the esp8266, the mcp9808 works normally but the ccs811 contiunes to fail as above.
On the M0 bot sesnsor work normally using busio and the mcp9808 works normally using bitbangio but the ccs811 is intermittent using bitbangio. Sometimes it works sometimes it fails.

@jerryneedell
Copy link
Contributor

hmmm - here is an example of the bitbangio failing on the m0 after running successfully for awhile. Time to hook up the scope....

CO2:  418  TVOC: 2  temp: 26.2719
CO2:  418  TVOC: 2  temp: 26.2719
CO2:  418  TVOC: 2  temp: 26.2719
CO2:  418  TVOC: 2  temp: 26.2719
CO2:  415  TVOC: 2  temp: 26.2719
CO2:  415  TVOC: 2  temp: 26.2719
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ccs811_example.py", line 19, in <module>
  File "adafruit_ccs811.py", line 170, in temperature
  File "adafruit_ccs811.py", line 169, in temperature
  File "adafruit_bus_device/i2c_device.py", line 102, in write
OSError: 5

@jerryneedell
Copy link
Contributor

The problem appears to be that the bitbangio I2C driver does not support "clock stretching"
Slowing the I2C clock to 10Khz did yield some success on the esp8266, but it still eventually crashed.
i2c_bus = bitbangio.I2C(SCL, SDA,frequency=10000)

@jerryneedell
Copy link
Contributor

Just a followup - after cleaning up my wiring I get less frequent crashes of the CCS811 on the esp8266. Still not ideal but better.... your mileage may vary.

@jerryneedell
Copy link
Contributor

ran a lot of tests of I2C clock stretching - see adafruit/circuitpython#511
basic conclusion is that this sensor is unreliable with bit banging I2C, especially on the esp8266.
I did get it to function for short periods of time by setting the I2C frequency to 10000 but it still fails after some time.
i2c_bus = bitbangio.I2C(SCL, SDA,frequency=10000)

the ccs811 works on my feather m0 express with hardware I2C and I have run it a lot under arduino on the esp8266, but I do get occasional errors with it and have to reset the board even under arduino.

@tannewt
Copy link
Member

tannewt commented Jan 24, 2018

@jerryneedell do you think there is anything else we can do to fix this or should we close the issue?

@jerryneedell
Copy link
Contributor

I suggest closing it and we can re-open or create a new one it if becomes a problem for someone.

@tannewt
Copy link
Member

tannewt commented Jan 24, 2018

Sounds good! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants