Maddening i2c problem with the Adafruit ccs811

The Adafruit ccs811 Gas Censor, ready for header installation

I’m trying to write a python script to use my and it WON’T respond. I’m sure my python code is good, but I keep getting this horrible error. It’s like the ccs811 isn’t even attached! I mean, look at this:

Traceback (most recent call last):
File "weather.py", line 54, in
print(str(ccs811.tvoc))
File "/usr/local/lib/python3.7/dist-packages/adafruit_ccs811.py", line 162, in tvoc
self._update_data()
File "/usr/local/lib/python3.7/dist-packages/adafruit_ccs811.py", line 147, in _update_data
if self.data_ready:
File "/usr/local/lib/python3.7/dist-packages/adafruit_register/i2c_bit.py", line 60, in <strong>get</strong>
i2c.write_then_readinto(self.buffer, self.buffer, out_end=1, in_start=1)
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 156, in write_then_readinto
in_end=in_end,
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 118, in writeto_then_readfrom
stop=stop,
File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 85, in writeto_then_readfrom
address, buffer_out[out_start:out_end], in_end - in_start
File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 273, in read_i2c_block_data
ioctl(self._device.fileno(), I2C_RDWR, request)
OSError: [Errno 121] Remote I/O error

What the hell?!?!

I do a little research and realize that the module has issues when it runs at full speed. The trick to getting the Adafruit Gas Sensor to respond is to slow down the i2c bus speed. This is simple to do.

Edit /boot/config.txt and add a couple of lines to the end:

core_freq=500
core_freq_min=500
dtparm=i2c_arm=on,i2c_arm_baudrate=10000

Reboot and run your script again! After a couple of minutes, the heater comes to operating temp and you start getting good readings! w00t!

I’m working on getting this Adafruit Gas Sensor installed above my 3D printer to watch for high fume levels coming from the printing process.

Author: John

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.